github.com/vnpaycloud-console/gophercloud/v2@v2.0.5/openstack/containerinfra/v1/clustertemplates/testing/requests_test.go (about) 1 package testing 2 3 import ( 4 "context" 5 "testing" 6 7 "github.com/vnpaycloud-console/gophercloud/v2/openstack/containerinfra/v1/clustertemplates" 8 "github.com/vnpaycloud-console/gophercloud/v2/pagination" 9 th "github.com/vnpaycloud-console/gophercloud/v2/testhelper" 10 fake "github.com/vnpaycloud-console/gophercloud/v2/testhelper/client" 11 ) 12 13 func TestCreateClusterTemplate(t *testing.T) { 14 th.SetupHTTP() 15 defer th.TeardownHTTP() 16 17 HandleCreateClusterTemplateSuccessfully(t) 18 19 boolFalse := false 20 boolTrue := true 21 dockerVolumeSize := 3 22 opts := clustertemplates.CreateOpts{ 23 Name: "kubernetes-dev", 24 Labels: map[string]string{}, 25 FixedSubnet: "", 26 MasterFlavorID: "", 27 NoProxy: "10.0.0.0/8,172.0.0.0/8,192.0.0.0/8,localhost", 28 HTTPSProxy: "http://10.164.177.169:8080", 29 TLSDisabled: &boolFalse, 30 KeyPairID: "kp", 31 Public: &boolFalse, 32 HTTPProxy: "http://10.164.177.169:8080", 33 DockerVolumeSize: &dockerVolumeSize, 34 ServerType: "vm", 35 ExternalNetworkID: "public", 36 ImageID: "Fedora-Atomic-27-20180212.2.x86_64", 37 VolumeDriver: "cinder", 38 RegistryEnabled: &boolFalse, 39 DockerStorageDriver: "devicemapper", 40 NetworkDriver: "flannel", 41 FixedNetwork: "", 42 COE: "kubernetes", 43 FlavorID: "m1.small", 44 MasterLBEnabled: &boolTrue, 45 DNSNameServer: "8.8.8.8", 46 Hidden: &boolTrue, 47 } 48 49 sc := fake.ServiceClient() 50 sc.Endpoint = sc.Endpoint + "v1/" 51 res := clustertemplates.Create(context.TODO(), sc, opts) 52 th.AssertNoErr(t, res.Err) 53 54 requestID := res.Header.Get("X-OpenStack-Request-Id") 55 th.AssertEquals(t, "req-781e9bdc-4163-46eb-91c9-786c53188bbb", requestID) 56 57 actual, err := res.Extract() 58 th.AssertNoErr(t, err) 59 60 actual.CreatedAt = actual.CreatedAt.UTC() 61 th.AssertDeepEquals(t, ExpectedClusterTemplate, *actual) 62 } 63 64 func TestDeleteClusterTemplate(t *testing.T) { 65 th.SetupHTTP() 66 defer th.TeardownHTTP() 67 68 HandleDeleteClusterSuccessfully(t) 69 70 sc := fake.ServiceClient() 71 sc.Endpoint = sc.Endpoint + "v1/" 72 res := clustertemplates.Delete(context.TODO(), sc, "6dc6d336e3fc4c0a951b5698cd1236ee") 73 th.AssertNoErr(t, res.Err) 74 requestID := res.Header["X-Openstack-Request-Id"][0] 75 th.AssertEquals(t, "req-781e9bdc-4163-46eb-91c9-786c53188bbb", requestID) 76 } 77 78 func TestListClusterTemplates(t *testing.T) { 79 th.SetupHTTP() 80 defer th.TeardownHTTP() 81 82 HandleListClusterTemplateSuccessfully(t) 83 84 count := 0 85 86 sc := fake.ServiceClient() 87 sc.Endpoint = sc.Endpoint + "v1/" 88 err := clustertemplates.List(sc, clustertemplates.ListOpts{Limit: 2}).EachPage(context.TODO(), func(_ context.Context, page pagination.Page) (bool, error) { 89 count++ 90 actual, err := clustertemplates.ExtractClusterTemplates(page) 91 th.AssertNoErr(t, err) 92 for idx := range actual { 93 actual[idx].CreatedAt = actual[idx].CreatedAt.UTC() 94 } 95 th.AssertDeepEquals(t, ExpectedClusterTemplates, actual) 96 97 return true, nil 98 }) 99 th.AssertNoErr(t, err) 100 101 if count != 1 { 102 t.Errorf("Expected 1 page, got %d", count) 103 } 104 } 105 106 func TestGetClusterTemplate(t *testing.T) { 107 th.SetupHTTP() 108 defer th.TeardownHTTP() 109 110 HandleGetClusterTemplateSuccessfully(t) 111 112 sc := fake.ServiceClient() 113 sc.Endpoint = sc.Endpoint + "v1/" 114 actual, err := clustertemplates.Get(context.TODO(), sc, "7d85f602-a948-4a30-afd4-e84f47471c15").Extract() 115 th.AssertNoErr(t, err) 116 actual.CreatedAt = actual.CreatedAt.UTC() 117 th.AssertDeepEquals(t, ExpectedClusterTemplate, *actual) 118 } 119 120 func TestGetClusterTemplateEmptyTime(t *testing.T) { 121 th.SetupHTTP() 122 defer th.TeardownHTTP() 123 124 HandleGetClusterTemplateEmptyTimeSuccessfully(t) 125 126 sc := fake.ServiceClient() 127 sc.Endpoint = sc.Endpoint + "v1/" 128 actual, err := clustertemplates.Get(context.TODO(), sc, "7d85f602-a948-4a30-afd4-e84f47471c15").Extract() 129 th.AssertNoErr(t, err) 130 actual.CreatedAt = actual.CreatedAt.UTC() 131 th.AssertDeepEquals(t, ExpectedClusterTemplate_EmptyTime, *actual) 132 } 133 134 func TestUpdateClusterTemplate(t *testing.T) { 135 th.SetupHTTP() 136 defer th.TeardownHTTP() 137 138 HandleUpdateClusterTemplateSuccessfully(t) 139 140 updateOpts := []clustertemplates.UpdateOptsBuilder{ 141 clustertemplates.UpdateOpts{ 142 Path: "/master_lb_enabled", 143 Value: "True", 144 Op: clustertemplates.ReplaceOp, 145 }, 146 clustertemplates.UpdateOpts{ 147 Path: "/registry_enabled", 148 Value: "True", 149 Op: clustertemplates.ReplaceOp, 150 }, 151 } 152 153 sc := fake.ServiceClient() 154 sc.Endpoint = sc.Endpoint + "v1/" 155 res := clustertemplates.Update(context.TODO(), sc, "7d85f602-a948-4a30-afd4-e84f47471c15", updateOpts) 156 th.AssertNoErr(t, res.Err) 157 158 actual, err := res.Extract() 159 th.AssertNoErr(t, err) 160 actual.CreatedAt = actual.CreatedAt.UTC() 161 th.AssertDeepEquals(t, ExpectedUpdateClusterTemplate, *actual) 162 } 163 164 func TestUpdateClusterTemplateEmptyTime(t *testing.T) { 165 th.SetupHTTP() 166 defer th.TeardownHTTP() 167 168 HandleUpdateClusterTemplateEmptyTimeSuccessfully(t) 169 170 updateOpts := []clustertemplates.UpdateOptsBuilder{ 171 clustertemplates.UpdateOpts{ 172 Op: clustertemplates.ReplaceOp, 173 Path: "/master_lb_enabled", 174 Value: "True", 175 }, 176 clustertemplates.UpdateOpts{ 177 Op: clustertemplates.ReplaceOp, 178 Path: "/registry_enabled", 179 Value: "True", 180 }, 181 } 182 183 sc := fake.ServiceClient() 184 sc.Endpoint = sc.Endpoint + "v1/" 185 actual, err := clustertemplates.Update(context.TODO(), sc, "7d85f602-a948-4a30-afd4-e84f47471c15", updateOpts).Extract() 186 th.AssertNoErr(t, err) 187 th.AssertDeepEquals(t, ExpectedUpdateClusterTemplate_EmptyTime, *actual) 188 } 189 190 func TestUpdateClusterTemplateInvalidUpdate(t *testing.T) { 191 th.SetupHTTP() 192 defer th.TeardownHTTP() 193 194 HandleUpdateClusterTemplateInvalidUpdate(t) 195 196 updateOpts := []clustertemplates.UpdateOptsBuilder{ 197 clustertemplates.UpdateOpts{ 198 Op: clustertemplates.ReplaceOp, 199 Path: "/master_lb_enabled", 200 }, 201 clustertemplates.UpdateOpts{ 202 Op: clustertemplates.RemoveOp, 203 Path: "/master_lb_enabled", 204 }, 205 clustertemplates.UpdateOpts{ 206 Op: clustertemplates.AddOp, 207 Path: "/master_lb_enabled", 208 }, 209 } 210 211 sc := fake.ServiceClient() 212 sc.Endpoint = sc.Endpoint + "v1/" 213 _, err := clustertemplates.Update(context.TODO(), sc, "7d85f602-a948-4a30-afd4-e84f47471c15", updateOpts).Extract() 214 th.AssertEquals(t, true, err != nil) 215 }