Skip to content

Commit

Permalink
add test for server Run
Browse files Browse the repository at this point in the history
  • Loading branch information
umputun committed Nov 4, 2019
1 parent 995f277 commit 5ecc6fa
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions app/server/rlb_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"encoding/json"
"fmt"
"io/ioutil"
"math/rand"
"net/http"
"net/http/httptest"
"testing"
Expand Down Expand Up @@ -65,6 +66,31 @@ func TestSubmitStats(t *testing.T) {
time.Sleep(100 * time.Millisecond)
}

func TestRun(t *testing.T) {
port := rand.Intn(10000) + 2000
srv := NewRLBServer(newMockPicker(), "error msg", "", port, "v1")

go func() {
srv.Run()
}()

ts := httptest.NewServer(srv.routes())
defer func() {
ts.Close()
defer srv.Shutdown()
}()

time.Sleep(100 * time.Millisecond) // allow server to start

resp, err := http.Get(fmt.Sprintf("http://localhost:%d/ping", port))
require.NoError(t, err)
defer resp.Body.Close()
data, err := ioutil.ReadAll(resp.Body)
require.NoError(t, err)
assert.Equal(t, "pong", string(data))

}

type hitReq struct {
svc string
resource string
Expand Down

0 comments on commit 5ecc6fa

Please sign in to comment.