http: roleAtLeast helper for the role hierarchy
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
package http
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"gitea.dcglab.co.uk/steve/restic-manager/internal/store"
|
||||
)
|
||||
|
||||
func TestRoleAtLeast(t *testing.T) {
|
||||
t.Parallel()
|
||||
cases := []struct {
|
||||
have store.Role
|
||||
min store.Role
|
||||
want bool
|
||||
}{
|
||||
{store.RoleViewer, store.RoleViewer, true},
|
||||
{store.RoleOperator, store.RoleViewer, true},
|
||||
{store.RoleAdmin, store.RoleViewer, true},
|
||||
{store.RoleAdmin, store.RoleOperator, true},
|
||||
{store.RoleAdmin, store.RoleAdmin, true},
|
||||
{store.RoleViewer, store.RoleOperator, false},
|
||||
{store.RoleViewer, store.RoleAdmin, false},
|
||||
{store.RoleOperator, store.RoleAdmin, false},
|
||||
{store.Role("nonsense"), store.RoleViewer, false},
|
||||
{store.RoleAdmin, store.Role("nonsense"), false},
|
||||
}
|
||||
for _, c := range cases {
|
||||
got := roleAtLeast(c.have, c.min)
|
||||
if got != c.want {
|
||||
t.Errorf("have=%q min=%q: got %v want %v", c.have, c.min, got, c.want)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user