|
| 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