(t *testing.T)
| 10 | ) |
| 11 | |
| 12 | func TestRunHealthCheck(t *testing.T) { |
| 13 | tests := []struct { |
| 14 | name string |
| 15 | statusCode int |
| 16 | body string |
| 17 | wantExit int |
| 18 | }{ |
| 19 | {"healthy", http.StatusOK, "", 0}, |
| 20 | {"unhealthy", http.StatusServiceUnavailable, "not ready", 1}, |
| 21 | } |
| 22 | |
| 23 | for _, tt := range tests { |
| 24 | t.Run(tt.name, func(t *testing.T) { |
| 25 | server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) { |
| 26 | w.WriteHeader(tt.statusCode) |
| 27 | fmt.Fprint(w, tt.body) |
| 28 | })) |
| 29 | defer server.Close() |
| 30 | |
| 31 | assert.Equal(t, tt.wantExit, RunHealthCheck(server.URL+"/ready")) |
| 32 | }) |
| 33 | } |
| 34 | } |
| 35 | |
| 36 | func TestRunHealthCheckDefaultURL(t *testing.T) { |
| 37 | assert.Equal(t, 1, RunHealthCheck("")) |
nothing calls this directly
no test coverage detected