@@ -182,20 +182,23 @@ const (
182182prebuildLogPath string = "/workspace/.gitpod"
183183prebuildLog string = "'🤙 This task ran as a workspace prebuild'"
184184initTask 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
200203func TestOpenWorkspaceFromPrebuild (t * testing.T ) {
201204f := features .New ("prebuild" ).
@@ -263,7 +266,11 @@ func TestOpenWorkspaceFromPrebuild(t *testing.T) {
263266if err != nil {
264267t .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) {
295302t .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+
298308defer func () {
299309// stop workspace in defer function to prevent we forget to stop the workspace
300310if err := stopWorkspace (t , cfg , stopWs ); err != nil {
@@ -313,7 +323,7 @@ func TestOpenWorkspaceFromPrebuild(t *testing.T) {
313323})
314324integration .DeferCloser (t , closer )
315325
316- // checkPrebuildLogExist checks the prebuild log message exists
326+ // check prebuild log message exists
317327checkPrebuildLogExist (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) {
341351if err != nil {
342352t .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
347360ws1 , stopWs1 , err := integration .LaunchWorkspaceDirectly (t , ctx , api , integration .WithRequestModifier (func (req * wsmanapi.StartWorkspaceRequest ) error {
@@ -365,6 +378,9 @@ func TestOpenWorkspaceFromPrebuild(t *testing.T) {
365378t .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+
368384defer func () {
369385// stop workspace in defer function to prevent we forget to stop the workspace
370386if err := stopWorkspace (t , cfg , stopWs1 ); err != nil {
@@ -555,7 +571,7 @@ func TestPrebuildAndRegularWorkspaceDifferentWorkspaceClass(t *testing.T) {
555571})
556572integration .DeferCloser (t , closer )
557573
558- // checkPrebuildLogExist checks the prebuild log message exists
574+ // check prebuild log message exists
559575checkPrebuildLogExist (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) {
569585testEnv .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
573604func 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