Skip to content
This repository has been archived by the owner on Dec 10, 2024. It is now read-only.

Commit

Permalink
chore: improve IPRestrictionRanges test
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremad committed Nov 15, 2024
1 parent f285de4 commit fd1c548
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions groups_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -785,21 +785,38 @@ func TestUnshareGroupFromGroup(t *testing.T) {

func TestUpdateGroupWithIPRestrictionRanges(t *testing.T) {
mux, client := setup(t)
const ipRange = "192.168.0.0/24"

mux.HandleFunc("/api/v4/groups/1",
func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, http.MethodPut)
fmt.Fprint(w, `{"id": 1, "ip_restriction_ranges" : "192.168.0.0/24"}`)

body, err := io.ReadAll(r.Body)
if err != nil {
t.Fatalf("Failed to read the request body. Error: %v", err)
}

var bodyJson map[string]interface{}
err = json.Unmarshal(body, &bodyJson)
if err != nil {
t.Fatalf("Failed to parse the request body into JSON. Error: %v", err)
}

if bodyJson["ip_restriction_ranges"] != ipRange {
t.Fatalf("Test failed. `allowed_email_domains_list` expected to be '%v', got %v", ipRange, bodyJson["ip_restriction_ranges"])
}

fmt.Fprintf(w, `{"id": 1, "ip_restriction_ranges" : "%v"}`, ipRange)
})

group, _, err := client.Groups.UpdateGroup(1, &UpdateGroupOptions{
IPRestrictionRanges: Ptr("192.168.0.0/24"),
IPRestrictionRanges: Ptr(ipRange),
})
if err != nil {
t.Errorf("Groups.UpdateGroup returned error: %v", err)
}

want := &Group{ID: 1, IPRestrictionRanges: "192.168.0.0/24"}
want := &Group{ID: 1, IPRestrictionRanges: ipRange}
if !reflect.DeepEqual(want, group) {
t.Errorf("Groups.UpdatedGroup returned %+v, want %+v", group, want)
}
Expand Down

0 comments on commit fd1c548

Please sign in to comment.