github.com/huaweicloud/golangsdk@v0.0.0-20210831081626-d823fe11ceba/openstack/cci/v1/persistentvolumeclaims/testing/fixtures.go (about) 1 package testing 2 3 import ( 4 "fmt" 5 "net/http" 6 "testing" 7 8 "github.com/huaweicloud/golangsdk/openstack/cci/v1/persistentvolumeclaims" 9 th "github.com/huaweicloud/golangsdk/testhelper" 10 "github.com/huaweicloud/golangsdk/testhelper/client" 11 ) 12 13 const ( 14 expectedRequest = ` 15 { 16 "apiVersion": "v1", 17 "kind": "PersistentVolumeClaim", 18 "metadata": { 19 "annotations": { 20 "fsType": "ext4", 21 "volumeID": "46d10433-35fb-459b-8482-2dd6fa192262" 22 }, 23 "name": "cci-ssd-test-demo", 24 "namespace": "terraform-test" 25 }, 26 "spec": { 27 "resources": { 28 "requests": { 29 "storage": "10Gi" 30 } 31 }, 32 "storageClassName": "ssd" 33 } 34 }` 35 36 expectedCreateResponse = ` 37 { 38 "kind": "PersistentVolumeClaim", 39 "apiVersion": "v1", 40 "metadata": { 41 "name": "cci-ssd-test-demo", 42 "namespace": "terraform-test", 43 "selfLink": "/api/v1/namespaces/terraform-test/persistentvolumeclaims/cci-ssd-test-demo", 44 "uid": "1ae26e9c-9e39-432d-9438-e6c669670629", 45 "resourceVersion": "285666212", 46 "creationTimestamp": "2021-05-25T03:45:45Z", 47 "labels": { 48 "failure-domain.beta.kubernetes.io/region": "cn-north-4", 49 "failure-domain.beta.kubernetes.io/zone": "cn-north-4a" 50 }, 51 "annotations": { 52 "kubernetes.io/volumeId": "46d10433-35fb-459b-8482-2dd6fa192262" 53 }, 54 "finalizers": [ 55 "kubernetes.io/pvc-protection" 56 ] 57 }, 58 "spec": { 59 "accessModes": [ 60 "ReadWriteMany" 61 ], 62 "resources": { 63 "requests": { 64 "storage": "10Gi" 65 } 66 }, 67 "volumeName": "cci-evs-import-46d10433-35fb-459b-8482-2dd6fa192262", 68 "storageClassName": "ssd", 69 "volumeMode": "Filesystem" 70 }, 71 "status": { 72 "phase": "Pending" 73 } 74 }` 75 76 expectedListResponse = ` 77 [ 78 { 79 "persistentVolumeClaim": { 80 "metadata": { 81 "name": "cci-ssd-test-demo", 82 "namespace": "terraform-test", 83 "selfLink": "/api/v1/namespaces/terraform-test/persistentvolumeclaims/cci-ssd-test-demo", 84 "uid": "acf521b6-1e60-4ecd-af4a-671005e6d4bd", 85 "resourceVersion": "285728642", 86 "creationTimestamp": "2021-05-25T06:26:29Z", 87 "labels": { 88 "failure-domain.beta.kubernetes.io/region": "cn-north-4", 89 "failure-domain.beta.kubernetes.io/zone": "cn-north-4a" 90 }, 91 "annotations": { 92 "kubernetes.io/volumeId": "45571ae3-125a-4cfa-bd76-a76eedcde45a" 93 }, 94 "finalizers": [ 95 "kubernetes.io/pvc-protection" 96 ] 97 }, 98 "spec": { 99 "accessModes": [ 100 "ReadWriteMany" 101 ], 102 "resources": { 103 "requests": { 104 "storage": "10Gi" 105 } 106 }, 107 "volumeName": "cci-evs-import-45571ae3-125a-4cfa-bd76-a76eedcde45a", 108 "storageClassName": "ssd", 109 "volumeMode": "Filesystem" 110 }, 111 "status": { 112 "phase": "Pending" 113 } 114 }, 115 "persistentVolume": { 116 "metadata": { 117 "name": "cci-evs-import-45571ae3-125a-4cfa-bd76-a76eedcde45a", 118 "selfLink": "/api/v1/persistentvolumes/cci-evs-import-45571ae3-125a-4cfa-bd76-a76eedcde45a", 119 "uid": "e8dc63e5-014d-4e39-970c-5cc151e92144", 120 "resourceVersion": "285728644", 121 "creationTimestamp": "2021-05-25T06:26:29Z", 122 "labels": { 123 "failure-domain.beta.kubernetes.io/region": "cn-north-4", 124 "failure-domain.beta.kubernetes.io/zone": "cn-north-4a", 125 "tenant.kubernetes.io/domain-id": "0970d7b7d400f2470fbec00316a03560", 126 "tenant.kubernetes.io/project-id": "0970dd7a1300f5672ff2c003c60ae115" 127 }, 128 "annotations": { 129 "kubernetes.io/createdby": "cci-apiserver", 130 "pv.kubernetes.io/bound-by-cci": "yes", 131 "pv.kubernetes.io/namespace": "terraform-test", 132 "tenant.kubernetes.io/domain-id": "0970d7b7d400f2470fbec00316a03560", 133 "tenant.kubernetes.io/project-id": "0970dd7a1300f5672ff2c003c60ae115" 134 }, 135 "finalizers": [ 136 "kubernetes.io/pv-protection" 137 ] 138 }, 139 "spec": { 140 "capacity": { 141 "storage": "10Gi" 142 }, 143 "flexVolume": { 144 "driver": "huawei.com/fuxivol", 145 "fsType": "ext4", 146 "options": { 147 "fsType": "ext4", 148 "storage_class": "ssd", 149 "volumeID": "45571ae3-125a-4cfa-bd76-a76eedcde45a" 150 } 151 }, 152 "accessModes": [ 153 "ReadWriteMany" 154 ], 155 "claimRef": { 156 "namespace": "terraform-test", 157 "name": "cci-ssd-test-demo" 158 }, 159 "persistentVolumeReclaimPolicy": "Delete", 160 "storageClassName": "ssd", 161 "volumeMode": "Filesystem" 162 }, 163 "status": { 164 "phase": "Available" 165 } 166 } 167 } 168 ]` 169 ) 170 171 var ( 172 createOpts = &persistentvolumeclaims.CreateOpts{ 173 ApiVersion: "v1", 174 Kind: "PersistentVolumeClaim", 175 Metadata: persistentvolumeclaims.Metadata{ 176 Name: "cci-ssd-test-demo", 177 Namespace: "terraform-test", 178 Annotations: &persistentvolumeclaims.Annotations{ 179 FsType: "ext4", 180 VolumeID: "46d10433-35fb-459b-8482-2dd6fa192262", 181 }, 182 }, 183 Spec: persistentvolumeclaims.Spec{ 184 Resources: persistentvolumeclaims.ResourceRequirement{ 185 Requests: &persistentvolumeclaims.ResourceName{ 186 Storage: "10Gi", 187 }, 188 }, 189 StorageClassName: "ssd", 190 }, 191 } 192 193 expectedCreateResponseData = &persistentvolumeclaims.PersistentVolumeClaim{ 194 Kind: "PersistentVolumeClaim", 195 ApiVersion: "v1", 196 Metadata: persistentvolumeclaims.MetaResp{ 197 Name: "cci-ssd-test-demo", 198 Namespace: "terraform-test", 199 SelfLink: "/api/v1/namespaces/terraform-test/persistentvolumeclaims/cci-ssd-test-demo", 200 UID: "1ae26e9c-9e39-432d-9438-e6c669670629", 201 ResourceVersion: "285666212", 202 CreationTimestamp: "2021-05-25T03:45:45Z", 203 Annotations: map[string]string{ 204 "kubernetes.io/volumeId": "46d10433-35fb-459b-8482-2dd6fa192262", 205 }, 206 Labels: map[string]string{ 207 "failure-domain.beta.kubernetes.io/region": "cn-north-4", 208 "failure-domain.beta.kubernetes.io/zone": "cn-north-4a", 209 }, 210 Finalizers: []string{ 211 "kubernetes.io/pvc-protection", 212 }, 213 }, 214 Spec: persistentvolumeclaims.SpecResp{ 215 AccessModes: []string{ 216 "ReadWriteMany", 217 }, 218 Resources: persistentvolumeclaims.ResourceRequirement{ 219 Requests: &persistentvolumeclaims.ResourceName{ 220 Storage: "10Gi", 221 }, 222 }, 223 VolumeName: "cci-evs-import-46d10433-35fb-459b-8482-2dd6fa192262", 224 StorageClassName: "ssd", 225 VolumeMode: "Filesystem", 226 }, 227 Status: persistentvolumeclaims.Status{ 228 Phase: "Pending", 229 }, 230 } 231 232 listOpts = persistentvolumeclaims.ListOpts{ 233 StorageType: "bs", 234 } 235 236 expectedListResponseData = []persistentvolumeclaims.ListResp{ 237 { 238 PersistentVolumeClaim: persistentvolumeclaims.PersistentVolumeClaim{ 239 Metadata: persistentvolumeclaims.MetaResp{ 240 Name: "cci-ssd-test-demo", 241 Namespace: "terraform-test", 242 UID: "acf521b6-1e60-4ecd-af4a-671005e6d4bd", 243 ResourceVersion: "285728642", 244 SelfLink: "/api/v1/namespaces/terraform-test/persistentvolumeclaims/cci-ssd-test-demo", 245 CreationTimestamp: "2021-05-25T06:26:29Z", 246 Annotations: map[string]string{ 247 "kubernetes.io/volumeId": "45571ae3-125a-4cfa-bd76-a76eedcde45a", 248 }, 249 Labels: map[string]string{ 250 "failure-domain.beta.kubernetes.io/region": "cn-north-4", 251 "failure-domain.beta.kubernetes.io/zone": "cn-north-4a", 252 }, 253 Finalizers: []string{ 254 "kubernetes.io/pvc-protection", 255 }, 256 }, 257 Spec: persistentvolumeclaims.SpecResp{ 258 AccessModes: []string{ 259 "ReadWriteMany", 260 }, 261 Resources: persistentvolumeclaims.ResourceRequirement{ 262 Requests: &persistentvolumeclaims.ResourceName{ 263 Storage: "10Gi", 264 }, 265 }, 266 VolumeName: "cci-evs-import-45571ae3-125a-4cfa-bd76-a76eedcde45a", 267 StorageClassName: "ssd", 268 VolumeMode: "Filesystem", 269 }, 270 Status: persistentvolumeclaims.Status{ 271 Phase: "Pending", 272 }, 273 }, 274 PersistentVolume: persistentvolumeclaims.PersistentVolumeClaim{ 275 Metadata: persistentvolumeclaims.MetaResp{ 276 Name: "cci-evs-import-45571ae3-125a-4cfa-bd76-a76eedcde45a", 277 UID: "e8dc63e5-014d-4e39-970c-5cc151e92144", 278 SelfLink: "/api/v1/persistentvolumes/cci-evs-import-45571ae3-125a-4cfa-bd76-a76eedcde45a", 279 ResourceVersion: "285728644", 280 CreationTimestamp: "2021-05-25T06:26:29Z", 281 Annotations: map[string]string{ 282 "kubernetes.io/createdby": "cci-apiserver", 283 "pv.kubernetes.io/bound-by-cci": "yes", 284 "pv.kubernetes.io/namespace": "terraform-test", 285 "tenant.kubernetes.io/domain-id": "0970d7b7d400f2470fbec00316a03560", 286 "tenant.kubernetes.io/project-id": "0970dd7a1300f5672ff2c003c60ae115", 287 }, 288 Labels: map[string]string{ 289 "failure-domain.beta.kubernetes.io/region": "cn-north-4", 290 "failure-domain.beta.kubernetes.io/zone": "cn-north-4a", 291 "tenant.kubernetes.io/domain-id": "0970d7b7d400f2470fbec00316a03560", 292 "tenant.kubernetes.io/project-id": "0970dd7a1300f5672ff2c003c60ae115", 293 }, 294 Finalizers: []string{ 295 "kubernetes.io/pv-protection", 296 }, 297 }, 298 Spec: persistentvolumeclaims.SpecResp{ 299 Capacity: persistentvolumeclaims.ResourceName{ 300 Storage: "10Gi", 301 }, 302 FlexVolume: persistentvolumeclaims.FlexVolume{ 303 Driver: "huawei.com/fuxivol", 304 FsType: "ext4", 305 Options: persistentvolumeclaims.Options{ 306 FsType: "ext4", 307 VolumeID: "45571ae3-125a-4cfa-bd76-a76eedcde45a", 308 }, 309 }, 310 AccessModes: []string{ 311 "ReadWriteMany", 312 }, 313 ClaimRef: persistentvolumeclaims.ClaimRef{ 314 Namespace: "terraform-test", 315 Name: "cci-ssd-test-demo", 316 }, 317 PersistentVolumeReclaimPolicy: "Delete", 318 StorageClassName: "ssd", 319 VolumeMode: "Filesystem", 320 }, 321 Status: persistentvolumeclaims.Status{ 322 Phase: "Available", 323 }, 324 }, 325 }, 326 } 327 ) 328 329 func handlePersistentVolumeClaimCreate(t *testing.T) { 330 th.Mux.HandleFunc("/namespaces/terraform-test/extended-persistentvolumeclaims", 331 func(w http.ResponseWriter, r *http.Request) { 332 th.TestMethod(t, r, "POST") 333 th.TestHeader(t, r, "X-Auth-Token", client.TokenID) 334 w.Header().Add("Content-Type", "application/json") 335 w.WriteHeader(http.StatusCreated) 336 _, _ = fmt.Fprint(w, expectedCreateResponse) 337 }) 338 } 339 340 func handlePersistentVolumeClaimList(t *testing.T) { 341 th.Mux.HandleFunc("/namespaces/terraform-test/extended-persistentvolumeclaims", 342 func(w http.ResponseWriter, r *http.Request) { 343 th.TestMethod(t, r, "GET") 344 th.TestHeader(t, r, "X-Auth-Token", client.TokenID) 345 w.Header().Add("Content-Type", "application/json") 346 w.WriteHeader(http.StatusOK) 347 _, _ = fmt.Fprint(w, expectedListResponse) 348 }) 349 }