github.com/huaweicloud/golangsdk@v0.0.0-20210831081626-d823fe11ceba/openstack/compute/v2/extensions/extendedserverattributes/testing/requests_test.go (about) 1 package testing 2 3 import ( 4 "fmt" 5 "net/http" 6 "testing" 7 8 "github.com/huaweicloud/golangsdk/openstack/compute/v2/extensions/extendedserverattributes" 9 "github.com/huaweicloud/golangsdk/openstack/compute/v2/servers" 10 th "github.com/huaweicloud/golangsdk/testhelper" 11 fake "github.com/huaweicloud/golangsdk/testhelper/client" 12 ) 13 14 func TestServerWithUsageExt(t *testing.T) { 15 th.SetupHTTP() 16 defer th.TeardownHTTP() 17 18 th.Mux.HandleFunc("/servers/d650a0ce-17c3-497d-961a-43c4af80998a", func(w http.ResponseWriter, r *http.Request) { 19 th.TestMethod(t, r, "GET") 20 th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) 21 th.TestHeader(t, r, "Accept", "application/json") 22 23 fmt.Fprintf(w, ServerWithAttributesExtResult) 24 }) 25 26 type serverAttributesExt struct { 27 servers.Server 28 extendedserverattributes.ServerAttributesExt 29 } 30 var serverWithAttributesExt serverAttributesExt 31 err := servers.Get(fake.ServiceClient(), "d650a0ce-17c3-497d-961a-43c4af80998a").ExtractInto(&serverWithAttributesExt) 32 th.AssertNoErr(t, err) 33 34 th.AssertEquals(t, serverWithAttributesExt.Host, "compute01") 35 th.AssertEquals(t, serverWithAttributesExt.InstanceName, "instance-00000001") 36 th.AssertEquals(t, serverWithAttributesExt.HypervisorHostname, "compute01") 37 }