Skip to content

Commit

Permalink
add test on query args
Browse files Browse the repository at this point in the history
  • Loading branch information
pablo-ruth committed Aug 5, 2022
1 parent 4c2ee34 commit 4356b83
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ func TestClient_NewRequest(t *testing.T) {
host string
path string
vdom string
query string
}

// Create test cases
Expand All @@ -24,20 +25,23 @@ func TestClient_NewRequest(t *testing.T) {
host: "localhost:8080",
path: "/api/v1/status/system",
vdom: "",
query: "",
},
{
method: "POST",
url: "http://localhost:8080/api/v1/status/system",
host: "localhost:8080",
path: "/api/v1/status/system",
vdom: "root",
query: "vdom=root",
},
{
method: "POST",
url: "http://localhost:8080/api/load_balance_virtual_server?mkey=test",
host: "localhost:8080",
path: "/api/load_balance_virtual_server",
vdom: "root",
query: "mkey=test&vdom=root",
},
}
// Iterate over test cases
Expand Down Expand Up @@ -82,5 +86,10 @@ func TestClient_NewRequest(t *testing.T) {
if tc.vdom == "" && req.URL.Query().Get("vdom") != "" {
t.Errorf("vdom parameter is set")
}

// Test if query parameter is set with the correct value
if tc.query != "" && req.URL.RawQuery != tc.query {
t.Errorf("query parameter is not set with the correct value, expected: %s, got: %s", tc.query, req.URL.RawQuery)
}
}
}

0 comments on commit 4356b83

Please sign in to comment.