Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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 @@ -125,7 +125,7 @@ func (b *ByocBaseClient) GetProjectDomain(projectName, zone string) string {
}
domain := dns.Normalize(zone)
if hasStack, ok := b.projectBackend.(HasStackSupport); ok {
domain = hasStack.GetStackName() + "." + domain
domain = DnsSafeLabel(hasStack.GetStackName()) + "." + domain
}
return domain
}
Expand Down
47 changes: 47 additions & 0 deletions src/pkg/cli/client/byoc/baseclient_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,3 +172,50 @@ 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-stack.test-zone"},
{"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"},
{"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