Skip to content

Commit d2eca2b

Browse files
jentingroboquat
authored andcommitted
test: update TestOpenWorkspaceFromPrebuild
Check the PVC object should exist or not. Signed-off-by: JenTing Hsiao <hsiaoairplane@gmail.com>
1 parent 02faf85 commit d2eca2b

File tree

2 files changed

+44
-8
lines changed

2 files changed

+44
-8
lines changed

test/pkg/integration/apis.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1148,3 +1148,8 @@ func (c *ComponentAPI) portFwdWithRetry(ctx context.Context, portFwdF portFwdFun
11481148
}
11491149
}
11501150
}
1151+
1152+
func (c *ComponentAPI) IsPVCExist(pvcName string) bool {
1153+
var pvc corev1.PersistentVolumeClaim
1154+
return c.client.Resources().Get(context.Background(), pvcName, c.namespace, &pvc) == nil
1155+
}

test/tests/components/ws-manager/prebuild_test.go

Lines changed: 39 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -182,20 +182,23 @@ const (
182182
prebuildLogPath string = "/workspace/.gitpod"
183183
prebuildLog string = "'🤙 This task ran as a workspace prebuild'"
184184
initTask string = "echo \"some output\" > someFile; sleep 90;"
185+
regularPrefix string = "ws-"
185186
)
186187

187188
// TestOpenWorkspaceFromPrebuild
188189
// - create a prebuild
189-
// - open the workspace from prebuild
190-
// - make sure the .git/ folder with correct permission
190+
// - open the regular workspace from prebuild
191+
// - make sure the regular workspace PVC object should exist or not
191192
// - make sure either one of the condition mets
192193
// - the prebuild log message exists
193194
// - the init task message exists
194195
// - the init task generated file exists
195196
//
197+
// - make sure the .git/ folder with correct permission
196198
// - write a new file foobar.txt
197-
// - stop the workspace
198-
// - relaunch the workspace
199+
// - stop the regular workspace
200+
// - relaunch the regular workspace
201+
// - make sure the regular workspace PVC object should exist or not
199202
// - make sure the file foobar.txt exists
200203
func TestOpenWorkspaceFromPrebuild(t *testing.T) {
201204
f := features.New("prebuild").
@@ -263,7 +266,11 @@ func TestOpenWorkspaceFromPrebuild(t *testing.T) {
263266
if err != nil {
264267
t.Fatalf("stop workspace and find snapshot error: %v", err)
265268
}
266-
t.Logf("prebuild snapshot: %s, vsName: %s, vsHandle: %s", prebuildSnapshot, vsInfo.VolumeSnapshotName, vsInfo.VolumeSnapshotHandle)
269+
270+
t.Logf("prebuild snapshot: %s", prebuildSnapshot)
271+
if vsInfo != nil {
272+
t.Logf("vsName: %s, vsHandle: %s", vsInfo.VolumeSnapshotName, vsInfo.VolumeSnapshotHandle)
273+
}
267274

268275
// launch the workspace from prebuild
269276
// TODO: change to use server API to launch the workspace, so we could run the integration test as the user code flow
@@ -295,6 +302,9 @@ func TestOpenWorkspaceFromPrebuild(t *testing.T) {
295302
t.Fatalf("cannot launch a workspace: %q", err)
296303
}
297304

305+
// check the PVC object should exist or not
306+
checkPVCObject(t, api, test.FF, regularPrefix+ws.Req.Id)
307+
298308
defer func() {
299309
// stop workspace in defer function to prevent we forget to stop the workspace
300310
if err := stopWorkspace(t, cfg, stopWs); err != nil {
@@ -313,7 +323,7 @@ func TestOpenWorkspaceFromPrebuild(t *testing.T) {
313323
})
314324
integration.DeferCloser(t, closer)
315325

316-
// checkPrebuildLogExist checks the prebuild log message exists
326+
// check prebuild log message exists
317327
checkPrebuildLogExist(t, cfg, rsa, ws, test.WorkspaceRoot)
318328

319329
// check the files/folders permission under .git/ is not root
@@ -341,7 +351,10 @@ func TestOpenWorkspaceFromPrebuild(t *testing.T) {
341351
if err != nil {
342352
t.Fatal(err)
343353
}
344-
t.Logf("vsName: %s, vsHandle: %s", vsInfo.VolumeSnapshotName, vsInfo.VolumeSnapshotHandle)
354+
355+
if vsInfo != nil {
356+
t.Logf("vsName: %s, vsHandle: %s", vsInfo.VolumeSnapshotName, vsInfo.VolumeSnapshotHandle)
357+
}
345358

346359
// reopen the workspace and make sure the file foobar.txt exists
347360
ws1, stopWs1, err := integration.LaunchWorkspaceDirectly(t, ctx, api, integration.WithRequestModifier(func(req *wsmanapi.StartWorkspaceRequest) error {
@@ -365,6 +378,9 @@ func TestOpenWorkspaceFromPrebuild(t *testing.T) {
365378
t.Fatalf("cannot launch a workspace: %q", err)
366379
}
367380

381+
// check the PVC object should exist or not
382+
checkPVCObject(t, api, test.FF, regularPrefix+ws1.Req.Id)
383+
368384
defer func() {
369385
// stop workspace in defer function to prevent we forget to stop the workspace
370386
if err := stopWorkspace(t, cfg, stopWs1); err != nil {
@@ -555,7 +571,7 @@ func TestPrebuildAndRegularWorkspaceDifferentWorkspaceClass(t *testing.T) {
555571
})
556572
integration.DeferCloser(t, closer)
557573

558-
// checkPrebuildLogExist checks the prebuild log message exists
574+
// check prebuild log message exists
559575
checkPrebuildLogExist(t, cfg, rsa, ws, test.WorkspaceRoot)
560576

561577
// check the files/folders permission under .git/ is not root
@@ -569,6 +585,21 @@ func TestPrebuildAndRegularWorkspaceDifferentWorkspaceClass(t *testing.T) {
569585
testEnv.Test(t, f)
570586
}
571587

588+
// checkPVCObject checks the PVC object should exist or not
589+
func checkPVCObject(t *testing.T, api *integration.ComponentAPI, ff []wsmanapi.WorkspaceFeatureFlag, pvcName string) {
590+
if reflect.DeepEqual(ff, []wsmanapi.WorkspaceFeatureFlag{wsmanapi.WorkspaceFeatureFlag_PERSISTENT_VOLUME_CLAIM}) {
591+
// check the PVC object exist
592+
if !api.IsPVCExist(pvcName) {
593+
t.Fatal("prebuild PVC object should exist")
594+
}
595+
return
596+
}
597+
// check the PVC object not exist
598+
if api.IsPVCExist(pvcName) {
599+
t.Fatal("prebuild PVC object should not exist")
600+
}
601+
}
602+
572603
// checkPrebuildLogExist checks the prebuild log message exists
573604
func checkPrebuildLogExist(t *testing.T, cfg *envconf.Config, rsa *rpc.Client, ws *integration.LaunchWorkspaceDirectlyResult, wsRoot string) {
574605
// since the message '🤙 This task ran as a workspace prebuild' is generated by

0 commit comments

Comments
 (0)