From d2eca2b09e37daf678fd7a19d78237dc968feebb Mon Sep 17 00:00:00 2001 From: JenTing Hsiao Date: Tue, 27 Sep 2022 07:22:35 +0000 Subject: [PATCH] test: update TestOpenWorkspaceFromPrebuild Check the PVC object should exist or not. Signed-off-by: JenTing Hsiao --- test/pkg/integration/apis.go | 5 ++ .../components/ws-manager/prebuild_test.go | 47 +++++++++++++++---- 2 files changed, 44 insertions(+), 8 deletions(-) diff --git a/test/pkg/integration/apis.go b/test/pkg/integration/apis.go index 0df436614cba9b..896ffba8293337 100644 --- a/test/pkg/integration/apis.go +++ b/test/pkg/integration/apis.go @@ -1148,3 +1148,8 @@ func (c *ComponentAPI) portFwdWithRetry(ctx context.Context, portFwdF portFwdFun } } } + +func (c *ComponentAPI) IsPVCExist(pvcName string) bool { + var pvc corev1.PersistentVolumeClaim + return c.client.Resources().Get(context.Background(), pvcName, c.namespace, &pvc) == nil +} diff --git a/test/tests/components/ws-manager/prebuild_test.go b/test/tests/components/ws-manager/prebuild_test.go index 99d976f9ff2649..ba86a019db059e 100644 --- a/test/tests/components/ws-manager/prebuild_test.go +++ b/test/tests/components/ws-manager/prebuild_test.go @@ -182,20 +182,23 @@ const ( prebuildLogPath string = "/workspace/.gitpod" prebuildLog string = "'🤙 This task ran as a workspace prebuild'" initTask string = "echo \"some output\" > someFile; sleep 90;" + regularPrefix string = "ws-" ) // TestOpenWorkspaceFromPrebuild // - create a prebuild -// - open the workspace from prebuild -// - make sure the .git/ folder with correct permission +// - open the regular workspace from prebuild +// - make sure the regular workspace PVC object should exist or not // - make sure either one of the condition mets // - the prebuild log message exists // - the init task message exists // - the init task generated file exists // +// - make sure the .git/ folder with correct permission // - write a new file foobar.txt -// - stop the workspace -// - relaunch the workspace +// - stop the regular workspace +// - relaunch the regular workspace +// - make sure the regular workspace PVC object should exist or not // - make sure the file foobar.txt exists func TestOpenWorkspaceFromPrebuild(t *testing.T) { f := features.New("prebuild"). @@ -263,7 +266,11 @@ func TestOpenWorkspaceFromPrebuild(t *testing.T) { if err != nil { t.Fatalf("stop workspace and find snapshot error: %v", err) } - t.Logf("prebuild snapshot: %s, vsName: %s, vsHandle: %s", prebuildSnapshot, vsInfo.VolumeSnapshotName, vsInfo.VolumeSnapshotHandle) + + t.Logf("prebuild snapshot: %s", prebuildSnapshot) + if vsInfo != nil { + t.Logf("vsName: %s, vsHandle: %s", vsInfo.VolumeSnapshotName, vsInfo.VolumeSnapshotHandle) + } // launch the workspace from prebuild // 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) { t.Fatalf("cannot launch a workspace: %q", err) } + // check the PVC object should exist or not + checkPVCObject(t, api, test.FF, regularPrefix+ws.Req.Id) + defer func() { // stop workspace in defer function to prevent we forget to stop the workspace if err := stopWorkspace(t, cfg, stopWs); err != nil { @@ -313,7 +323,7 @@ func TestOpenWorkspaceFromPrebuild(t *testing.T) { }) integration.DeferCloser(t, closer) - // checkPrebuildLogExist checks the prebuild log message exists + // check prebuild log message exists checkPrebuildLogExist(t, cfg, rsa, ws, test.WorkspaceRoot) // check the files/folders permission under .git/ is not root @@ -341,7 +351,10 @@ func TestOpenWorkspaceFromPrebuild(t *testing.T) { if err != nil { t.Fatal(err) } - t.Logf("vsName: %s, vsHandle: %s", vsInfo.VolumeSnapshotName, vsInfo.VolumeSnapshotHandle) + + if vsInfo != nil { + t.Logf("vsName: %s, vsHandle: %s", vsInfo.VolumeSnapshotName, vsInfo.VolumeSnapshotHandle) + } // reopen the workspace and make sure the file foobar.txt exists ws1, stopWs1, err := integration.LaunchWorkspaceDirectly(t, ctx, api, integration.WithRequestModifier(func(req *wsmanapi.StartWorkspaceRequest) error { @@ -365,6 +378,9 @@ func TestOpenWorkspaceFromPrebuild(t *testing.T) { t.Fatalf("cannot launch a workspace: %q", err) } + // check the PVC object should exist or not + checkPVCObject(t, api, test.FF, regularPrefix+ws1.Req.Id) + defer func() { // stop workspace in defer function to prevent we forget to stop the workspace if err := stopWorkspace(t, cfg, stopWs1); err != nil { @@ -555,7 +571,7 @@ func TestPrebuildAndRegularWorkspaceDifferentWorkspaceClass(t *testing.T) { }) integration.DeferCloser(t, closer) - // checkPrebuildLogExist checks the prebuild log message exists + // check prebuild log message exists checkPrebuildLogExist(t, cfg, rsa, ws, test.WorkspaceRoot) // check the files/folders permission under .git/ is not root @@ -569,6 +585,21 @@ func TestPrebuildAndRegularWorkspaceDifferentWorkspaceClass(t *testing.T) { testEnv.Test(t, f) } +// checkPVCObject checks the PVC object should exist or not +func checkPVCObject(t *testing.T, api *integration.ComponentAPI, ff []wsmanapi.WorkspaceFeatureFlag, pvcName string) { + if reflect.DeepEqual(ff, []wsmanapi.WorkspaceFeatureFlag{wsmanapi.WorkspaceFeatureFlag_PERSISTENT_VOLUME_CLAIM}) { + // check the PVC object exist + if !api.IsPVCExist(pvcName) { + t.Fatal("prebuild PVC object should exist") + } + return + } + // check the PVC object not exist + if api.IsPVCExist(pvcName) { + t.Fatal("prebuild PVC object should not exist") + } +} + // checkPrebuildLogExist checks the prebuild log message exists func checkPrebuildLogExist(t *testing.T, cfg *envconf.Config, rsa *rpc.Client, ws *integration.LaunchWorkspaceDirectlyResult, wsRoot string) { // since the message '🤙 This task ran as a workspace prebuild' is generated by