Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/pkg/cli/client/byoc/baseclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ func (b *ByocBaseClient) GetProjectDomain(projectName, zone string) string {
}
domain := projectLabel + "." + DnsSafe(zone)
if hasStack, ok := b.projectBackend.(HasStackSupport); ok {
domain = hasStack.GetStackName() + "." + domain
domain = hasStack.GetStackName() + "." + domain // TODO: Should we dns-safe the stack name too?
}
return domain
}
Expand Down
46 changes: 46 additions & 0 deletions src/pkg/cli/client/byoc/baseclient_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,3 +171,49 @@ func TestGetServiceInfosWithTestData(t *testing.T) {
})
}
}

type TestProjectBackendWithStack struct {
ProjectBackend
stack string
}

func (t TestProjectBackendWithStack) GetStackName() string {
return t.stack
}

type TestProjectBackendWithoutStack struct {
ProjectBackend
}

func TestGetProjectDomain(t *testing.T) {
tests := []struct {
projectName string
zone string
tenantName string
projectBackend ProjectBackend
expected string
}{
{"", "test-zone", "test-tenant", TestProjectBackendWithoutStack{}, ""},
{"", "test-zone", "test-tenant", TestProjectBackendWithStack{stack: "test-stack"}, ""},
Comment on lines +197 to +198
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess this is unlikely (or impossible) based on validation further up the stack, but should we generate a project prefix in this case (or panic)?

{"test-project", "test-zone", "test-tenant", TestProjectBackendWithoutStack{}, "test-project.test-zone"},
{"test-project", "test-zone", "test-tenant", TestProjectBackendWithStack{stack: "test-stack"}, "test-stack.test-project.test-zone"},
{"project-is-tenant-name", "test-zone", "project-is-tenant-name", TestProjectBackendWithoutStack{}, "test-zone"},
{"project-is-tenant-name", "test-zone", "project-is-tenant-name", TestProjectBackendWithStack{stack: "test-stack"}, "test-zone"}, // Stack is ignored when project name is the same as tenant -- Is that correct?
{"Test.Project", "tesT.zonE", "test-tenant", TestProjectBackendWithoutStack{}, "test-project.test.zone"},
{"Test.Project", "tesT.zonE", "test-tenant", TestProjectBackendWithStack{stack: "test-stack"}, "test-stack.test-project.test.zone"},
}

for _, tt := range tests {
stack := "no-stack"
if hasStack, ok := tt.projectBackend.(HasStackSupport); ok {
stack = hasStack.GetStackName()
}
t.Run(fmt.Sprintf("%s-%s-%s-%s", tt.projectName, tt.zone, tt.tenantName, stack), func(t *testing.T) {
b := &ByocBaseClient{TenantName: tt.tenantName, projectBackend: tt.projectBackend}
actual := b.GetProjectDomain(tt.projectName, tt.zone)
if actual != tt.expected {
t.Errorf("expected %q, got %q", tt.expected, actual)
}
})
}
}
Loading