Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
gitpod-io
GitHub Repository: gitpod-io/gitpod
Path: blob/main/install/installer/pkg/components/ws-manager-bridge/objects_test.go
2501 views
1
// Copyright (c) 2022 Gitpod GmbH. All rights reserved.
2
/// Licensed under the GNU Affero General Public License (AGPL).
3
// See License.AGPL.txt in the project root for license information.
4
5
package wsmanagerbridge
6
7
import (
8
"testing"
9
10
"github.com/stretchr/testify/require"
11
12
"github.com/gitpod-io/gitpod/installer/pkg/common"
13
config "github.com/gitpod-io/gitpod/installer/pkg/config/v1"
14
"github.com/gitpod-io/gitpod/installer/pkg/config/v1/experimental"
15
"github.com/gitpod-io/gitpod/installer/pkg/config/versions"
16
)
17
18
func TestWorkspaceManagerList_WhenSkipSelfIsSet(t *testing.T) {
19
testCases := []struct {
20
Kind config.InstallationKind
21
SkipSelf bool
22
ExpectWorkspaceClusters bool
23
}{
24
{Kind: config.InstallationMeta, SkipSelf: true, ExpectWorkspaceClusters: false},
25
{Kind: config.InstallationMeta, SkipSelf: false, ExpectWorkspaceClusters: false}, // cannot mount anything it if there is nothing to mount
26
{Kind: config.InstallationFull, SkipSelf: true, ExpectWorkspaceClusters: false},
27
{Kind: config.InstallationFull, SkipSelf: false, ExpectWorkspaceClusters: true},
28
}
29
30
for _, testCase := range testCases {
31
ctx := renderContextWithConfig(t, testCase.Kind, testCase.SkipSelf)
32
33
wsclusters := WSManagerList(ctx)
34
if testCase.ExpectWorkspaceClusters {
35
require.NotEmptyf(t, wsclusters, "expected to render workspace clusters when skipSelf=%v", testCase.SkipSelf)
36
} else {
37
require.Emptyf(t, wsclusters, "expected not to render workspace clusters when skipSelf=%v", testCase.SkipSelf)
38
}
39
}
40
}
41
42
func renderContextWithConfig(t *testing.T, kind config.InstallationKind, skipSelf bool) *common.RenderContext {
43
ctx, err := common.NewRenderContext(config.Config{
44
Kind: kind,
45
Experimental: &experimental.Config{
46
WebApp: &experimental.WebAppConfig{
47
WorkspaceManagerBridge: &experimental.WsManagerBridgeConfig{
48
SkipSelf: skipSelf,
49
},
50
},
51
},
52
}, versions.Manifest{
53
Components: versions.Components{
54
PublicAPIServer: versions.Versioned{
55
Version: "commit-test-latest",
56
},
57
},
58
}, "test-namespace")
59
require.NoError(t, err)
60
61
return ctx
62
}
63
64