Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: update test TestOpenWorkspaceFromPrebuild #13371

Merged
merged 1 commit into from
Sep 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions test/pkg/integration/apis.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
47 changes: 39 additions & 8 deletions test/tests/components/ws-manager/prebuild_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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").
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand All @@ -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
Expand Down Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down