|
| 1 | +/* |
| 2 | +Copyright 2023 The Kubernetes Authors. |
| 3 | +
|
| 4 | +
|
| 5 | +Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | +you may not use this file except in compliance with the License. |
| 7 | +You may obtain a copy of the License at |
| 8 | +
|
| 9 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +
|
| 11 | +Unless required by applicable law or agreed to in writing, software |
| 12 | +distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | +See the License for the specific language governing permissions and |
| 15 | +limitations under the License. |
| 16 | +*/ |
| 17 | + |
| 18 | +package gcecloudprovider |
| 19 | + |
| 20 | +import ( |
| 21 | + "testing" |
| 22 | + |
| 23 | + computebeta "google.golang.org/api/compute/v0.beta" |
| 24 | + computev1 "google.golang.org/api/compute/v1" |
| 25 | +) |
| 26 | + |
| 27 | +func CreateDiskWithConfidentialCompute(betaDisk bool, confidentialCompute bool, diskType string) *CloudDisk { |
| 28 | + if betaDisk { |
| 29 | + return &CloudDisk{ |
| 30 | + betaDisk: &computebeta.Disk{ |
| 31 | + EnableConfidentialCompute: confidentialCompute, |
| 32 | + Type: diskType, |
| 33 | + }, |
| 34 | + } |
| 35 | + } |
| 36 | + return &CloudDisk{ |
| 37 | + disk: &computev1.Disk{}, |
| 38 | + } |
| 39 | +} |
| 40 | + |
| 41 | +func TestGetEnableConfidentialCompute(t *testing.T) { |
| 42 | + testCases := []struct { |
| 43 | + name string |
| 44 | + diskVersion *CloudDisk |
| 45 | + expectedEnableConfidentialCompute bool |
| 46 | + }{ |
| 47 | + { |
| 48 | + name: "test betaDisk with enableConfidentialCompute=false", |
| 49 | + diskVersion: CreateDiskWithConfidentialCompute(true, false, "hyperdisk-balanced"), |
| 50 | + expectedEnableConfidentialCompute: false, |
| 51 | + }, |
| 52 | + { |
| 53 | + name: "test betaDisk with enableConfidentialCompute=true", |
| 54 | + diskVersion: CreateDiskWithConfidentialCompute(true, true, "hyperdisk-balanced"), |
| 55 | + expectedEnableConfidentialCompute: true, |
| 56 | + }, |
| 57 | + { |
| 58 | + name: "test disk withpit enableConfidentialCompute", |
| 59 | + diskVersion: CreateDiskWithConfidentialCompute(false, false, "hyperdisk-balanced"), |
| 60 | + expectedEnableConfidentialCompute: false, |
| 61 | + }, |
| 62 | + { |
| 63 | + name: "test disk withpit enableConfidentialCompute", |
| 64 | + diskVersion: CreateDiskWithConfidentialCompute(false, false, "pd-standard"), |
| 65 | + expectedEnableConfidentialCompute: false, |
| 66 | + }, |
| 67 | + } |
| 68 | + |
| 69 | + for _, tc := range testCases { |
| 70 | + t.Logf("Running test: %v", tc.name) |
| 71 | + confidentialCompute := tc.diskVersion.GetEnableConfidentialCompute() |
| 72 | + if confidentialCompute != tc.expectedEnableConfidentialCompute { |
| 73 | + t.Fatalf("Got confidentialCompute value %t expected %t", confidentialCompute, tc.expectedEnableConfidentialCompute) |
| 74 | + } |
| 75 | + if confidentialCompute != tc.expectedEnableConfidentialCompute { |
| 76 | + t.Fatalf("Got confidentialCompute value %t expected %t", confidentialCompute, tc.expectedEnableConfidentialCompute) |
| 77 | + } |
| 78 | + } |
| 79 | +} |
0 commit comments