@@ -171,3 +171,49 @@ func TestGetServiceInfosWithTestData(t *testing.T) {
171
171
})
172
172
}
173
173
}
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