Skip to content

Commit

Permalink
refactor(oauth): use named tests for WithTenant to improve test outpu…
Browse files Browse the repository at this point in the history
…t 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.
  • Loading branch information
handsomejack-42 committed Nov 4, 2024
1 parent bd2dbaf commit b2e545f
Showing 1 changed file with 17 additions and 12 deletions.
29 changes: 17 additions & 12 deletions apps/internal/oauth/ops/authority/authority_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import (
"strings"
"testing"

"github.com/google/uuid"

"github.com/kylelemons/godebug/pretty"
)

Expand Down Expand Up @@ -319,22 +321,25 @@ func TestCreateAuthorityInfoFromAuthorityUri(t *testing.T) {
}

func TestAuthParamsWithTenant(t *testing.T) {
uuid1 := "00000000-0000-0000-0000-000000000000"
uuid2 := strings.ReplaceAll(uuid1, "0", "1")
uuid1 := uuid.New().String()
uuid2 := uuid.New().String()
host := "https://localhost/"
for _, test := range []struct {

tests := map[string]struct {
authority, expectedAuthority, tenant string
expectError bool
}{
{authority: host + "common", tenant: uuid1, expectedAuthority: host + uuid1},
{authority: host + "organizations", tenant: uuid1, expectedAuthority: host + uuid1},
{authority: host + uuid1, tenant: uuid2, expectedAuthority: host + uuid2},
{authority: host + uuid1, tenant: "common", expectError: true},
{authority: host + uuid1, tenant: "organizations", expectError: true},
{authority: host + "adfs", tenant: uuid1, expectError: true},
{authority: host + "consumers", tenant: uuid1, expectError: true},
} {
t.Run("", func(t *testing.T) {
"override common to tenant": {authority: host + "common", tenant: uuid1, expectedAuthority: host + uuid1},
"override organizations to tenant": {authority: host + "organizations", tenant: uuid1, expectedAuthority: host + uuid1},
"override tenant to tenant2": {authority: host + uuid1, tenant: uuid2, expectedAuthority: host + uuid2},
"tenant can't be common for AAD": {authority: host + uuid1, tenant: "common", expectError: true},
"tenant can't be organizations for AAD": {authority: host + uuid1, tenant: "organizations", expectError: true},
"can't override tenant for ADFS ever": {authority: host + "adfs", tenant: uuid1, expectError: true},
"can't override AAD tenant consumers": {authority: host + "consumers", tenant: uuid1, expectError: true},
}

for name, test := range tests {
t.Run(name, func(t *testing.T) {
info, err := NewInfoFromAuthorityURI(test.authority, false, false)
if err != nil {
t.Fatal(err)
Expand Down

0 comments on commit b2e545f

Please sign in to comment.