github.com/huaweicloud/golangsdk@v0.0.0-20210831081626-d823fe11ceba/openstack/compute/v2/extensions/serverusage/testing/requests_test.go (about) 1 package testing 2 3 import ( 4 "fmt" 5 "net/http" 6 "testing" 7 "time" 8 9 "github.com/huaweicloud/golangsdk/openstack/compute/v2/extensions/serverusage" 10 "github.com/huaweicloud/golangsdk/openstack/compute/v2/servers" 11 th "github.com/huaweicloud/golangsdk/testhelper" 12 fake "github.com/huaweicloud/golangsdk/testhelper/client" 13 ) 14 15 func TestServerWithUsageExt(t *testing.T) { 16 th.SetupHTTP() 17 defer th.TeardownHTTP() 18 19 th.Mux.HandleFunc("/servers/d650a0ce-17c3-497d-961a-43c4af80998a", func(w http.ResponseWriter, r *http.Request) { 20 th.TestMethod(t, r, "GET") 21 th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) 22 th.TestHeader(t, r, "Accept", "application/json") 23 24 fmt.Fprintf(w, ServerWithUsageExtResult) 25 }) 26 27 type serverUsageExt struct { 28 servers.Server 29 serverusage.UsageExt 30 } 31 var serverWithUsageExt serverUsageExt 32 err := servers.Get(fake.ServiceClient(), "d650a0ce-17c3-497d-961a-43c4af80998a").ExtractInto(&serverWithUsageExt) 33 th.AssertNoErr(t, err) 34 35 th.AssertEquals(t, serverWithUsageExt.LaunchedAt, time.Date(2018, 07, 27, 9, 15, 55, 0, time.UTC)) 36 th.AssertEquals(t, serverWithUsageExt.TerminatedAt, time.Time{}) 37 th.AssertEquals(t, serverWithUsageExt.Created, time.Date(2018, 07, 27, 9, 15, 48, 0, time.UTC)) 38 th.AssertEquals(t, serverWithUsageExt.Updated, time.Date(2018, 07, 27, 9, 15, 55, 0, time.UTC)) 39 th.AssertEquals(t, serverWithUsageExt.ID, "d650a0ce-17c3-497d-961a-43c4af80998a") 40 th.AssertEquals(t, serverWithUsageExt.Name, "test_instance") 41 th.AssertEquals(t, serverWithUsageExt.Status, "ACTIVE") 42 th.AssertEquals(t, serverWithUsageExt.UserID, "0f2f3822679e4b3ea073e5d1c6ed5f02") 43 th.AssertEquals(t, serverWithUsageExt.TenantID, "424e7cf0243c468ca61732ba45973b3e") 44 }