mirror of
https://github.com/qdm12/gluetun.git
synced 2026-05-10 04:30:20 +02:00
4a78989d9d
- main reason being it's a burden to always define sentinel errors at global scope, wrap them with `%w` instead of using a string directly - only use sentinel errors when it has to be checked using `errors.Is` - replace all usage of these sentinel errors in `fmt.Errorf` with direct strings that were in the sentinel error - exclude the sentinel error definition requirement from .golangci.yml - update unit tests to use ContainersError instead of ErrorIs so it stays as a "not a change detector test" without requiring a sentinel error
60 lines
1.3 KiB
Go
60 lines
1.3 KiB
Go
package auth
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
// Read reads the toml file specified by the filepath given.
|
|
func Test_settingsToLookupMap(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
testCases := map[string]struct {
|
|
settings Settings
|
|
routeToRoles map[string][]internalRole
|
|
errMessage string
|
|
}{
|
|
"empty_settings": {
|
|
routeToRoles: map[string][]internalRole{},
|
|
},
|
|
"auth_method_not_supported": {
|
|
settings: Settings{
|
|
Roles: []Role{{Name: "a", Auth: "bad"}},
|
|
},
|
|
errMessage: "authentication method not supported: bad",
|
|
},
|
|
"success": {
|
|
settings: Settings{
|
|
Roles: []Role{
|
|
{Name: "a", Auth: AuthNone, Routes: []string{"GET /path"}},
|
|
{Name: "b", Auth: AuthNone, Routes: []string{"GET /path", "PUT /path"}},
|
|
},
|
|
},
|
|
routeToRoles: map[string][]internalRole{
|
|
"GET /path": {
|
|
{name: "a", checker: newNoneMethod()}, // deduplicated method
|
|
},
|
|
"PUT /path": {
|
|
{name: "b", checker: newNoneMethod()},
|
|
},
|
|
},
|
|
},
|
|
}
|
|
|
|
for name, testCase := range testCases {
|
|
t.Run(name, func(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
routeToRoles, err := settingsToLookupMap(testCase.settings)
|
|
|
|
assert.Equal(t, testCase.routeToRoles, routeToRoles)
|
|
if testCase.errMessage != "" {
|
|
assert.EqualError(t, err, testCase.errMessage)
|
|
} else {
|
|
assert.NoError(t, err)
|
|
}
|
|
})
|
|
}
|
|
}
|