Skip to content

Commit

Permalink
feat: added test for IsFreePass
Browse files Browse the repository at this point in the history
  • Loading branch information
elraphty committed Dec 3, 2024
1 parent 4da5e61 commit d9cc3a2
Showing 1 changed file with 115 additions and 0 deletions.
115 changes: 115 additions & 0 deletions auth/auth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,3 +124,118 @@ func TestAdminCheck(t *testing.T) {
})
}
}

// Mock function to be tested
func TestIsFreePass(t *testing.T) {
t.Setenv("SUPER_ADMINS", "")
tests := []struct {
name string
superAdmins []string
adminDevFreePass string
adminStrings string
expected bool
}{
{
name: "Single SuperAdmin with FreePass",
superAdmins: []string{"freepass"},
adminDevFreePass: "freepass",
adminStrings: "non-empty",
expected: true,
},
{
name: "Empty AdminStrings",
superAdmins: []string{"admin"},
adminDevFreePass: "freepass",
adminStrings: "",
expected: true,
},
{
name: "Both Conditions Met",
superAdmins: []string{"freepass"},
adminDevFreePass: "freepass",
adminStrings: "",
expected: true,
},
{
name: "Multiple SuperAdmins",
superAdmins: []string{"freepass", "admin2"},
adminDevFreePass: "freepass",
adminStrings: "non-empty",
expected: false,
},
{
name: "Empty SuperAdmins List",
superAdmins: []string{},
adminDevFreePass: "freepass",
adminStrings: "non-empty",
expected: false,
},
{
name: "Empty SuperAdmins and Empty AdminStrings",
superAdmins: []string{},
adminDevFreePass: "freepass",
adminStrings: "",
expected: true,
},
{
name: "Null SuperAdmins",
superAdmins: nil,
adminDevFreePass: "freepass",
adminStrings: "non-empty",
expected: false,
},
{
name: "Null AdminStrings",
superAdmins: []string{"admin"},
adminDevFreePass: "freepass",
adminStrings: "",
expected: true,
},
{
name: "SuperAdmin with Different FreePass",
superAdmins: []string{"admin"},
adminDevFreePass: "freepass",
adminStrings: "non-empty",
expected: false,
},
{
name: "SuperAdmin with Empty String",
superAdmins: []string{""},
adminDevFreePass: "freepass",
adminStrings: "non-empty",
expected: false,
},
{
name: "Large SuperAdmins List",
superAdmins: make([]string, 1000),
adminDevFreePass: "freepass",
adminStrings: "non-empty",
expected: false,
},
{
name: "SuperAdmin with Null FreePass",
superAdmins: []string{"freepass"},
adminDevFreePass: "",
adminStrings: "non-empty",
expected: false,
},
{
name: "AdminDevFreePass as Empty String",
superAdmins: []string{"freepass"},
adminDevFreePass: "",
adminStrings: "non-empty",
expected: false,
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
config.SuperAdmins = tt.superAdmins
config.AdminDevFreePass = tt.adminDevFreePass
config.AdminStrings = tt.adminStrings

result := IsFreePass()
assert.Equal(t, tt.expected, result)
})
}
}

0 comments on commit d9cc3a2

Please sign in to comment.