switch test port

This commit is contained in:
Umputun
2019-04-04 22:51:41 -05:00
parent ad3430883f
commit 50e437c22c
+23 -12
View File
@@ -1,6 +1,7 @@
package main
import (
"context"
"io/ioutil"
"net/http"
"os"
@@ -11,6 +12,7 @@ import (
"time"
log "github.com/go-pkgz/lgr"
"github.com/go-pkgz/repeater"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
@@ -23,12 +25,12 @@ func Test_Main(t *testing.T) {
defer os.RemoveAll(dir)
os.Args = []string{"test", "server", "--secret=123456", "--store.bolt.path=" + dir, "--backup=/tmp",
"--avatar.fs.path=" + dir, "--port=18202", "--url=https://demo.remark42.com", "--dbg", "--notify.type=none"}
"--avatar.fs.path=" + dir, "--port=18222", "--url=https://demo.remark42.com", "--dbg", "--notify.type=none"}
go func() {
time.Sleep(1000 * time.Millisecond)
err := syscall.Kill(syscall.Getpid(), syscall.SIGTERM)
require.Nil(t, err)
e := syscall.Kill(syscall.Getpid(), syscall.SIGTERM)
require.Nil(t, e)
}()
wg := sync.WaitGroup{}
@@ -40,16 +42,25 @@ func Test_Main(t *testing.T) {
wg.Done()
}()
time.Sleep(500 * time.Millisecond) // let server start
var passed bool
err = repeater.NewDefault(10, time.Millisecond*100).Do(context.Background(), func() error {
resp, e := http.Get("http://localhost:18222/api/v1/ping")
if e != nil {
t.Logf("%+v", e)
return e
}
require.Nil(t, e)
defer resp.Body.Close()
assert.Equal(t, 200, resp.StatusCode)
body, e := ioutil.ReadAll(resp.Body)
assert.Nil(t, e)
assert.Equal(t, "pong", string(body))
passed = true
return nil
})
// send ping
resp, err := http.Get("http://localhost:18202/api/v1/ping")
require.Nil(t, err)
defer resp.Body.Close()
assert.Equal(t, 200, resp.StatusCode)
body, err := ioutil.ReadAll(resp.Body)
assert.Nil(t, err)
assert.Equal(t, "pong", string(body))
assert.NoError(t, err)
assert.Equal(t, true, passed)
wg.Wait()
}