Skip to content

Commit 73502c0

Browse files
Andrew Farriesroboquat
Andrew Farries
authored andcommitted
Add test for workspace URL templates
1 parent 82f6f1f commit 73502c0

File tree

1 file changed

+59
-0
lines changed

1 file changed

+59
-0
lines changed

install/installer/pkg/components/ws-manager/configmap_test.go

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,16 @@
55
package wsmanager
66

77
import (
8+
"encoding/json"
89
"testing"
910

1011
"github.com/gitpod-io/gitpod/installer/pkg/common"
12+
"github.com/gitpod-io/gitpod/installer/pkg/config/v1"
1113
configv1 "github.com/gitpod-io/gitpod/installer/pkg/config/v1"
14+
"github.com/gitpod-io/gitpod/installer/pkg/config/versions"
1215
wsmancfg "github.com/gitpod-io/gitpod/ws-manager/api/config"
1316
"github.com/google/go-cmp/cmp"
17+
"github.com/stretchr/testify/require"
1418

1519
corev1 "k8s.io/api/core/v1"
1620
"k8s.io/apimachinery/pkg/runtime"
@@ -133,3 +137,58 @@ func TestBuildWorkspaceTemplates(t *testing.T) {
133137
})
134138
}
135139
}
140+
141+
func TestWorkspaceURLTemplates(t *testing.T) {
142+
tests := []struct {
143+
Name string
144+
Domain string
145+
InstallationShortname string
146+
ExpectedWorkspaceUrlTemplate string
147+
ExpectedWorkspacePortURLTemplate string
148+
}{
149+
{
150+
Name: "With an installation shortname",
151+
Domain: "example.com",
152+
InstallationShortname: "eu02",
153+
ExpectedWorkspaceUrlTemplate: "https://{{ .Prefix }}.ws-eu02.example.com",
154+
ExpectedWorkspacePortURLTemplate: "https://{{ .WorkspacePort }}-{{ .Prefix }}.ws-eu02.example.com",
155+
},
156+
{
157+
Name: "Without an installation shortname",
158+
Domain: "example.com",
159+
InstallationShortname: "",
160+
ExpectedWorkspaceUrlTemplate: "https://{{ .Prefix }}.ws.example.com",
161+
ExpectedWorkspacePortURLTemplate: "https://{{ .WorkspacePort }}-{{ .Prefix }}.ws.example.com",
162+
},
163+
}
164+
165+
for _, test := range tests {
166+
t.Run(test.Name, func(t *testing.T) {
167+
ctx, err := common.NewRenderContext(config.Config{
168+
Domain: test.Domain,
169+
Metadata: configv1.Metadata{
170+
InstallationShortname: test.InstallationShortname,
171+
},
172+
ObjectStorage: configv1.ObjectStorage{
173+
InCluster: pointer.Bool(true),
174+
},
175+
}, versions.Manifest{}, "test_namespace")
176+
require.NoError(t, err)
177+
178+
objs, err := configmap(ctx)
179+
require.NoError(t, err)
180+
181+
cfgmap, ok := objs[0].(*corev1.ConfigMap)
182+
require.Truef(t, ok, "configmap function did not return a configmap")
183+
184+
configJson, ok := cfgmap.Data["config.json"]
185+
require.Truef(t, ok, "configmap data did not contain %q key", "config.json")
186+
187+
serviceConfig := wsmancfg.ServiceConfiguration{}
188+
json.Unmarshal([]byte(configJson), &serviceConfig)
189+
190+
require.Equal(t, test.ExpectedWorkspaceUrlTemplate, serviceConfig.Manager.WorkspaceURLTemplate)
191+
require.Equal(t, test.ExpectedWorkspacePortURLTemplate, serviceConfig.Manager.WorkspacePortURLTemplate)
192+
})
193+
}
194+
}

0 commit comments

Comments
 (0)