Skip to content

Commit a074706

Browse files
committed
add e2e test for endpoint
1 parent 7592dc1 commit a074706

File tree

3 files changed

+42
-5
lines changed

3 files changed

+42
-5
lines changed

test/e2e/tests/setup_e2e_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ var _ = BeforeSuite(func() {
116116

117117
klog.Infof("Creating new driver and client for node %s\n", i.GetName())
118118
// Create new driver and client
119-
testContext, err := testutils.GCEClientAndDriverSetup(i)
119+
testContext, err := testutils.GCEClientAndDriverSetup(i, "")
120120
if err != nil {
121121
klog.Fatalf("Failed to set up Test Context for instance %v: %v", i.GetName(), err)
122122
}

test/e2e/tests/single_zone_e2e_test.go

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1124,8 +1124,41 @@ var _ = Describe("GCE PD CSI Driver", func() {
11241124
Expect(gce.IsGCEError(err, "notFound")).To(BeTrue(), "Expected disk to not be found")
11251125
}()
11261126
})
1127-
})
11281127

1128+
It("Should pass/fail if valid/invalid compute endpoint is passed in", func() {
1129+
// gets instance set up w/o compute-endpoint set from test setup
1130+
_, err := getRandomTestContext().Client.ListVolumes()
1131+
Expect(err).To(BeNil(), "no error expected when passed valid compute url")
1132+
1133+
zone := "us-central1-c"
1134+
nodeID := fmt.Sprintf("gce-pd-csi-e2e-%s", zone)
1135+
i, err := remote.SetupInstance(*project, *architecture, zone, nodeID, *machineType, *serviceAccount, *imageURL, computeService)
1136+
1137+
if err != nil {
1138+
klog.Fatalf("Failed to setup instance %v: %v", nodeID, err)
1139+
}
1140+
1141+
klog.Infof("Creating new driver and client for node %s\n", i.GetName())
1142+
1143+
// Create new driver and client w/ invalid endpoint
1144+
tcInvalid, err := testutils.GCEClientAndDriverSetup(i, "invalid-string")
1145+
if err != nil {
1146+
klog.Fatalf("Failed to set up Test Context for instance %v: %v", i.GetName(), err)
1147+
}
1148+
1149+
_, err = tcInvalid.Client.ListVolumes()
1150+
Expect(err).ToNot(BeNil(), "expected error when passed invalid compute url")
1151+
1152+
// Create new driver and client w/ valid, passed-in endpoint
1153+
tcValid, err := testutils.GCEClientAndDriverSetup(i, "https://compute.googleapis.com/compute/v1/")
1154+
if err != nil {
1155+
klog.Fatalf("Failed to set up Test Context for instance %v: %v", i.GetName(), err)
1156+
}
1157+
_, err = tcValid.Client.ListVolumes()
1158+
1159+
Expect(err).To(BeNil(), "no error expected when passed valid compute url")
1160+
})
1161+
})
11291162
func equalWithinEpsilon(a, b, epsiolon int64) bool {
11301163
if a > b {
11311164
return a-b < epsiolon

test/e2e/utils/utils.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ var (
4343
boskos, _ = boskosclient.NewClient(os.Getenv("JOB_NAME"), "http://boskos", "", "")
4444
)
4545

46-
func GCEClientAndDriverSetup(instance *remote.InstanceInfo) (*remote.TestContext, error) {
46+
func GCEClientAndDriverSetup(instance *remote.InstanceInfo, computeEndpoint string) (*remote.TestContext, error) {
4747
port := fmt.Sprintf("%v", 1024+rand.Intn(10000))
4848
goPath, ok := os.LookupEnv("GOPATH")
4949
if !ok {
@@ -53,10 +53,14 @@ func GCEClientAndDriverSetup(instance *remote.InstanceInfo) (*remote.TestContext
5353
binPath := path.Join(pkgPath, "bin/gce-pd-csi-driver")
5454

5555
endpoint := fmt.Sprintf("tcp://localhost:%s", port)
56+
computeFlag := ""
57+
if computeEndpoint != "" {
58+
computeFlag = fmt.Sprintf("--compute-endpoint %s", computeEndpoint)
59+
}
5660

5761
workspace := remote.NewWorkspaceDir("gce-pd-e2e-")
58-
driverRunCmd := fmt.Sprintf("sh -c '/usr/bin/nohup %s/gce-pd-csi-driver -v=4 --endpoint=%s --extra-labels=%s=%s 2> %s/prog.out < /dev/null > /dev/null &'",
59-
workspace, endpoint, DiskLabelKey, DiskLabelValue, workspace)
62+
driverRunCmd := fmt.Sprintf("sh -c '/usr/bin/nohup %s/gce-pd-csi-driver -v=4 --endpoint=%s %s --extra-labels=%s=%s 2> %s/prog.out < /dev/null > /dev/null &'",
63+
workspace, endpoint, computeFlag, DiskLabelKey, DiskLabelValue, workspace)
6064

6165
config := &remote.ClientConfig{
6266
PkgPath: pkgPath,

0 commit comments

Comments
 (0)