github.com/vnpaycloud-console/gophercloud/v2@v2.0.5/openstack/baremetalintrospection/v1/introspection/testing/requests_test.go (about) 1 package testing 2 3 import ( 4 "context" 5 "testing" 6 7 "github.com/vnpaycloud-console/gophercloud/v2/openstack/baremetalintrospection/v1/introspection" 8 "github.com/vnpaycloud-console/gophercloud/v2/pagination" 9 th "github.com/vnpaycloud-console/gophercloud/v2/testhelper" 10 "github.com/vnpaycloud-console/gophercloud/v2/testhelper/client" 11 ) 12 13 func TestListIntrospections(t *testing.T) { 14 th.SetupHTTP() 15 defer th.TeardownHTTP() 16 HandleListIntrospectionsSuccessfully(t) 17 18 pages := 0 19 err := introspection.ListIntrospections(client.ServiceClient(), introspection.ListIntrospectionsOpts{}).EachPage(context.TODO(), func(_ context.Context, page pagination.Page) (bool, error) { 20 pages++ 21 22 actual, err := introspection.ExtractIntrospections(page) 23 if err != nil { 24 return false, err 25 } 26 27 if len(actual) != 2 { 28 t.Fatalf("Expected 2 introspections, got %d", len(actual)) 29 } 30 th.CheckDeepEquals(t, IntrospectionFoo, actual[0]) 31 th.CheckDeepEquals(t, IntrospectionBar, actual[1]) 32 33 return true, nil 34 }) 35 36 th.AssertNoErr(t, err) 37 38 if pages != 1 { 39 t.Errorf("Expected 1 page, saw %d", pages) 40 } 41 } 42 43 func TestGetIntrospectionStatus(t *testing.T) { 44 th.SetupHTTP() 45 defer th.TeardownHTTP() 46 HandleGetIntrospectionStatusSuccessfully(t) 47 48 c := client.ServiceClient() 49 actual, err := introspection.GetIntrospectionStatus(context.TODO(), c, "c244557e-899f-46fa-a1ff-5b2c6718616b").Extract() 50 if err != nil { 51 t.Fatalf("Unexpected Get error: %v", err) 52 } 53 54 th.CheckDeepEquals(t, IntrospectionBar, *actual) 55 } 56 57 func TestStartIntrospection(t *testing.T) { 58 th.SetupHTTP() 59 defer th.TeardownHTTP() 60 HandleStartIntrospectionSuccessfully(t) 61 62 c := client.ServiceClient() 63 err := introspection.StartIntrospection(context.TODO(), c, "c244557e-899f-46fa-a1ff-5b2c6718616b", introspection.StartOpts{}).ExtractErr() 64 th.AssertNoErr(t, err) 65 } 66 67 func TestAbortIntrospection(t *testing.T) { 68 th.SetupHTTP() 69 defer th.TeardownHTTP() 70 HandleAbortIntrospectionSuccessfully(t) 71 72 c := client.ServiceClient() 73 err := introspection.AbortIntrospection(context.TODO(), c, "c244557e-899f-46fa-a1ff-5b2c6718616b").ExtractErr() 74 th.AssertNoErr(t, err) 75 } 76 77 func TestGetIntrospectionData(t *testing.T) { 78 th.SetupHTTP() 79 defer th.TeardownHTTP() 80 HandleGetIntrospectionDataSuccessfully(t) 81 82 c := client.ServiceClient() 83 actual, err := introspection.GetIntrospectionData(context.TODO(), c, "c244557e-899f-46fa-a1ff-5b2c6718616b").Extract() 84 if err != nil { 85 t.Fatalf("Unexpected Get error: %v", err) 86 } 87 88 th.CheckDeepEquals(t, IntrospectionDataRes, *actual) 89 } 90 91 func TestReApplyIntrospection(t *testing.T) { 92 th.SetupHTTP() 93 defer th.TeardownHTTP() 94 HandleReApplyIntrospectionSuccessfully(t) 95 96 c := client.ServiceClient() 97 err := introspection.ReApplyIntrospection(context.TODO(), c, "c244557e-899f-46fa-a1ff-5b2c6718616b").ExtractErr() 98 th.AssertNoErr(t, err) 99 }