Skip to content

Commit eb50eca

Browse files
committed
Add unit-test to GetProjectDomain in BaseClient
1 parent c424ec5 commit eb50eca

File tree

2 files changed

+47
-1
lines changed

2 files changed

+47
-1
lines changed

src/pkg/cli/client/byoc/baseclient.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ func (b *ByocBaseClient) GetProjectDomain(projectName, zone string) string {
126126
}
127127
domain := projectLabel + "." + DnsSafe(zone)
128128
if hasStack, ok := b.projectBackend.(HasStackSupport); ok {
129-
domain = hasStack.GetStackName() + "." + domain
129+
domain = hasStack.GetStackName() + "." + domain // TODO: Should we dns-safe the stack name too?
130130
}
131131
return domain
132132
}

src/pkg/cli/client/byoc/baseclient_test.go

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,3 +171,49 @@ func TestGetServiceInfosWithTestData(t *testing.T) {
171171
})
172172
}
173173
}
174+
175+
type TestProjectBackendWithStack struct {
176+
ProjectBackend
177+
stack string
178+
}
179+
180+
func (t TestProjectBackendWithStack) GetStackName() string {
181+
return t.stack
182+
}
183+
184+
type TestProjectBackendWithoutStack struct {
185+
ProjectBackend
186+
}
187+
188+
func TestGetProjectDomain(t *testing.T) {
189+
tests := []struct {
190+
projectName string
191+
zone string
192+
tenantName string
193+
projectBackend ProjectBackend
194+
expected string
195+
}{
196+
{"", "test-zone", "test-tenant", TestProjectBackendWithoutStack{}, ""},
197+
{"", "test-zone", "test-tenant", TestProjectBackendWithStack{stack: "test-stack"}, ""},
198+
{"test-project", "test-zone", "test-tenant", TestProjectBackendWithoutStack{}, "test-project.test-zone"},
199+
{"test-project", "test-zone", "test-tenant", TestProjectBackendWithStack{stack: "test-stack"}, "test-stack.test-project.test-zone"},
200+
{"project-is-tenant-name", "test-zone", "project-is-tenant-name", TestProjectBackendWithoutStack{}, "test-zone"},
201+
{"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?
202+
{"Test.Project", "tesT.zonE", "test-tenant", TestProjectBackendWithoutStack{}, "test-project.test.zone"},
203+
{"Test.Project", "tesT.zonE", "test-tenant", TestProjectBackendWithStack{stack: "test-stack"}, "test-stack.test-project.test.zone"},
204+
}
205+
206+
for _, tt := range tests {
207+
stack := "no-stack"
208+
if hasStack, ok := tt.projectBackend.(HasStackSupport); ok {
209+
stack = hasStack.GetStackName()
210+
}
211+
t.Run(fmt.Sprintf("%s-%s-%s-%s", tt.projectName, tt.zone, tt.tenantName, stack), func(t *testing.T) {
212+
b := &ByocBaseClient{TenantName: tt.tenantName, projectBackend: tt.projectBackend}
213+
actual := b.GetProjectDomain(tt.projectName, tt.zone)
214+
if actual != tt.expected {
215+
t.Errorf("expected %q, got %q", tt.expected, actual)
216+
}
217+
})
218+
}
219+
}

0 commit comments

Comments
 (0)