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

Commit 4f7ea73

Browse files
committed
chore: improve IPRestrictionRanges test
1 parent f285de4 commit 4f7ea73

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

groups_test.go

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -785,21 +785,38 @@ func TestUnshareGroupFromGroup(t *testing.T) {
785785

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

789790
mux.HandleFunc("/api/v4/groups/1",
790791
func(w http.ResponseWriter, r *http.Request) {
791792
testMethod(t, r, http.MethodPut)
792-
fmt.Fprint(w, `{"id": 1, "ip_restriction_ranges" : "192.168.0.0/24"}`)
793+
794+
body, err := io.ReadAll(r.Body)
795+
if err != nil {
796+
t.Fatalf("Failed to read the request body. Error: %v", err)
797+
}
798+
799+
var bodyJson map[string]interface{}
800+
err = json.Unmarshal(body, &bodyJson)
801+
if err != nil {
802+
t.Fatalf("Failed to parse the request body into JSON. Error: %v", err)
803+
}
804+
805+
if bodyJson["ip_restriction_ranges"] != ipRange {
806+
t.Fatalf("Test failed. `ip_restriction_ranges` expected to be '%v', got %v", ipRange, bodyJson["ip_restriction_ranges"])
807+
}
808+
809+
fmt.Fprintf(w, `{"id": 1, "ip_restriction_ranges" : "%v"}`, ipRange)
793810
})
794811

795812
group, _, err := client.Groups.UpdateGroup(1, &UpdateGroupOptions{
796-
IPRestrictionRanges: Ptr("192.168.0.0/24"),
813+
IPRestrictionRanges: Ptr(ipRange),
797814
})
798815
if err != nil {
799816
t.Errorf("Groups.UpdateGroup returned error: %v", err)
800817
}
801818

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

0 commit comments

Comments
 (0)