package domain import "testing" func TestRedisKey_ToString(t *testing.T) { tests := []struct { name string key RedisKey want string }{ {"AccessToken Key", AccessTokenRedisKey, "permission:access_token"}, {"UIDToken Key", UIDTokenRedisKey, "permission:uid_token"}, {"Ticket Key", TicketRedisKey, "permission:ticket"}, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { if got := tt.key.ToString(); got != tt.want { t.Errorf("ToString() = %v, want %v", got, tt.want) } }) } } func TestRedisKey_With(t *testing.T) { tests := []struct { name string key RedisKey args []string want string }{ {"AccessToken with ID", AccessTokenRedisKey, []string{"12345"}, "access_token:12345"}, {"UIDToken with UID", UIDTokenRedisKey, []string{"67890"}, "uid_token:67890"}, {"Ticket with multiple parts", TicketRedisKey, []string{"session", "12345"}, "ticket:session:12345"}, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { if got := tt.key.With(tt.args...).ToString(); got != "permission:"+tt.want { t.Errorf("With() = %v, want %v", got, "permission:"+tt.want) } }) } } func TestGetAccessTokenRedisKey(t *testing.T) { tests := []struct { name string id string want string }{ {"AccessToken Key with ID", "12345", "permission:access_token:12345"}, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { if got := GetAccessTokenRedisKey(tt.id); got != tt.want { t.Errorf("GetAccessTokenRedisKey() = %v, want %v", got, tt.want) } }) } } func TestGetUIDTokenRedisKey(t *testing.T) { tests := []struct { name string uid string want string }{ {"UIDToken Key with UID", "67890", "permission:uid_token:67890"}, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { if got := GetUIDTokenRedisKey(tt.uid); got != tt.want { t.Errorf("GetUIDTokenRedisKey() = %v, want %v", got, tt.want) } }) } } func TestGetTicketRedisKey(t *testing.T) { tests := []struct { name string ticket string want string }{ {"Ticket Key with Ticket", "session123", "permission:ticket:session123"}, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { if got := GetTicketRedisKey(tt.ticket); got != tt.want { t.Errorf("GetTicketRedisKey() = %v, want %v", got, tt.want) } }) } }