sigs.k8s.io/blob-csi-driver@v1.24.1/test/e2e/testsuites/pre_provisioned_read_only_volume_tester.go (about) 1 /* 2 Copyright 2019 The Kubernetes Authors. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package testsuites 18 19 import ( 20 "context" 21 "fmt" 22 23 "sigs.k8s.io/blob-csi-driver/test/e2e/driver" 24 25 "github.com/onsi/ginkgo/v2" 26 "github.com/onsi/gomega" 27 v1 "k8s.io/api/core/v1" 28 clientset "k8s.io/client-go/kubernetes" 29 "k8s.io/kubernetes/test/e2e/framework" 30 ) 31 32 // PreProvisionedReadOnlyVolumeTest will provision required PV(s), PVC(s) and Pod(s) 33 // Testing that the Pod(s) cannot write to the volume when mounted 34 type PreProvisionedReadOnlyVolumeTest struct { 35 CSIDriver driver.PreProvisionedVolumeTestDriver 36 Pods []PodDetails 37 } 38 39 func (t *PreProvisionedReadOnlyVolumeTest) Run(ctx context.Context, client clientset.Interface, namespace *v1.Namespace) { 40 for _, pod := range t.Pods { 41 tpod, cleanup := pod.SetupWithPreProvisionedVolumes(ctx, client, namespace, t.CSIDriver) 42 // defer must be called here for resources not get removed before using them 43 for i := range cleanup { 44 defer cleanup[i](ctx) 45 } 46 47 ginkgo.By("deploying the pod") 48 tpod.Create(ctx) 49 defer tpod.Cleanup(ctx) 50 ginkgo.By("checking that the pods command exits with an error") 51 tpod.WaitForFailure(ctx) 52 ginkgo.By("checking that pod logs contain expected message") 53 body, err := tpod.Logs(ctx) 54 framework.ExpectNoError(err, fmt.Sprintf("Error getting logs for pod %s: %v", tpod.pod.Name, err)) 55 gomega.Expect(string(body)).To(gomega.ContainSubstring(expectedReadOnlyLog)) 56 } 57 }