Skip to content

Commit

Permalink
Add tests for WsManagerList function
Browse files Browse the repository at this point in the history
Ensure that no workspace clusters are returned when either skipSelf is
set or the installation is not a full one.
  • Loading branch information
Andrew Farries committed May 4, 2022
1 parent 6b0281a commit 8016623
Showing 1 changed file with 58 additions and 0 deletions.
58 changes: 58 additions & 0 deletions install/installer/pkg/components/ws-manager-bridge/objects_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// Copyright (c) 2022 Gitpod GmbH. All rights reserved.
// Licensed under the MIT License. See License-MIT.txt in the project root for license information.

package wsmanagerbridge

import (
"github.com/gitpod-io/gitpod/installer/pkg/common"
"github.com/gitpod-io/gitpod/installer/pkg/config/v1"
"github.com/gitpod-io/gitpod/installer/pkg/config/v1/experimental"
"github.com/gitpod-io/gitpod/installer/pkg/config/versions"
"github.com/stretchr/testify/require"
"testing"
)

func TestWorkspaceManagerList_WhenSkipSelfIsSet(t *testing.T) {
testCases := []struct {
SkipSelf bool
InstallationKind config.InstallationKind
ExpectWorkspaceClusters bool
}{
{SkipSelf: true, InstallationKind: config.InstallationFull, ExpectWorkspaceClusters: false},
{SkipSelf: true, InstallationKind: config.InstallationMeta, ExpectWorkspaceClusters: false},
{SkipSelf: false, InstallationKind: config.InstallationFull, ExpectWorkspaceClusters: true},
{SkipSelf: false, InstallationKind: config.InstallationMeta, ExpectWorkspaceClusters: false},
}

for _, testCase := range testCases {
ctx := renderContextWithConfig(t, testCase.SkipSelf, testCase.InstallationKind)

wsclusters := WSManagerList(ctx)
if testCase.ExpectWorkspaceClusters {
require.NotEmpty(t, wsclusters, "expected to render workspace clusters when skipSelf=%v, kind=%s",
testCase.SkipSelf, testCase.InstallationKind)
}
}
}

func renderContextWithConfig(t *testing.T, skipSelf bool, installationKind config.InstallationKind) *common.RenderContext {
ctx, err := common.NewRenderContext(config.Config{
Kind: installationKind,
Experimental: &experimental.Config{
WebApp: &experimental.WebAppConfig{
WorkspaceManagerBridge: &experimental.WsManagerBridgeConfig{
SkipSelf: skipSelf,
},
},
},
}, versions.Manifest{
Components: versions.Components{
PublicAPIServer: versions.Versioned{
Version: "commit-test-latest",
},
},
}, "test-namespace")
require.NoError(t, err)

return ctx
}

0 comments on commit 8016623

Please sign in to comment.