Skip to content

Commit

Permalink
Test coverage improvement
Browse files Browse the repository at this point in the history
  • Loading branch information
XD-DENG committed Aug 22, 2020
1 parent 8f22e66 commit c8f75bf
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1511,3 +1511,33 @@ func Test_api_key_authentication(t *testing.T) {
expectedCode = 401
compareAndShout(t, expectedCode, res.StatusCode)
}

func Test_service_root(t *testing.T) {

mr, _ := miniredis.Run()
defer mr.Close()

originalRedisURI := os.Getenv("REDISEEN_REDIS_URI")
os.Setenv("REDISEEN_REDIS_URI", fmt.Sprintf("redis://:@%s", mr.Addr()))
defer os.Setenv("REDISEEN_REDIS_URI", originalRedisURI)

var testService service
testService.loadConfigFromEnv()
s := httptest.NewServer(http.Handler(&testService))
defer s.Close()

client := &http.Client{}
req, _ := http.NewRequest("GET", s.URL+"/", nil)
res, _ := client.Do(req)

expectedCode := 200
compareAndShout(t, expectedCode, res.StatusCode)

resultStr, _ := ioutil.ReadAll(res.Body)
res.Body.Close()

expectedPartialContent := "Available Endpoints:"
if !strings.Contains(string(resultStr), expectedPartialContent) {
t.Error("Expected partial content not found:\n", expectedPartialContent)
}
}

0 comments on commit c8f75bf

Please sign in to comment.