|
| 1 | +// Package provider contains the cloud provider specific implementations to manage machines |
| 2 | +package provider |
| 3 | + |
| 4 | +import ( |
| 5 | + "context" |
| 6 | + "testing" |
| 7 | + |
| 8 | + "github.com/gardener/machine-controller-manager/pkg/util/provider/driver" |
| 9 | + "github.com/google/go-cmp/cmp" |
| 10 | + corev1 "k8s.io/api/core/v1" |
| 11 | +) |
| 12 | + |
| 13 | +func TestProvider_GetVolumeIDs(t *testing.T) { |
| 14 | + tests := []struct { |
| 15 | + name string |
| 16 | + req *driver.GetVolumeIDsRequest |
| 17 | + want *driver.GetVolumeIDsResponse |
| 18 | + wantErr error |
| 19 | + }{ |
| 20 | + { |
| 21 | + name: "valid lightbits volume", |
| 22 | + req: &driver.GetVolumeIDsRequest{ |
| 23 | + PVSpecs: []*corev1.PersistentVolumeSpec{ |
| 24 | + { |
| 25 | + |
| 26 | + PersistentVolumeSource: corev1.PersistentVolumeSource{ |
| 27 | + CSI: &corev1.CSIPersistentVolumeSource{ |
| 28 | + Driver: "csi.lightbitslabs.com", |
| 29 | + VolumeHandle: "mgmt:10.131.44.1:443,10.131.44.2:443,10.131.44.3:443|nguid:d22572da-a225-4578-ab1a-9318ac5155c3|proj:cd4eac58-46a5-4a31-b59f-2ec207baa817|scheme:grpcs", |
| 30 | + }, |
| 31 | + }, |
| 32 | + }, |
| 33 | + }, |
| 34 | + }, |
| 35 | + want: &driver.GetVolumeIDsResponse{ |
| 36 | + VolumeIDs: []string{"d22572da-a225-4578-ab1a-9318ac5155c3"}, |
| 37 | + }, |
| 38 | + }, |
| 39 | + { |
| 40 | + name: "invalid lightbits volume", |
| 41 | + req: &driver.GetVolumeIDsRequest{ |
| 42 | + PVSpecs: []*corev1.PersistentVolumeSpec{ |
| 43 | + { |
| 44 | + |
| 45 | + PersistentVolumeSource: corev1.PersistentVolumeSource{ |
| 46 | + CSI: &corev1.CSIPersistentVolumeSource{ |
| 47 | + Driver: "csi.lightbitslabs.com", |
| 48 | + VolumeHandle: "mgmt:10.131.44.1:443,10.131.44.2:443,10.131.44.3:443|proj:cd4eac58-46a5-4a31-b59f-2ec207baa817|scheme:grpcs", |
| 49 | + }, |
| 50 | + }, |
| 51 | + }, |
| 52 | + }, |
| 53 | + }, |
| 54 | + want: &driver.GetVolumeIDsResponse{ |
| 55 | + VolumeIDs: []string{"mgmt:10.131.44.1:443,10.131.44.2:443,10.131.44.3:443|proj:cd4eac58-46a5-4a31-b59f-2ec207baa817|scheme:grpcs"}, |
| 56 | + }, |
| 57 | + }, |
| 58 | + } |
| 59 | + for _, tt := range tests { |
| 60 | + t.Run(tt.name, func(t *testing.T) { |
| 61 | + p := &Provider{} |
| 62 | + |
| 63 | + got, err := p.GetVolumeIDs(context.Background(), tt.req) |
| 64 | + |
| 65 | + if diff := cmp.Diff(tt.wantErr, err); diff != "" { |
| 66 | + t.Errorf("err diff = %s", diff) |
| 67 | + } |
| 68 | + if diff := cmp.Diff(tt.want, got); diff != "" { |
| 69 | + t.Errorf("diff = %s", diff) |
| 70 | + } |
| 71 | + }) |
| 72 | + } |
| 73 | +} |
0 commit comments