1
0
forked from baron/baron-sso
Files
baron-sso/backend/internal/utils/slug_test.go
2026-02-19 17:00:39 +09:00

57 lines
1.2 KiB
Go

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)
})
}
}