2014-06-13 21:03:49 +00:00
|
|
|
/*
|
Rename import paths from camlistore.org to perkeep.org.
Part of the project renaming, issue #981.
After this, users will need to mv their $GOPATH/src/camlistore.org to
$GOPATH/src/perkeep.org. Sorry.
This doesn't yet rename the tools like camlistored, camput, camget,
camtool, etc.
Also, this only moves the lru package to internal. More will move to
internal later.
Also, this doesn't yet remove the "/pkg/" directory. That'll likely
happen later.
This updates some docs, but not all.
devcam test now passes again, even with Go 1.10 (which requires vet
checks are clean too). So a bunch of vet tests are fixed in this CL
too, and a bunch of other broken tests are now fixed (introduced from
the past week of merging the CL backlog).
Change-Id: If580db1691b5b99f8ed6195070789b1f44877dd4
2018-01-01 22:41:41 +00:00
|
|
|
Copyright 2014 The Perkeep Authors
|
2014-06-13 21:03:49 +00:00
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
package app
|
|
|
|
|
|
|
|
import (
|
2014-12-19 15:31:59 +00:00
|
|
|
"bufio"
|
|
|
|
"fmt"
|
|
|
|
"io"
|
|
|
|
"os"
|
|
|
|
"os/exec"
|
2019-04-03 16:05:56 +00:00
|
|
|
"runtime"
|
2014-06-13 21:03:49 +00:00
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
2016-06-28 00:12:47 +00:00
|
|
|
func TestRandListen(t *testing.T) {
|
2014-06-13 21:03:49 +00:00
|
|
|
tests := []struct {
|
2016-06-28 00:12:47 +00:00
|
|
|
randPort int
|
|
|
|
listen string
|
|
|
|
wantListenAddr string
|
2014-06-13 21:03:49 +00:00
|
|
|
}{
|
|
|
|
{
|
2016-06-28 00:12:47 +00:00
|
|
|
listen: ":3179",
|
|
|
|
randPort: 58094,
|
|
|
|
wantListenAddr: ":58094",
|
2014-06-13 21:03:49 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
{
|
2016-06-28 00:12:47 +00:00
|
|
|
listen: "foo.com:3179",
|
|
|
|
randPort: 58094,
|
|
|
|
wantListenAddr: "foo.com:58094",
|
2014-06-13 21:03:49 +00:00
|
|
|
},
|
2016-06-28 00:12:47 +00:00
|
|
|
}
|
|
|
|
for _, v := range tests {
|
|
|
|
listenAddr, err := randListenFn(v.listen, func() (int, error) { return v.randPort, nil })
|
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
if listenAddr != v.wantListenAddr {
|
|
|
|
t.Errorf("for listen addr, got: %v, want: %v", listenAddr, v.wantListenAddr)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-06-13 21:03:49 +00:00
|
|
|
|
2016-06-28 00:12:47 +00:00
|
|
|
func TestBaseURL(t *testing.T) {
|
|
|
|
tests := []struct {
|
|
|
|
listen string
|
|
|
|
baseURL string
|
|
|
|
wantBackendURL string
|
|
|
|
}{
|
2014-06-13 21:03:49 +00:00
|
|
|
{
|
2016-06-28 00:12:47 +00:00
|
|
|
listen: ":3179",
|
|
|
|
baseURL: "http://foo.com",
|
|
|
|
wantBackendURL: "http://foo.com:3179/",
|
2014-06-13 21:03:49 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
{
|
2016-06-28 00:12:47 +00:00
|
|
|
listen: "localhost",
|
|
|
|
baseURL: "http://foo.com",
|
|
|
|
wantBackendURL: "http://foo.com:80/",
|
2014-06-13 21:03:49 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
{
|
2016-06-28 00:12:47 +00:00
|
|
|
listen: "localhost",
|
|
|
|
baseURL: "https://foo.com",
|
|
|
|
wantBackendURL: "https://foo.com:443/",
|
2014-06-13 21:03:49 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
{
|
2016-06-28 00:12:47 +00:00
|
|
|
listen: "localhost:3179",
|
|
|
|
baseURL: "http://foo.com",
|
|
|
|
wantBackendURL: "http://foo.com:3179/",
|
2014-06-13 21:03:49 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
{
|
2016-06-28 00:12:47 +00:00
|
|
|
listen: "localhost:3179",
|
|
|
|
baseURL: "https://foo.com",
|
|
|
|
wantBackendURL: "https://foo.com:3179/",
|
2014-06-13 21:03:49 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
{
|
2016-06-28 00:12:47 +00:00
|
|
|
listen: ":3179",
|
|
|
|
baseURL: "http://foo.com:123",
|
|
|
|
wantBackendURL: "http://foo.com:3179/",
|
2014-06-13 21:03:49 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
{
|
2016-06-28 00:12:47 +00:00
|
|
|
listen: "localhost",
|
|
|
|
baseURL: "http://foo.com:123",
|
|
|
|
wantBackendURL: "http://foo.com:80/",
|
2014-06-13 21:03:49 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
{
|
2016-06-28 00:12:47 +00:00
|
|
|
listen: "localhost",
|
|
|
|
baseURL: "https://foo.com:123",
|
|
|
|
wantBackendURL: "https://foo.com:443/",
|
2014-06-13 21:03:49 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
{
|
2016-06-28 00:12:47 +00:00
|
|
|
listen: "localhost:3179",
|
|
|
|
baseURL: "http://foo.com:123",
|
|
|
|
wantBackendURL: "http://foo.com:3179/",
|
2014-06-13 21:03:49 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
{
|
2016-06-28 00:12:47 +00:00
|
|
|
listen: "localhost:3179",
|
|
|
|
baseURL: "https://foo.com:123",
|
|
|
|
wantBackendURL: "https://foo.com:3179/",
|
2014-06-13 21:03:49 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
for _, v := range tests {
|
2016-06-28 00:12:47 +00:00
|
|
|
backendURL, err := baseURL(v.baseURL, v.listen)
|
2014-06-13 21:03:49 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
continue
|
|
|
|
}
|
2016-06-28 00:12:47 +00:00
|
|
|
if v.wantBackendURL != backendURL {
|
|
|
|
t.Errorf("For backendURL, got: %v, want %v", v.wantBackendURL, backendURL)
|
2014-06-13 21:03:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-12-19 15:31:59 +00:00
|
|
|
|
|
|
|
// We just want a helper command that ignores SIGINT.
|
|
|
|
func ignoreInterrupt() (*os.Process, error) {
|
|
|
|
script := `trap "echo hello" SIGINT
|
|
|
|
echo READY
|
|
|
|
sleep 10000`
|
|
|
|
cmd := exec.Command("bash")
|
|
|
|
|
|
|
|
w, err := cmd.StdinPipe()
|
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("couldn't get pipe for helper shell")
|
|
|
|
}
|
|
|
|
go io.WriteString(w, script)
|
|
|
|
|
|
|
|
stdout, err := cmd.StdoutPipe()
|
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("couldn't get pipe for helper shell")
|
|
|
|
}
|
|
|
|
|
|
|
|
err = cmd.Start()
|
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("couldn't start helper shell")
|
|
|
|
}
|
|
|
|
|
|
|
|
r := bufio.NewReader(stdout)
|
|
|
|
l, err := r.ReadBytes('\n')
|
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("couldn't read from helper shell")
|
|
|
|
}
|
|
|
|
if string(l) != "READY\n" {
|
|
|
|
return nil, fmt.Errorf("unexpected output from helper shell script")
|
|
|
|
}
|
|
|
|
return cmd.Process, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestQuit(t *testing.T) {
|
|
|
|
if testing.Short() {
|
|
|
|
t.Skip("skipping test in short mode")
|
|
|
|
}
|
2019-04-03 16:05:56 +00:00
|
|
|
if runtime.GOOS == "windows" {
|
|
|
|
// windows does not support interrupts
|
|
|
|
t.Skip("Skipping interrupt test on windows")
|
|
|
|
}
|
2014-12-19 15:31:59 +00:00
|
|
|
|
|
|
|
cmd := exec.Command("sleep", "10000")
|
|
|
|
err := cmd.Start()
|
|
|
|
if err != nil {
|
|
|
|
t.Skip("couldn't run test helper command")
|
|
|
|
}
|
|
|
|
h := Handler{
|
|
|
|
process: cmd.Process,
|
|
|
|
}
|
|
|
|
err = h.Quit()
|
|
|
|
if err != nil {
|
|
|
|
t.Errorf("got %v, wanted %v", err, nil)
|
|
|
|
}
|
|
|
|
|
|
|
|
pid, err := ignoreInterrupt()
|
|
|
|
if err != nil {
|
Rename import paths from camlistore.org to perkeep.org.
Part of the project renaming, issue #981.
After this, users will need to mv their $GOPATH/src/camlistore.org to
$GOPATH/src/perkeep.org. Sorry.
This doesn't yet rename the tools like camlistored, camput, camget,
camtool, etc.
Also, this only moves the lru package to internal. More will move to
internal later.
Also, this doesn't yet remove the "/pkg/" directory. That'll likely
happen later.
This updates some docs, but not all.
devcam test now passes again, even with Go 1.10 (which requires vet
checks are clean too). So a bunch of vet tests are fixed in this CL
too, and a bunch of other broken tests are now fixed (introduced from
the past week of merging the CL backlog).
Change-Id: If580db1691b5b99f8ed6195070789b1f44877dd4
2018-01-01 22:41:41 +00:00
|
|
|
t.Skipf("couldn't run test helper command: %v", err)
|
2014-12-19 15:31:59 +00:00
|
|
|
}
|
|
|
|
h = Handler{
|
|
|
|
process: pid,
|
|
|
|
}
|
|
|
|
err = h.Quit()
|
|
|
|
if err != errProcessTookTooLong {
|
|
|
|
t.Errorf("got %v, wanted %v", err, errProcessTookTooLong)
|
|
|
|
}
|
|
|
|
}
|