Verified Commit 2d341d99 authored by Patrick Rice's avatar Patrick Rice 🫖 Committed by GitLab
Browse files

test(namespaces): Address test feedback to simplify the test

Changelog: Improvements
parent beea2c16
Loading
Loading
Loading
Loading
+6 −37
Original line number Diff line number Diff line
@@ -300,49 +300,18 @@ func TestGetNamespaceWithSlashInID(t *testing.T) {
	mux, client := setup(t)

	// GIVEN a namespace with a slash in the ID (e.g., "my/namespace")
	// WHEN GetNamespace is called with this ID
	// THEN the URL should be encoded once as "my%2Fnamespace", not double-encoded as "my%252Fnamespace"
	mux.HandleFunc("/api/v4/namespaces/my%2Fnamespace", func(w http.ResponseWriter, r *http.Request) {
		testMethod(t, r, http.MethodGet)

		// Only respond successfully if the path is correctly single-encoded
		fmt.Fprintf(w, `{
				"id": 5,
				"name": "namespace",
				"path": "namespace",
				"kind": "group",
				"full_path": "my/namespace",
				"avatar_url": null,
				"web_url": "https://gitlab.example.com/groups/my/namespace",
				"members_count_with_descendants": 1,
				"billable_members_count": 1,
				"max_seats_used": 0,
				"seats_in_use": 0,
				"plan": "default",
				"trial_ends_on": null,
				"trial": false
		 }`)
		// Print a simple ID attribute since the point of the test is only the URL escaping
		mustWriteJSONResponse(t, w, &Namespace{ID: 5})
	})

	// WHEN GetNamespace is called with this ID
	namespace, _, err := client.Namespaces.GetNamespace("my/namespace")
	require.NoError(t, err)

	want := &Namespace{
		ID:                          5,
		Name:                        "namespace",
		Path:                        "namespace",
		Kind:                        "group",
		FullPath:                    "my/namespace",
		AvatarURL:                   nil,
		WebURL:                      "https://gitlab.example.com/groups/my/namespace",
		MembersCountWithDescendants: 1,
		BillableMembersCount:        1,
		MaxSeatsUsed:                Ptr(int64(0)),
		SeatsInUse:                  Ptr(int64(0)),
		Plan:                        "default",
		TrialEndsOn:                 nil,
		Trial:                       false,
	}

	// THEN the URL should be encoded once as "my%2Fnamespace", not double-encoded as "my%252Fnamespace"
	// Note - this is validated by getting the response back from the mux.
	want := &Namespace{ID: 5}
	assert.Equal(t, want, namespace)
}