Skip to content

Commit 64abad4

Browse files
author
Andrew Farries
committed
Add tests for WsManagerList function
Ensure that no workspace clusters are returned when either skipSelf is set or the installation is not a full one.
1 parent 8bdad13 commit 64abad4

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
// Copyright (c) 2022 Gitpod GmbH. All rights reserved.
2+
// Licensed under the MIT License. See License-MIT.txt in the project root for license information.
3+
4+
package wsmanagerbridge
5+
6+
import (
7+
"github.com/gitpod-io/gitpod/installer/pkg/common"
8+
"github.com/gitpod-io/gitpod/installer/pkg/config/v1"
9+
"github.com/gitpod-io/gitpod/installer/pkg/config/v1/experimental"
10+
"github.com/gitpod-io/gitpod/installer/pkg/config/versions"
11+
"github.com/stretchr/testify/require"
12+
"testing"
13+
)
14+
15+
func TestWorkspaceManagerList_WhenSkipSelfIsSet(t *testing.T) {
16+
testCases := []struct {
17+
SkipSelf bool
18+
ExpectWorkspaceClusters bool
19+
}{
20+
{SkipSelf: true, ExpectWorkspaceClusters: false},
21+
{SkipSelf: false, ExpectWorkspaceClusters: true},
22+
}
23+
24+
for _, testCase := range testCases {
25+
ctx := renderContextWithConfig(t, testCase.SkipSelf)
26+
27+
wsclusters := WSManagerList(ctx)
28+
if testCase.ExpectWorkspaceClusters {
29+
require.NotEmptyf(t, wsclusters, "expected to render workspace clusters when skipSelf=%v", testCase.SkipSelf)
30+
} else {
31+
require.Emptyf(t, wsclusters, "expected not to render workspace clusters when skipSelf=%v", testCase.SkipSelf)
32+
}
33+
}
34+
}
35+
36+
func renderContextWithConfig(t *testing.T, skipSelf bool) *common.RenderContext {
37+
ctx, err := common.NewRenderContext(config.Config{
38+
Experimental: &experimental.Config{
39+
WebApp: &experimental.WebAppConfig{
40+
WorkspaceManagerBridge: &experimental.WsManagerBridgeConfig{
41+
SkipSelf: skipSelf,
42+
},
43+
},
44+
},
45+
}, versions.Manifest{
46+
Components: versions.Components{
47+
PublicAPIServer: versions.Versioned{
48+
Version: "commit-test-latest",
49+
},
50+
},
51+
}, "test-namespace")
52+
require.NoError(t, err)
53+
54+
return ctx
55+
}

0 commit comments

Comments
 (0)