|
5 | 5 | package wsmanager
|
6 | 6 |
|
7 | 7 | import (
|
| 8 | + "encoding/json" |
8 | 9 | "testing"
|
9 | 10 |
|
10 | 11 | "github.com/gitpod-io/gitpod/installer/pkg/common"
|
| 12 | + "github.com/gitpod-io/gitpod/installer/pkg/config/v1" |
11 | 13 | configv1 "github.com/gitpod-io/gitpod/installer/pkg/config/v1"
|
| 14 | + "github.com/gitpod-io/gitpod/installer/pkg/config/versions" |
12 | 15 | wsmancfg "github.com/gitpod-io/gitpod/ws-manager/api/config"
|
13 | 16 | "github.com/google/go-cmp/cmp"
|
| 17 | + "github.com/stretchr/testify/require" |
14 | 18 |
|
15 | 19 | corev1 "k8s.io/api/core/v1"
|
16 | 20 | "k8s.io/apimachinery/pkg/runtime"
|
@@ -133,3 +137,58 @@ func TestBuildWorkspaceTemplates(t *testing.T) {
|
133 | 137 | })
|
134 | 138 | }
|
135 | 139 | }
|
| 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