github.com/huaweicloud/golangsdk@v0.0.0-20210831081626-d823fe11ceba/openstack/compute/v2/extensions/attachinterfaces/testing/requests_test.go (about) 1 package testing 2 3 import ( 4 "testing" 5 6 "github.com/huaweicloud/golangsdk/openstack/compute/v2/extensions/attachinterfaces" 7 "github.com/huaweicloud/golangsdk/pagination" 8 th "github.com/huaweicloud/golangsdk/testhelper" 9 "github.com/huaweicloud/golangsdk/testhelper/client" 10 ) 11 12 func TestListInterface(t *testing.T) { 13 th.SetupHTTP() 14 defer th.TeardownHTTP() 15 HandleInterfaceListSuccessfully(t) 16 17 expected := ListInterfacesExpected 18 pages := 0 19 err := attachinterfaces.List(client.ServiceClient(), "b07e7a3b-d951-4efc-a4f9-ac9f001afb7f").EachPage(func(page pagination.Page) (bool, error) { 20 pages++ 21 22 actual, err := attachinterfaces.ExtractInterfaces(page) 23 th.AssertNoErr(t, err) 24 25 if len(actual) != 1 { 26 t.Fatalf("Expected 1 interface, got %d", len(actual)) 27 } 28 th.CheckDeepEquals(t, expected, actual) 29 30 return true, nil 31 }) 32 th.AssertNoErr(t, err) 33 th.CheckEquals(t, 1, pages) 34 } 35 36 func TestListInterfacesAllPages(t *testing.T) { 37 th.SetupHTTP() 38 defer th.TeardownHTTP() 39 HandleInterfaceListSuccessfully(t) 40 41 allPages, err := attachinterfaces.List(client.ServiceClient(), "b07e7a3b-d951-4efc-a4f9-ac9f001afb7f").AllPages() 42 th.AssertNoErr(t, err) 43 _, err = attachinterfaces.ExtractInterfaces(allPages) 44 th.AssertNoErr(t, err) 45 } 46 47 func TestGetInterface(t *testing.T) { 48 th.SetupHTTP() 49 defer th.TeardownHTTP() 50 HandleInterfaceGetSuccessfully(t) 51 52 expected := GetInterfaceExpected 53 54 serverID := "b07e7a3b-d951-4efc-a4f9-ac9f001afb7f" 55 interfaceID := "0dde1598-b374-474e-986f-5b8dd1df1d4e" 56 57 actual, err := attachinterfaces.Get(client.ServiceClient(), serverID, interfaceID).Extract() 58 th.AssertNoErr(t, err) 59 th.CheckDeepEquals(t, &expected, actual) 60 } 61 62 func TestCreateInterface(t *testing.T) { 63 th.SetupHTTP() 64 defer th.TeardownHTTP() 65 HandleInterfaceCreateSuccessfully(t) 66 67 expected := CreateInterfacesExpected 68 69 serverID := "b07e7a3b-d951-4efc-a4f9-ac9f001afb7f" 70 networkID := "8a5fe506-7e9f-4091-899b-96336909d93c" 71 72 actual, err := attachinterfaces.Create(client.ServiceClient(), serverID, attachinterfaces.CreateOpts{ 73 NetworkID: networkID, 74 }).Extract() 75 th.AssertNoErr(t, err) 76 th.CheckDeepEquals(t, &expected, actual) 77 } 78 79 func TestDeleteInterface(t *testing.T) { 80 th.SetupHTTP() 81 defer th.TeardownHTTP() 82 HandleInterfaceDeleteSuccessfully(t) 83 84 serverID := "b07e7a3b-d951-4efc-a4f9-ac9f001afb7f" 85 portID := "0dde1598-b374-474e-986f-5b8dd1df1d4e" 86 87 err := attachinterfaces.Delete(client.ServiceClient(), serverID, portID).ExtractErr() 88 th.AssertNoErr(t, err) 89 }