Skip to content

Commit

Permalink
keeping the test behaviour same
Browse files Browse the repository at this point in the history
  • Loading branch information
absolutelightning committed Jun 13, 2023
1 parent 06235a9 commit 8e32cc0
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 1 deletion.
2 changes: 2 additions & 0 deletions agent/http_oss_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ func TestHTTPAPI_OptionMethod_OSS(t *testing.T) {
uri := fmt.Sprintf("http://%s%s", a.HTTPAddr(), path)
req, _ := http.NewRequest("OPTIONS", uri, nil)
resp := httptest.NewRecorder()
a.config.EnableDebug = true
a.srv.handler().ServeHTTP(resp, req)
allMethods := append([]string{"OPTIONS"}, methods...)

Expand Down Expand Up @@ -190,6 +191,7 @@ func TestHTTPAPI_AllowedNets_OSS(t *testing.T) {
req, _ := http.NewRequest(method, uri, nil)
req.RemoteAddr = "192.168.1.2:5555"
resp := httptest.NewRecorder()
a.config.EnableDebug = true
a.srv.handler().ServeHTTP(resp, req)

require.Equal(t, http.StatusForbidden, resp.Code, "%s %s", method, path)
Expand Down
10 changes: 9 additions & 1 deletion agent/http_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,7 @@ func TestSetupHTTPServer_HTTP2(t *testing.T) {
err = setupHTTPS(httpServer, noopConnState, time.Second)
require.NoError(t, err)

a.config.EnableDebug = true
srvHandler := a.srv.handler()
mux, ok := srvHandler.(*wrappedMux)
require.True(t, ok, "expected a *wrappedMux, got %T", handler)
Expand Down Expand Up @@ -483,6 +484,7 @@ func TestHTTPAPI_Ban_Nonprintable_Characters(t *testing.T) {
t.Fatal(err)
}
resp := httptest.NewRecorder()
a.config.EnableDebug = true
a.srv.handler().ServeHTTP(resp, req)
if got, want := resp.Code, http.StatusBadRequest; got != want {
t.Fatalf("bad response code got %d want %d", got, want)
Expand All @@ -506,6 +508,7 @@ func TestHTTPAPI_Allow_Nonprintable_Characters_With_Flag(t *testing.T) {
t.Fatal(err)
}
resp := httptest.NewRecorder()
a.config.EnableDebug = true
a.srv.handler().ServeHTTP(resp, req)
// Key doesn't actually exist so we should get 404
if got, want := resp.Code, http.StatusNotFound; got != want {
Expand Down Expand Up @@ -645,6 +648,7 @@ func requireHasHeadersSet(t *testing.T, a *TestAgent, path string) {

resp := httptest.NewRecorder()
req, _ := http.NewRequest("GET", path, nil)
a.config.EnableDebug = true
a.srv.handler().ServeHTTP(resp, req)

hdrs := resp.Header()
Expand Down Expand Up @@ -706,13 +710,15 @@ func TestAcceptEncodingGzip(t *testing.T) {
// negotiation, but since this call doesn't go through a real
// transport, the header has to be set manually
req.Header["Accept-Encoding"] = []string{"gzip"}
a.config.EnableDebug = true
a.srv.handler().ServeHTTP(resp, req)
require.Equal(t, 200, resp.Code)
require.Equal(t, "", resp.Header().Get("Content-Encoding"))

resp = httptest.NewRecorder()
req, _ = http.NewRequest("GET", "/v1/kv/long", nil)
req.Header["Accept-Encoding"] = []string{"gzip"}
a.config.EnableDebug = true
a.srv.handler().ServeHTTP(resp, req)
require.Equal(t, 200, resp.Code)
require.Equal(t, "gzip", resp.Header().Get("Content-Encoding"))
Expand Down Expand Up @@ -1069,7 +1075,6 @@ func TestHTTPServer_PProfHandlers_EnableDebug(t *testing.T) {
req, _ := http.NewRequest("GET", "/debug/pprof/profile?seconds=1", nil)

a.config.EnableDebug = true

httpServer := &HTTPHandlers{agent: a.Agent}
httpServer.handler().ServeHTTP(resp, req)

Expand Down Expand Up @@ -1170,6 +1175,7 @@ func TestHTTPServer_PProfHandlers_ACLs(t *testing.T) {
t.Run(fmt.Sprintf("case %d (%#v)", i, c), func(t *testing.T) {
req, _ := http.NewRequest("GET", fmt.Sprintf("%s?token=%s", c.endpoint, c.token), nil)
resp := httptest.NewRecorder()
a.config.EnableDebug = true
a.srv.handler().ServeHTTP(resp, req)
assert.Equal(t, c.code, resp.Code)
})
Expand Down Expand Up @@ -1480,6 +1486,7 @@ func TestEnableWebUI(t *testing.T) {

req, _ := http.NewRequest("GET", "/ui/", nil)
resp := httptest.NewRecorder()
a.config.EnableDebug = true
a.srv.handler().ServeHTTP(resp, req)
require.Equal(t, http.StatusOK, resp.Code)

Expand Down Expand Up @@ -1509,6 +1516,7 @@ func TestEnableWebUI(t *testing.T) {
{
req, _ := http.NewRequest("GET", "/ui/", nil)
resp := httptest.NewRecorder()
a.config.EnableDebug = true
a.srv.handler().ServeHTTP(resp, req)
require.Equal(t, http.StatusOK, resp.Code)
require.Contains(t, resp.Body.String(), `<!-- CONSUL_VERSION:`)
Expand Down
1 change: 1 addition & 0 deletions agent/ui_endpoint_oss_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ func TestUIEndpoint_MetricsProxy_ACLDeny(t *testing.T) {
`, backendURL))
defer a.Shutdown()

a.config.EnableDebug = true
h := a.srv.handler()

testrpc.WaitForLeader(t, a.RPC, "dc1")
Expand Down
1 change: 1 addition & 0 deletions agent/ui_endpoint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2621,6 +2621,7 @@ func TestUIEndpoint_MetricsProxy(t *testing.T) {

// Now fetch the API handler to run requests against
h := a.srv.handler()
a.config.EnableDebug = true

req := httptest.NewRequest("GET", tc.path, nil)
rec := httptest.NewRecorder()
Expand Down

0 comments on commit 8e32cc0

Please sign in to comment.