app-cloudep-permission-server/pkg/domain/token/additional_test.go

56 lines
1.1 KiB
Go

package token
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestAdditional_String(t *testing.T) {
tests := []struct {
name string
input Additional
expected string
}{
{"ID to String", ID, "id"},
{"Role to String", Role, "role"},
{"Device to String", Device, "device"},
{"UID to String", UID, "uid"},
{"Account to String", Account, "account"},
{"Scope to String", Scope, "scope"},
{"Type to String", Type, "token_type"},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
result := tt.input.String()
assert.Equal(t, tt.expected, result)
})
}
}
func TestIsValidAdditional(t *testing.T) {
validKeys := []Additional{
ID, Role, Device,
UID, Account, Scope, Type,
}
invalidKeys := []Additional{
"invalid", "unknown", "random", "test",
}
// 測試有效 Key
for _, key := range validKeys {
t.Run("ValidKey_"+key.String(), func(t *testing.T) {
assert.True(t, IsValidAdditional(key))
})
}
// 測試無效 Key
for _, key := range invalidKeys {
t.Run("InvalidKey_"+string(key), func(t *testing.T) {
assert.False(t, IsValidAdditional(key))
})
}
}