Skip to content

Commit 350c55e

Browse files
committed
Setup sanity and integration test CI
1 parent c9904bf commit 350c55e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+10844
-3814
lines changed

Gopkg.lock

Lines changed: 12 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Makefile

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,15 @@ verify:
3232

3333
.PHONY: unit-test
3434
unit-test:
35-
go test -covermode=count -coverprofile=profile.cov ./pkg/...
35+
go test -covermode=count -coverprofile=profile.cov ./pkg/... ./test/utils/credentials
3636

3737
.PHONY: sanity-test
38-
sanity-test:
39-
test/sanity/run-tests-all-clouds.sh
38+
sanity-test: blobfuse
39+
go test -v -timeout=30m ./test/sanity
4040

4141
.PHONY: integration-test
42-
integration-test:
43-
test/integration/run-tests-all-clouds.sh
42+
integration-test: blobfuse
43+
go test -v -timeout=30m ./test/integration
4444

4545
.PHONY: e2e-test
4646
e2e-test:
File renamed without changes.

test/integration/azure.json

Lines changed: 0 additions & 33 deletions
This file was deleted.

test/integration/integration_test.go

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
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 integration
18+
19+
import (
20+
"context"
21+
"log"
22+
"os"
23+
"os/exec"
24+
"strings"
25+
"testing"
26+
27+
"github.com/kubernetes-sigs/blobfuse-csi-driver/test/utils/azure"
28+
"github.com/kubernetes-sigs/blobfuse-csi-driver/test/utils/credentials"
29+
"github.com/kubernetes-sigs/blobfuse-csi-driver/test/utils/testutil"
30+
31+
"github.com/stretchr/testify/assert"
32+
)
33+
34+
func TestIntegrationOnAzurePublicCloud(t *testing.T) {
35+
// Test on AzurePublicCloud
36+
creds, err := credentials.CreateAzureCredentialFile(false)
37+
defer func() {
38+
err := credentials.DeleteAzureCredentialFile()
39+
assert.NoError(t, err)
40+
}()
41+
assert.NoError(t, err)
42+
assert.NotNil(t, creds)
43+
44+
testIntegration(t, creds)
45+
}
46+
47+
func TestIntegrationOnAzureChinaCloud(t *testing.T) {
48+
if testutil.IsRunningInProw() {
49+
t.Skipf("Skipping integration test on Azure China Cloud because Prow only tests on Azure Public Cloud at the moment")
50+
}
51+
52+
// Test on AzureChinaCloud
53+
creds, err := credentials.CreateAzureCredentialFile(true)
54+
defer func() {
55+
err := credentials.DeleteAzureCredentialFile()
56+
assert.NoError(t, err)
57+
}()
58+
59+
if err != nil {
60+
// Skip the test if Azure China Cloud credentials are not supplied
61+
t.Skipf("Skipping integration test on Azure China Cloud due to the following error %v", err)
62+
}
63+
assert.NotNil(t, creds)
64+
testIntegration(t, creds)
65+
}
66+
67+
func testIntegration(t *testing.T, creds *credentials.Credentials) {
68+
os.Setenv("AZURE_CREDENTIAL_FILE", credentials.TempAzureCredentialFilePath)
69+
70+
azureClient, err := azure.GetClient(creds.Cloud, creds.SubscriptionID, creds.AADClientID, creds.TenantID, creds.AADClientSecret)
71+
assert.NoError(t, err)
72+
73+
ctx := context.Background()
74+
// Create an empty resource group for integration test
75+
log.Printf("Creating resource group %s in %s", creds.ResourceGroup, creds.Cloud)
76+
_, err = azureClient.EnsureResourceGroup(ctx, creds.ResourceGroup, creds.Location, nil)
77+
assert.NoError(t, err)
78+
defer func() {
79+
// Only delete resource group the test created
80+
if strings.HasPrefix(creds.ResourceGroup, credentials.ResourceGroupPrefix) {
81+
log.Printf("Deleting resource group %s", creds.ResourceGroup)
82+
err := azureClient.DeleteResourceGroup(ctx, creds.ResourceGroup)
83+
assert.NoError(t, err)
84+
}
85+
}()
86+
87+
// Execute the script from project root
88+
err = os.Chdir("../..")
89+
assert.NoError(t, err)
90+
// Change directory back to test/integration in preparation for next test
91+
defer func() {
92+
err := os.Chdir("test/integration")
93+
assert.NoError(t, err)
94+
}()
95+
96+
cwd, err := os.Getwd()
97+
assert.NoError(t, err)
98+
assert.True(t, strings.HasSuffix(cwd, "blobfuse-csi-driver"))
99+
100+
// Pass in resource group name, storage account name and cloud type
101+
cmd := exec.Command("./test/integration/run-tests-all-clouds.sh", creds.ResourceGroup, creds.Cloud)
102+
cmd.Dir = cwd
103+
cmd.Stdout = os.Stdout
104+
cmd.Stderr = os.Stderr
105+
if err := cmd.Run(); err != nil {
106+
t.Fatalf("Integration test failed %v", err)
107+
}
108+
}

0 commit comments

Comments
 (0)