Skip to content

Commit

Permalink
fix so assertions are test case driven
Browse files Browse the repository at this point in the history
  • Loading branch information
drewbailey committed Nov 12, 2019
1 parent e84eed8 commit e187a7f
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions command/agent/http_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ func TestRootFallthrough(t *testing.T) {
cases := []struct {
desc string
path string
expectedPath string
expectedCode int
}{
{
Expand All @@ -80,33 +81,34 @@ func TestRootFallthrough(t *testing.T) {
{
desc: "root path redirects to ui",
path: "/",
expectedPath: "/ui/",
expectedCode: 307,
},
}

s := makeHTTPServer(t, nil)
defer s.Shutdown()

// setup a client that doesn't follow redirects
client := &http.Client{
CheckRedirect: func(_ *http.Request, _ []*http.Request) error {
return http.ErrUseLastResponse
},
}

for _, tc := range cases {
t.Run(tc.desc, func(t *testing.T) {

reqURL := fmt.Sprintf("http://%s%s", s.Agent.config.AdvertiseAddrs.HTTP, tc.path)

// setup a client that doesn't follow redirects
client := &http.Client{
CheckRedirect: func(_ *http.Request, _ []*http.Request) error {
return http.ErrUseLastResponse
},
}

resp, err := client.Get(reqURL)
require.NoError(t, err)
require.Equal(t, tc.expectedCode, resp.StatusCode)

if tc.expectedCode == 307 {
if tc.expectedPath != "" {
loc, err := resp.Location()
require.NoError(t, err)
require.Equal(t, "/ui/", loc.Path)
require.Equal(t, tc.expectedPath, loc.Path)
}
})
}
Expand Down

0 comments on commit e187a7f

Please sign in to comment.