github.com/opentelekomcloud/gophertelekomcloud@v0.9.3/openstack/identity/v3/agency/testing/requests_test.go (about) 1 package testing 2 3 import ( 4 "fmt" 5 "net/http" 6 "testing" 7 8 "github.com/opentelekomcloud/gophertelekomcloud/openstack/identity/v3/agency" 9 th "github.com/opentelekomcloud/gophertelekomcloud/testhelper" 10 mock "github.com/opentelekomcloud/gophertelekomcloud/testhelper/client" 11 ) 12 13 func TestAgencyList(t *testing.T) { 14 th.SetupHTTP() 15 t.Cleanup(th.TeardownHTTP) 16 17 th.Mux.HandleFunc("/OS-AGENCY/agencies", func(w http.ResponseWriter, r *http.Request) { 18 th.TestMethod(t, r, "GET") 19 th.TestHeader(t, r, "X-Auth-Token", mock.TokenID) 20 th.TestHeader(t, r, "Content-Type", "application/json") 21 22 w.Header().Add("Content-Type", "application/json") 23 w.WriteHeader(http.StatusOK) 24 _, _ = fmt.Fprint(w, agencyListResponse) 25 }) 26 27 opts := agency.ListOpts{} 28 pages, err := agency.List(mock.ServiceClient(), opts).AllPages() 29 th.AssertNoErr(t, err) 30 31 agencies, err := agency.ExtractAgencies(pages) 32 th.AssertNoErr(t, err) 33 th.AssertEquals(t, 1, len(agencies)) 34 th.AssertEquals(t, "afca8ddf2e92469a8fd26a635da5206f", agencies[0].ID) 35 }