-
Notifications
You must be signed in to change notification settings - Fork 1.3k
[installer, ws-manager]: Use installation shortname in URL templates #10152
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
fb1e69d
a14d383
b5f422a
390b79d
8823016
3bd7592
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,12 +5,16 @@ | |
package wsmanager | ||
|
||
import ( | ||
"encoding/json" | ||
"testing" | ||
|
||
"github.com/gitpod-io/gitpod/installer/pkg/common" | ||
"github.com/gitpod-io/gitpod/installer/pkg/config/v1" | ||
configv1 "github.com/gitpod-io/gitpod/installer/pkg/config/v1" | ||
"github.com/gitpod-io/gitpod/installer/pkg/config/versions" | ||
wsmancfg "github.com/gitpod-io/gitpod/ws-manager/api/config" | ||
"github.com/google/go-cmp/cmp" | ||
"github.com/stretchr/testify/require" | ||
|
||
corev1 "k8s.io/api/core/v1" | ||
"k8s.io/apimachinery/pkg/runtime" | ||
|
@@ -133,3 +137,65 @@ func TestBuildWorkspaceTemplates(t *testing.T) { | |
}) | ||
} | ||
} | ||
|
||
func TestWorkspaceURLTemplates(t *testing.T) { | ||
tests := []struct { | ||
Name string | ||
Domain string | ||
InstallationShortname string | ||
ExpectedWorkspaceUrlTemplate string | ||
ExpectedWorkspacePortURLTemplate string | ||
}{ | ||
{ | ||
Name: "With an installation shortname", | ||
Domain: "example.com", | ||
InstallationShortname: "eu02", | ||
ExpectedWorkspaceUrlTemplate: "https://{{ .Prefix }}.ws-eu02.example.com", | ||
ExpectedWorkspacePortURLTemplate: "https://{{ .WorkspacePort }}-{{ .Prefix }}.ws-eu02.example.com", | ||
}, | ||
{ | ||
Name: "Without an installation shortname", | ||
Domain: "example.com", | ||
InstallationShortname: "", | ||
ExpectedWorkspaceUrlTemplate: "https://{{ .Prefix }}.ws.example.com", | ||
ExpectedWorkspacePortURLTemplate: "https://{{ .WorkspacePort }}-{{ .Prefix }}.ws.example.com", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @andrew-farries We need a test case "with 'default' as installation shortname" to cover all existing self-hosted installations out there I think. That will lead us to the comment above I think. |
||
}, | ||
{ | ||
Name: "With old default installation shortname for existing self-hosted installations", | ||
Domain: "example.com", | ||
InstallationShortname: configv1.InstallationShortNameOldDefault, | ||
ExpectedWorkspaceUrlTemplate: "https://{{ .Prefix }}.ws.example.com", | ||
ExpectedWorkspacePortURLTemplate: "https://{{ .WorkspacePort }}-{{ .Prefix }}.ws.example.com", | ||
}, | ||
} | ||
|
||
for _, test := range tests { | ||
t.Run(test.Name, func(t *testing.T) { | ||
ctx, err := common.NewRenderContext(config.Config{ | ||
Domain: test.Domain, | ||
Metadata: configv1.Metadata{ | ||
InstallationShortname: test.InstallationShortname, | ||
}, | ||
ObjectStorage: configv1.ObjectStorage{ | ||
InCluster: pointer.Bool(true), | ||
}, | ||
}, versions.Manifest{}, "test_namespace") | ||
require.NoError(t, err) | ||
|
||
objs, err := configmap(ctx) | ||
require.NoError(t, err) | ||
|
||
cfgmap, ok := objs[0].(*corev1.ConfigMap) | ||
require.Truef(t, ok, "configmap function did not return a configmap") | ||
|
||
configJson, ok := cfgmap.Data["config.json"] | ||
require.Truef(t, ok, "configmap data did not contain %q key", "config.json") | ||
|
||
serviceConfig := wsmancfg.ServiceConfiguration{} | ||
json.Unmarshal([]byte(configJson), &serviceConfig) | ||
|
||
require.Equal(t, test.ExpectedWorkspaceUrlTemplate, serviceConfig.Manager.WorkspaceURLTemplate) | ||
require.Equal(t, test.ExpectedWorkspacePortURLTemplate, serviceConfig.Manager.WorkspacePortURLTemplate) | ||
}) | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍