sigs.k8s.io/blobfuse-csi-driver@v0.6.0/test/sanity/sanity_test.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 sanity 18 19 import ( 20 "context" 21 "log" 22 "os" 23 "os/exec" 24 "strings" 25 "testing" 26 27 "sigs.k8s.io/blobfuse-csi-driver/test/utils/azure" 28 "sigs.k8s.io/blobfuse-csi-driver/test/utils/credentials" 29 30 "github.com/stretchr/testify/assert" 31 ) 32 33 func TestSanity(t *testing.T) { 34 creds, err := credentials.CreateAzureCredentialFile(false) 35 defer func() { 36 err := credentials.DeleteAzureCredentialFile() 37 assert.NoError(t, err) 38 }() 39 assert.NoError(t, err) 40 assert.NotNil(t, creds) 41 42 os.Setenv("AZURE_CREDENTIAL_FILE", credentials.TempAzureCredentialFilePath) 43 44 azureClient, err := azure.GetClient(creds.Cloud, creds.SubscriptionID, creds.AADClientID, creds.TenantID, creds.AADClientSecret) 45 assert.NoError(t, err) 46 47 ctx := context.Background() 48 // Create an empty resource group for sanity test 49 log.Printf("Creating resource group %s in %s", creds.ResourceGroup, creds.Cloud) 50 _, err = azureClient.EnsureResourceGroup(ctx, creds.ResourceGroup, creds.Location, nil) 51 assert.NoError(t, err) 52 defer func() { 53 // Only delete resource group the test created 54 if strings.HasPrefix(creds.ResourceGroup, credentials.ResourceGroupPrefix) { 55 log.Printf("Deleting resource group %s", creds.ResourceGroup) 56 err := azureClient.DeleteResourceGroup(ctx, creds.ResourceGroup) 57 assert.NoError(t, err) 58 } 59 }() 60 61 // Execute the script from project root 62 err = os.Chdir("../..") 63 assert.NoError(t, err) 64 // Change directory back to test/sanity 65 defer func() { 66 err := os.Chdir("test/sanity") 67 assert.NoError(t, err) 68 }() 69 70 projectRoot, err := os.Getwd() 71 assert.NoError(t, err) 72 assert.True(t, strings.HasSuffix(projectRoot, "blobfuse-csi-driver")) 73 74 cmd := exec.Command("./test/sanity/run-tests-all-clouds.sh") 75 cmd.Dir = projectRoot 76 cmd.Stdout = os.Stdout 77 cmd.Stderr = os.Stderr 78 if err := cmd.Run(); err != nil { 79 t.Fatalf("Sanity test failed %v", err) 80 } 81 }