forked from baron/baron-sso
테스트 코드 추가
This commit is contained in:
56
backend/internal/utils/slug_test.go
Normal file
56
backend/internal/utils/slug_test.go
Normal file
@@ -0,0 +1,56 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestValidateSlug_ReservedKeywords(t *testing.T) {
|
||||
tests := []struct {
|
||||
slug string
|
||||
valid bool
|
||||
}{
|
||||
{"my-tenant", true},
|
||||
{"admin", false},
|
||||
{"api", false},
|
||||
{"static", false},
|
||||
{"security", false},
|
||||
{"billing", false},
|
||||
{"ns", false},
|
||||
{"mx", false},
|
||||
{"webmaster", false},
|
||||
{"status", false},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.slug, func(t *testing.T) {
|
||||
valid, msg := ValidateSlug(tt.slug)
|
||||
assert.Equal(t, tt.valid, valid, "Slug: "+tt.slug+" - "+msg)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestValidateSlug_Format(t *testing.T) {
|
||||
tests := []struct {
|
||||
slug string
|
||||
valid bool
|
||||
}{
|
||||
{"abc", true},
|
||||
{"a-b-c", true},
|
||||
{"123", true},
|
||||
{"ab", false}, // Too short
|
||||
{"-abc", false}, // Starts with hyphen
|
||||
{"abc-", false}, // Ends with hyphen
|
||||
{"Abc", true}, // Case insensitive check (converted to lower)
|
||||
{"invalid_slug", false}, // Contains underscore
|
||||
{"too-long-slug-name-that-exceeds-thirty-two-chars", false},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.slug, func(t *testing.T) {
|
||||
valid, _ := ValidateSlug(tt.slug)
|
||||
assert.Equal(t, tt.valid, valid)
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user