Skip to content

Commit

Permalink
Minor changes addressing code review feedbacks
Browse files Browse the repository at this point in the history
Signed-off-by: dttung2905 <ttdao.2015@accountancy.smu.edu.sg>
  • Loading branch information
dttung2905 committed Dec 23, 2022
1 parent f00ed41 commit 5a50a71
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 9 deletions.
6 changes: 1 addition & 5 deletions command/agent/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -792,11 +792,7 @@ func parseConsistency(resp http.ResponseWriter, req *http.Request, b *structs.Qu
resp.Write([]byte(fmt.Sprintf("Expect `true` or `false` for `stale` query string parameter, got %s", staleVal[0])))
}

if staleQuery || staleVal[0] == "" {
b.AllowStale = true
} else {
b.AllowStale = false
}
b.AllowStale = staleQuery || staleVal[0] == ""
}
}

Expand Down
9 changes: 5 additions & 4 deletions command/agent/http_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -480,8 +480,8 @@ func TestParseConsistency(t *testing.T) {
var resp *httptest.ResponseRecorder

testCases := [2]string{"/v1/catalog/nodes?stale", "/v1/catalog/nodes?stale=true"}
for _, url := range testCases {
req, err := http.NewRequest("GET", url, nil)
for _, urlPath := range testCases {
req, err := http.NewRequest("GET", urlPath, nil)
must.NoError(t, err)
resp = httptest.NewRecorder()
parseConsistency(resp, req, &b)
Expand All @@ -492,12 +492,13 @@ func TestParseConsistency(t *testing.T) {
must.NoError(t, err)
resp = httptest.NewRecorder()
parseConsistency(resp, req, &b)
must.True(t, !b.AllowStale)
must.False(t, b.AllowStale)

req, err = http.NewRequest("GET", "/v1/catalog/nodes?stale=random", nil)
must.NoError(t, err)
resp = httptest.NewRecorder()
parseConsistency(resp, req, &b)
must.False(t, b.AllowStale)
must.EqOp(t, resp.Code, 400)

b = structs.QueryOptions{}
Expand All @@ -506,7 +507,7 @@ func TestParseConsistency(t *testing.T) {

resp = httptest.NewRecorder()
parseConsistency(resp, req, &b)
must.True(t, !b.AllowStale)
must.False(t, b.AllowStale)
}

func TestParseRegion(t *testing.T) {
Expand Down

0 comments on commit 5a50a71

Please sign in to comment.