Skip to content

Commit

Permalink
Changes from code review to use github.com/shoenig/test package
Browse files Browse the repository at this point in the history
Signed-off-by: dttung2905 <[email protected]>
  • Loading branch information
dttung2905 committed Dec 22, 2022
1 parent 4ed12c9 commit b4141e7
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 16 deletions.
2 changes: 2 additions & 0 deletions command/agent/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -794,6 +794,8 @@ func parseConsistency(resp http.ResponseWriter, req *http.Request, b *structs.Qu

if staleQuery || staleVal[0] == "" {
b.AllowStale = true
} else {
b.AllowStale = false
}
}
}
Expand Down
28 changes: 12 additions & 16 deletions command/agent/http_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -479,35 +479,31 @@ func TestParseConsistency(t *testing.T) {
var b structs.QueryOptions
var resp *httptest.ResponseRecorder

testCases := [3]string{"/v1/catalog/nodes?stale", "/v1/catalog/nodes?stale=true", "/v1/catalog/nodes?stale=false"}
testCases := [2]string{"/v1/catalog/nodes?stale", "/v1/catalog/nodes?stale=true"}
for _, url := range testCases {
req, err := http.NewRequest("GET",
url, nil)
req, err := http.NewRequest("GET", url, nil)
must.NoError(t, err)
resp = httptest.NewRecorder()
parseConsistency(resp, req, &b)
if !b.AllowStale {
t.Fatalf("Bad: %v", b)
}
must.True(t, b.AllowStale)
}

req, err := http.NewRequest("GET", "/v1/catalog/nodes?stale=random", nil)
if err != nil {
t.Fatalf("err: %v", err)
}
req, err := http.NewRequest("GET", "/v1/catalog/nodes?stale=false", nil)
must.Nil(t, err, must.Sprintf("err: %v", err))
resp = httptest.NewRecorder()
parseConsistency(resp, req, &b)
must.True(t, !b.AllowStale)

req, err = http.NewRequest("GET", "/v1/catalog/nodes?stale=random", nil)
must.Nil(t, err, must.Sprintf("err: %v", err))
resp = httptest.NewRecorder()
parseConsistency(resp, req, &b)
if resp.Code != 400 {
t.Fatalf("bad code: %v", resp.Code)
}
must.EqOp(t, resp.Code, 400)

b = structs.QueryOptions{}
req, err = http.NewRequest("GET",
"/v1/catalog/nodes?consistent", nil)
if err != nil {
t.Fatalf("err: %v", err)
}
must.Nil(t, err, must.Sprintf("err: %v", err))

resp = httptest.NewRecorder()
parseConsistency(resp, req, &b)
Expand Down

0 comments on commit b4141e7

Please sign in to comment.