package main import ( "fmt" "net/http" "net/http/httptest" "testing" ) const jsonContentType = "application/json" func TestPortal(t *testing.T) { store := StubUserStore{ map[string]string{ "testUser": "123.123.123.123:50120", "jimmy": "12.12.12.12:50121", }, } server := NewLoginServer(&store) t.Run("Logs client ip", func(t *testing.T) { for _, want := range store.userIpMap { t.Run(fmt.Sprintf("got ip from "+want), func(t *testing.T) { request := NewGetHomeRequest() request.RemoteAddr = want response := httptest.NewRecorder() server.ServeHTTP(response, request) got := response.Body.String() AssertStatus(t, response.Code, http.StatusOK) //todo we should update on post not get AssertResponseBody(t, got, want) //t.Fatalf("This test is bad, we should store on post not get") }) } }) t.Run("Update client IP", func(t *testing.T) { request := NewPutHomeRequest("testUser") want := "5.5.5.5:10121" request.RemoteAddr = want response := httptest.NewRecorder() server.ServeHTTP(response, request) //todo make this fail response.Body.String() AssertStatus(t, response.Code, http.StatusAccepted) }) }