Skip to content

Commit d2abd94

Browse files
handsomejack-42bgavrilMS
authored andcommitted
refactor(oauth): use named tests for WithTenant to improve test output readability
Previously, the test results were printed as #0 #1 #2, which made it hard to navigate the failed test cases. Now, the test cases are annotated by their respective names. The names also make it more clear what is being unit-tested.
1 parent 24e1a6e commit d2abd94

File tree

1 file changed

+17
-12
lines changed

1 file changed

+17
-12
lines changed

apps/internal/oauth/ops/authority/authority_test.go

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ import (
1414
"strings"
1515
"testing"
1616

17+
"github.com/google/uuid"
18+
1719
"github.com/kylelemons/godebug/pretty"
1820
)
1921

@@ -319,22 +321,25 @@ func TestCreateAuthorityInfoFromAuthorityUri(t *testing.T) {
319321
}
320322

321323
func TestAuthParamsWithTenant(t *testing.T) {
322-
uuid1 := "00000000-0000-0000-0000-000000000000"
323-
uuid2 := strings.ReplaceAll(uuid1, "0", "1")
324+
uuid1 := uuid.New().String()
325+
uuid2 := uuid.New().String()
324326
host := "https://localhost/"
325-
for _, test := range []struct {
327+
328+
tests := map[string]struct {
326329
authority, expectedAuthority, tenant string
327330
expectError bool
328331
}{
329-
{authority: host + "common", tenant: uuid1, expectedAuthority: host + uuid1},
330-
{authority: host + "organizations", tenant: uuid1, expectedAuthority: host + uuid1},
331-
{authority: host + uuid1, tenant: uuid2, expectedAuthority: host + uuid2},
332-
{authority: host + uuid1, tenant: "common", expectError: true},
333-
{authority: host + uuid1, tenant: "organizations", expectError: true},
334-
{authority: host + "adfs", tenant: uuid1, expectError: true},
335-
{authority: host + "consumers", tenant: uuid1, expectError: true},
336-
} {
337-
t.Run("", func(t *testing.T) {
332+
"override common to tenant": {authority: host + "common", tenant: uuid1, expectedAuthority: host + uuid1},
333+
"override organizations to tenant": {authority: host + "organizations", tenant: uuid1, expectedAuthority: host + uuid1},
334+
"override tenant to tenant2": {authority: host + uuid1, tenant: uuid2, expectedAuthority: host + uuid2},
335+
"tenant can't be common for AAD": {authority: host + uuid1, tenant: "common", expectError: true},
336+
"tenant can't be organizations for AAD": {authority: host + uuid1, tenant: "organizations", expectError: true},
337+
"can't override tenant for ADFS ever": {authority: host + "adfs", tenant: uuid1, expectError: true},
338+
"can't override AAD tenant consumers": {authority: host + "consumers", tenant: uuid1, expectError: true},
339+
}
340+
341+
for name, test := range tests {
342+
t.Run(name, func(t *testing.T) {
338343
info, err := NewInfoFromAuthorityURI(test.authority, false, false)
339344
if err != nil {
340345
t.Fatal(err)

0 commit comments

Comments
 (0)