Skip to content

Commit 91df39a

Browse files
committed
workspace integration test: enhance TestRegularWorkspaceTasks
Signed-off-by: JenTing Hsiao <[email protected]>
1 parent 197d9b8 commit 91df39a

File tree

1 file changed

+40
-48
lines changed

1 file changed

+40
-48
lines changed

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

+40-48
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ package wsmanager
77
import (
88
"context"
99
"encoding/json"
10+
"fmt"
1011
"testing"
1112
"time"
1213

@@ -21,43 +22,33 @@ import (
2122
)
2223

2324
func TestRegularWorkspaceTasks(t *testing.T) {
25+
testRepo := "https://github.com/gitpod-io/empty"
26+
testRepoName := "empty"
27+
wsLoc := "/workspace/empty"
28+
2429
tests := []struct {
2530
Name string
26-
Task gitpod.TasksItems
27-
LookForFile string
31+
Task []gitpod.TasksItems
32+
LookForFile []string
2833
FF []wsmanapi.WorkspaceFeatureFlag
2934
}{
3035
{
31-
Name: "classic-init",
32-
Task: gitpod.TasksItems{Init: "touch /workspace/gitpod/init-ran; exit"},
33-
LookForFile: "init-ran",
34-
},
35-
{
36-
Name: "classic-before",
37-
Task: gitpod.TasksItems{Before: "touch /workspace/gitpod/before-ran; exit"},
38-
LookForFile: "before-ran",
39-
},
40-
{
41-
Name: "classic-command",
42-
Task: gitpod.TasksItems{Command: "touch /workspace/gitpod/command-ran; exit"},
43-
LookForFile: "command-ran",
44-
},
45-
{
46-
Name: "pvc-init",
47-
Task: gitpod.TasksItems{Init: "touch /workspace/gitpod/init-ran; exit"},
48-
LookForFile: "init-ran",
49-
FF: []wsmanapi.WorkspaceFeatureFlag{wsmanapi.WorkspaceFeatureFlag_PERSISTENT_VOLUME_CLAIM},
36+
Name: "classic",
37+
Task: []gitpod.TasksItems{
38+
{Init: fmt.Sprintf("touch %s/init-ran; exit", wsLoc)},
39+
{Before: fmt.Sprintf("touch %s/before-ran; exit", wsLoc)},
40+
{Command: fmt.Sprintf("touch %s/command-ran; exit", wsLoc)},
41+
},
42+
LookForFile: []string{"init-ran", "before-ran", "command-ran"},
5043
},
5144
{
52-
Name: "pvc-before",
53-
Task: gitpod.TasksItems{Before: "touch /workspace/gitpod/before-ran; exit"},
54-
LookForFile: "before-ran",
55-
FF: []wsmanapi.WorkspaceFeatureFlag{wsmanapi.WorkspaceFeatureFlag_PERSISTENT_VOLUME_CLAIM},
56-
},
57-
{
58-
Name: "pvc-command",
59-
Task: gitpod.TasksItems{Command: "touch /workspace/gitpod/command-ran; exit"},
60-
LookForFile: "command-ran",
45+
Name: "pvc",
46+
Task: []gitpod.TasksItems{
47+
{Init: fmt.Sprintf("touch %s/init-ran; exit", wsLoc)},
48+
{Before: fmt.Sprintf("touch %s/before-ran; exit", wsLoc)},
49+
{Command: fmt.Sprintf("touch %s/command-ran; exit", wsLoc)},
50+
},
51+
LookForFile: []string{"init-ran", "before-ran", "command-ran"},
6152
FF: []wsmanapi.WorkspaceFeatureFlag{wsmanapi.WorkspaceFeatureFlag_PERSISTENT_VOLUME_CLAIM},
6253
},
6354
}
@@ -66,7 +57,7 @@ func TestRegularWorkspaceTasks(t *testing.T) {
6657
WithLabel("component", "ws-manager").
6758
WithLabel("type", "tasks").
6859
Assess("it can run workspace tasks", func(_ context.Context, t *testing.T, cfg *envconf.Config) context.Context {
69-
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Minute)
60+
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Minute)
7061
defer cancel()
7162

7263
api := integration.NewComponentAPI(ctx, cfg.Namespace(), kubeconfig, cfg.Client())
@@ -77,7 +68,7 @@ func TestRegularWorkspaceTasks(t *testing.T) {
7768
for _, test := range tests {
7869
t.Run(test.Name, func(t *testing.T) {
7970
addInitTask := func(swr *wsmanapi.StartWorkspaceRequest) error {
80-
tasks, err := json.Marshal([]gitpod.TasksItems{test.Task})
71+
tasks, err := json.Marshal(test.Task)
8172
if err != nil {
8273
return err
8374
}
@@ -89,15 +80,15 @@ func TestRegularWorkspaceTasks(t *testing.T) {
8980
swr.Spec.Initializer = &csapi.WorkspaceInitializer{
9081
Spec: &csapi.WorkspaceInitializer_Git{
9182
Git: &csapi.GitInitializer{
92-
RemoteUri: "https://github.com/gitpod-io/gitpod.git",
83+
RemoteUri: testRepo,
9384
TargetMode: csapi.CloneTargetMode_REMOTE_BRANCH,
9485
CloneTaget: "main",
95-
CheckoutLocation: "gitpod",
86+
CheckoutLocation: testRepoName,
9687
Config: &csapi.GitConfig{},
9788
},
9889
},
9990
}
100-
swr.Spec.WorkspaceLocation = "gitpod"
91+
swr.Spec.WorkspaceLocation = testRepoName
10192
return nil
10293
}
10394

@@ -107,8 +98,7 @@ func TestRegularWorkspaceTasks(t *testing.T) {
10798
}
10899

109100
defer func() {
110-
err = stopWs(true)
111-
if err != nil {
101+
if err = stopWs(true); err != nil {
112102
t.Errorf("cannot stop workspace: %q", err)
113103
}
114104
}()
@@ -131,7 +121,7 @@ func TestRegularWorkspaceTasks(t *testing.T) {
131121
for i := 1; i < 10; i++ {
132122
var res agent.ExecResponse
133123
err = rsa.Call("WorkspaceAgent.Exec", &agent.ExecRequest{
134-
Dir: "/workspace/gitpod",
124+
Dir: wsLoc,
135125
Command: "curl",
136126
// nftable rule only forwards to this ip address
137127
Args: []string{"10.0.5.2:22999/_supervisor/v1/status/tasks"},
@@ -144,7 +134,7 @@ func TestRegularWorkspaceTasks(t *testing.T) {
144134
t.Fatalf("cannot decode supervisor status response: %s", err)
145135
}
146136

147-
if len(parsedResp.Result.Tasks) != 1 {
137+
if len(parsedResp.Result.Tasks) != len(test.Task) {
148138
t.Fatalf("expected one task to run, but got %d", len(parsedResp.Result.Tasks))
149139
}
150140
if parsedResp.Result.Tasks[0].State == supervisorapi.TaskState_name[int32(supervisorapi.TaskState_closed)] {
@@ -160,21 +150,23 @@ func TestRegularWorkspaceTasks(t *testing.T) {
160150

161151
var ls agent.ListDirResponse
162152
err = rsa.Call("WorkspaceAgent.ListDir", &agent.ListDirRequest{
163-
Dir: "/workspace/gitpod",
153+
Dir: wsLoc,
164154
}, &ls)
165155
if err != nil {
166156
t.Fatal(err)
167157
}
168158

169-
var foundMaker bool
170-
for _, f := range ls.Files {
171-
if f == test.LookForFile {
172-
foundMaker = true
173-
break
159+
for _, lff := range test.LookForFile {
160+
var foundMaker bool
161+
for _, f := range ls.Files {
162+
if f == lff {
163+
foundMaker = true
164+
break
165+
}
166+
}
167+
if !foundMaker {
168+
t.Fatalf("task seems to have run, but cannot find %s it should have created", lff)
174169
}
175-
}
176-
if !foundMaker {
177-
t.Fatal("task seems to have run, but cannot find the file it should have created")
178170
}
179171
})
180172
}

0 commit comments

Comments
 (0)