Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
absolutelightning committed Jun 17, 2023
1 parent 94e6a00 commit 499f388
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 15 deletions.
5 changes: 4 additions & 1 deletion agent/agent_endpoint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"os"
"strconv"
"strings"
"sync/atomic"
"testing"
"time"

Expand Down Expand Up @@ -6008,7 +6009,9 @@ func TestAgent_Monitor(t *testing.T) {
cancelCtx, cancelFunc := context.WithCancel(context.Background())
req = req.WithContext(cancelCtx)

a.config.EnableDebug = true
a.enableDebug = atomic.Bool{}
a.enableDebug.Store(true)

resp := httptest.NewRecorder()
handler := a.srv.handler()
go handler.ServeHTTP(resp, req)
Expand Down
7 changes: 5 additions & 2 deletions agent/http_oss_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"net/http"
"net/http/httptest"
"strings"
"sync/atomic"
"testing"
"time"

Expand Down Expand Up @@ -144,7 +145,8 @@ 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.enableDebug = atomic.Bool{}
a.enableDebug.Store(true)
a.srv.handler().ServeHTTP(resp, req)
allMethods := append([]string{"OPTIONS"}, methods...)

Expand Down Expand Up @@ -191,7 +193,8 @@ 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.enableDebug = atomic.Bool{}
a.enableDebug.Store(true)

a.srv.handler().ServeHTTP(resp, req)

Expand Down
40 changes: 30 additions & 10 deletions agent/http_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"runtime"
"strconv"
"strings"
"sync/atomic"
"testing"
"time"

Expand Down Expand Up @@ -288,7 +289,9 @@ func TestSetupHTTPServer_HTTP2(t *testing.T) {
err = setupHTTPS(httpServer, noopConnState, time.Second)
require.NoError(t, err)

a.config.EnableDebug = true
a.enableDebug = atomic.Bool{}
a.enableDebug.Store(true)

srvHandler := a.srv.handler()
mux, ok := srvHandler.(*wrappedMux)
require.True(t, ok, "expected a *wrappedMux, got %T", handler)
Expand Down Expand Up @@ -484,7 +487,9 @@ func TestHTTPAPI_Ban_Nonprintable_Characters(t *testing.T) {
t.Fatal(err)
}
resp := httptest.NewRecorder()
a.config.EnableDebug = true
a.enableDebug = atomic.Bool{}
a.enableDebug.Store(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 @@ -508,7 +513,9 @@ func TestHTTPAPI_Allow_Nonprintable_Characters_With_Flag(t *testing.T) {
t.Fatal(err)
}
resp := httptest.NewRecorder()
a.config.EnableDebug = true
a.enableDebug = atomic.Bool{}
a.enableDebug.Store(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 @@ -648,7 +655,9 @@ func requireHasHeadersSet(t *testing.T, a *TestAgent, path string) {

resp := httptest.NewRecorder()
req, _ := http.NewRequest("GET", path, nil)
a.config.EnableDebug = true
a.enableDebug = atomic.Bool{}
a.enableDebug.Store(true)

a.srv.handler().ServeHTTP(resp, req)

hdrs := resp.Header()
Expand Down Expand Up @@ -710,15 +719,19 @@ 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.enableDebug = atomic.Bool{}
a.enableDebug.Store(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.enableDebug = atomic.Bool{}
a.enableDebug.Store(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 @@ -1074,7 +1087,8 @@ func TestHTTPServer_PProfHandlers_EnableDebug(t *testing.T) {
resp := httptest.NewRecorder()
req, _ := http.NewRequest("GET", "/debug/pprof/profile?seconds=1", nil)

a.config.EnableDebug = true
a.enableDebug = atomic.Bool{}
a.enableDebug.Store(true)
httpServer := &HTTPHandlers{agent: a.Agent}
httpServer.handler().ServeHTTP(resp, req)

Expand Down Expand Up @@ -1175,7 +1189,9 @@ 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.enableDebug = atomic.Bool{}
a.enableDebug.Store(true)

a.srv.handler().ServeHTTP(resp, req)
assert.Equal(t, c.code, resp.Code)
})
Expand Down Expand Up @@ -1486,7 +1502,9 @@ func TestEnableWebUI(t *testing.T) {

req, _ := http.NewRequest("GET", "/ui/", nil)
resp := httptest.NewRecorder()
a.config.EnableDebug = true
a.enableDebug = atomic.Bool{}
a.enableDebug.Store(true)

a.srv.handler().ServeHTTP(resp, req)
require.Equal(t, http.StatusOK, resp.Code)

Expand Down Expand Up @@ -1516,7 +1534,9 @@ func TestEnableWebUI(t *testing.T) {
{
req, _ := http.NewRequest("GET", "/ui/", nil)
resp := httptest.NewRecorder()
a.config.EnableDebug = true
a.enableDebug = atomic.Bool{}
a.enableDebug.Store(true)

a.srv.handler().ServeHTTP(resp, req)
require.Equal(t, http.StatusOK, resp.Code)
require.Contains(t, resp.Body.String(), `<!-- CONSUL_VERSION:`)
Expand Down
4 changes: 3 additions & 1 deletion agent/ui_endpoint_oss_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,9 @@ func TestUIEndpoint_MetricsProxy_ACLDeny(t *testing.T) {
`, backendURL))
defer a.Shutdown()

a.config.EnableDebug = true
a.enableDebug = atomic.Bool{}
a.enableDebug.Store(true)

h := a.srv.handler()

testrpc.WaitForLeader(t, a.RPC, "dc1")
Expand Down
4 changes: 3 additions & 1 deletion agent/ui_endpoint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2620,7 +2620,9 @@ func TestUIEndpoint_MetricsProxy(t *testing.T) {
require.NoError(t, a.Agent.reloadConfigInternal(&cfg))

// Now fetch the API handler to run requests against
a.config.EnableDebug = true
a.enableDebug = atomic.Bool{}
a.enableDebug.Store(true)

h := a.srv.handler()

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

0 comments on commit 499f388

Please sign in to comment.