@@ -7,6 +7,7 @@ package wsmanager
7
7
import (
8
8
"context"
9
9
"encoding/json"
10
+ "fmt"
10
11
"testing"
11
12
"time"
12
13
@@ -21,43 +22,33 @@ import (
21
22
)
22
23
23
24
func TestRegularWorkspaceTasks (t * testing.T ) {
25
+ testRepo := "https://github.com/gitpod-io/empty"
26
+ testRepoName := "empty"
27
+ wsLoc := "/workspace/empty"
28
+
24
29
tests := []struct {
25
30
Name string
26
- Task gitpod.TasksItems
27
- LookForFile string
31
+ Task [] gitpod.TasksItems
32
+ LookForFile [] string
28
33
FF []wsmanapi.WorkspaceFeatureFlag
29
34
}{
30
35
{
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" },
50
43
},
51
44
{
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" },
61
52
FF : []wsmanapi.WorkspaceFeatureFlag {wsmanapi .WorkspaceFeatureFlag_PERSISTENT_VOLUME_CLAIM },
62
53
},
63
54
}
@@ -66,7 +57,7 @@ func TestRegularWorkspaceTasks(t *testing.T) {
66
57
WithLabel ("component" , "ws-manager" ).
67
58
WithLabel ("type" , "tasks" ).
68
59
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 )
70
61
defer cancel ()
71
62
72
63
api := integration .NewComponentAPI (ctx , cfg .Namespace (), kubeconfig , cfg .Client ())
@@ -77,7 +68,7 @@ func TestRegularWorkspaceTasks(t *testing.T) {
77
68
for _ , test := range tests {
78
69
t .Run (test .Name , func (t * testing.T ) {
79
70
addInitTask := func (swr * wsmanapi.StartWorkspaceRequest ) error {
80
- tasks , err := json .Marshal ([]gitpod. TasksItems { test .Task } )
71
+ tasks , err := json .Marshal (test .Task )
81
72
if err != nil {
82
73
return err
83
74
}
@@ -89,15 +80,15 @@ func TestRegularWorkspaceTasks(t *testing.T) {
89
80
swr .Spec .Initializer = & csapi.WorkspaceInitializer {
90
81
Spec : & csapi.WorkspaceInitializer_Git {
91
82
Git : & csapi.GitInitializer {
92
- RemoteUri : "https://github.com/gitpod-io/gitpod.git" ,
83
+ RemoteUri : testRepo ,
93
84
TargetMode : csapi .CloneTargetMode_REMOTE_BRANCH ,
94
85
CloneTaget : "main" ,
95
- CheckoutLocation : "gitpod" ,
86
+ CheckoutLocation : testRepoName ,
96
87
Config : & csapi.GitConfig {},
97
88
},
98
89
},
99
90
}
100
- swr .Spec .WorkspaceLocation = "gitpod"
91
+ swr .Spec .WorkspaceLocation = testRepoName
101
92
return nil
102
93
}
103
94
@@ -107,8 +98,7 @@ func TestRegularWorkspaceTasks(t *testing.T) {
107
98
}
108
99
109
100
defer func () {
110
- err = stopWs (true )
111
- if err != nil {
101
+ if err = stopWs (true ); err != nil {
112
102
t .Errorf ("cannot stop workspace: %q" , err )
113
103
}
114
104
}()
@@ -131,7 +121,7 @@ func TestRegularWorkspaceTasks(t *testing.T) {
131
121
for i := 1 ; i < 10 ; i ++ {
132
122
var res agent.ExecResponse
133
123
err = rsa .Call ("WorkspaceAgent.Exec" , & agent.ExecRequest {
134
- Dir : "/workspace/gitpod" ,
124
+ Dir : wsLoc ,
135
125
Command : "curl" ,
136
126
// nftable rule only forwards to this ip address
137
127
Args : []string {"10.0.5.2:22999/_supervisor/v1/status/tasks" },
@@ -144,7 +134,7 @@ func TestRegularWorkspaceTasks(t *testing.T) {
144
134
t .Fatalf ("cannot decode supervisor status response: %s" , err )
145
135
}
146
136
147
- if len (parsedResp .Result .Tasks ) != 1 {
137
+ if len (parsedResp .Result .Tasks ) != len ( test . Task ) {
148
138
t .Fatalf ("expected one task to run, but got %d" , len (parsedResp .Result .Tasks ))
149
139
}
150
140
if parsedResp .Result .Tasks [0 ].State == supervisorapi .TaskState_name [int32 (supervisorapi .TaskState_closed )] {
@@ -160,21 +150,23 @@ func TestRegularWorkspaceTasks(t *testing.T) {
160
150
161
151
var ls agent.ListDirResponse
162
152
err = rsa .Call ("WorkspaceAgent.ListDir" , & agent.ListDirRequest {
163
- Dir : "/workspace/gitpod" ,
153
+ Dir : wsLoc ,
164
154
}, & ls )
165
155
if err != nil {
166
156
t .Fatal (err )
167
157
}
168
158
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 )
174
169
}
175
- }
176
- if ! foundMaker {
177
- t .Fatal ("task seems to have run, but cannot find the file it should have created" )
178
170
}
179
171
})
180
172
}
0 commit comments