Skip to content

Commit 34ab82f

Browse files
committed
Add test
1 parent dd2b68f commit 34ab82f

File tree

1 file changed

+99
-2
lines changed

1 file changed

+99
-2
lines changed

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

Lines changed: 99 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ func TestMaintenance(t *testing.T) {
7070
api.Done(t)
7171
})
7272

73-
addInitTask := func(swr *wsmanapi.StartWorkspaceRequest) error {
73+
customizeWorkspace := func(swr *wsmanapi.StartWorkspaceRequest) error {
7474
swr.Spec.Initializer = &csapi.WorkspaceInitializer{
7575
Spec: &csapi.WorkspaceInitializer_Git{
7676
Git: &csapi.GitInitializer{
@@ -84,7 +84,7 @@ func TestMaintenance(t *testing.T) {
8484
return nil
8585
}
8686

87-
_, _, err = integration.LaunchWorkspaceDirectly(t, ctx, api, integration.WithRequestModifier(addInitTask))
87+
_, _, err = integration.LaunchWorkspaceDirectly(t, ctx, api, integration.WithRequestModifier(customizeWorkspace))
8888
if err == nil {
8989
t.Fatalf("expected under maintenance error")
9090
} else {
@@ -100,6 +100,103 @@ func TestMaintenance(t *testing.T) {
100100
testEnv.Test(t, f)
101101
}
102102

103+
func TestMaintenanceUpdate(t *testing.T) {
104+
testRepo := "https://github.com/gitpod-io/empty"
105+
testRepoName := "empty"
106+
107+
f := features.New("ws-manager").
108+
WithLabel("component", "ws-manager").
109+
WithLabel("type", "maintenance").
110+
Assess("should display a maintenance message when configured and not when disabled", func(testCtx context.Context, t *testing.T, cfg *envconf.Config) context.Context {
111+
kubeClient, err := cfg.NewClient()
112+
if err != nil {
113+
t.Fatal(err)
114+
}
115+
116+
untilTime := time.Now().Add(1 * time.Hour)
117+
cmap, err := maintenanceConfigmap(&untilTime)
118+
if err != nil {
119+
t.Fatal(err)
120+
}
121+
122+
err = kubeClient.Resources().Create(testCtx, cmap)
123+
if err != nil && !apierrors.IsAlreadyExists(err) {
124+
t.Fatal(err)
125+
}
126+
127+
disableMaintenanceMode := func() {
128+
cmap, err := maintenanceConfigmap(nil)
129+
if err != nil {
130+
t.Error(err)
131+
return
132+
}
133+
134+
err = kubeClient.Resources().Update(testCtx, cmap)
135+
if err != nil {
136+
t.Error(err)
137+
}
138+
}
139+
140+
disableMaintenanceMode()
141+
142+
ctx, cancel := context.WithTimeout(testCtx, time.Duration(5*time.Minute))
143+
defer cancel()
144+
145+
api := integration.NewComponentAPI(ctx, cfg.Namespace(), kubeconfig, cfg.Client())
146+
t.Cleanup(func() {
147+
api.Done(t)
148+
})
149+
150+
_, _, err = integration.LaunchWorkspaceDirectly(t, ctx, api, integration.WithRequestModifier(func(swr *wsmanapi.StartWorkspaceRequest) error {
151+
swr.Spec.Initializer = &csapi.WorkspaceInitializer{
152+
Spec: &csapi.WorkspaceInitializer_Git{
153+
Git: &csapi.GitInitializer{
154+
RemoteUri: testRepo,
155+
CheckoutLocation: testRepoName,
156+
Config: &csapi.GitConfig{},
157+
},
158+
},
159+
}
160+
swr.Spec.WorkspaceLocation = testRepoName
161+
return nil
162+
}))
163+
if err == nil {
164+
t.Fatalf("expected under maintenance error")
165+
} else {
166+
if !errors.Is(err, status.Error(codes.FailedPrecondition, "under maintenance")) {
167+
t.Fatal(err)
168+
}
169+
}
170+
171+
disableMaintenanceMode()
172+
173+
_, stopWs, err := integration.LaunchWorkspaceDirectly(t, ctx, api, integration.WithRequestModifier(func(swr *wsmanapi.StartWorkspaceRequest) error {
174+
swr.Spec.Initializer = &csapi.WorkspaceInitializer{
175+
Spec: &csapi.WorkspaceInitializer_Git{
176+
Git: &csapi.GitInitializer{
177+
RemoteUri: testRepo,
178+
CheckoutLocation: testRepoName,
179+
Config: &csapi.GitConfig{},
180+
},
181+
},
182+
}
183+
swr.Spec.WorkspaceLocation = testRepoName
184+
return nil
185+
}))
186+
if err != nil {
187+
t.Fatal(err)
188+
}
189+
190+
if err := stopWorkspace(t, cfg, stopWs); err != nil {
191+
t.Errorf("cannot stop workspace: %q", err)
192+
}
193+
194+
return testCtx
195+
}).
196+
Feature()
197+
198+
testEnv.Test(t, f)
199+
}
103200
func maintenanceConfigmap(untilTime *time.Time) (*corev1.ConfigMap, error) {
104201
mcfg := config.MaintenanceConfig{}
105202
if untilTime != nil {

0 commit comments

Comments
 (0)