69012bb1ae
New test files: - config/config_test.go (100% coverage) - constants/constants_test.go (100% coverage) - httputil/response_test.go (100% coverage) - validation/rules_test.go (91.9% coverage) - middleware/logger_test.go, security_test.go, security_logger_test.go - handlers/errors_test.go Updated documentation: - doc/27-GO-TESTING.md: Complete testing guide - doc/00-GO-DOCUMENTATION-INDEX.md: Added testing section - doc/01-ARCHITECTURE.md: Updated package structure - doc/DECISIONS.md: Added ADR-004 caching decision - PROJECT-MEMORY.md: Added Go testing section
149 lines
3.3 KiB
Go
149 lines
3.3 KiB
Go
package constants
|
|
|
|
import (
|
|
"testing"
|
|
)
|
|
|
|
func TestAllLangs(t *testing.T) {
|
|
langs := AllLangs()
|
|
|
|
if len(langs) != 2 {
|
|
t.Errorf("Expected 2 languages, got %d", len(langs))
|
|
}
|
|
|
|
// Check that en and es are present
|
|
hasEn, hasEs := false, false
|
|
for _, lang := range langs {
|
|
if lang == LangEnglish {
|
|
hasEn = true
|
|
}
|
|
if lang == LangSpanish {
|
|
hasEs = true
|
|
}
|
|
}
|
|
|
|
if !hasEn {
|
|
t.Error("Expected English (en) to be in AllLangs()")
|
|
}
|
|
if !hasEs {
|
|
t.Error("Expected Spanish (es) to be in AllLangs()")
|
|
}
|
|
}
|
|
|
|
func TestIsValidLang(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
lang string
|
|
expected bool
|
|
}{
|
|
{"Valid - English", LangEnglish, true},
|
|
{"Valid - Spanish", LangSpanish, true},
|
|
{"Invalid - French", "fr", false},
|
|
{"Invalid - German", "de", false},
|
|
{"Invalid - Empty", "", false},
|
|
{"Invalid - Random", "xyz", false},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
result := IsValidLang(tt.lang)
|
|
if result != tt.expected {
|
|
t.Errorf("IsValidLang(%q) = %v, want %v", tt.lang, result, tt.expected)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestValidateLang(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
lang string
|
|
wantError bool
|
|
}{
|
|
{"Valid - English", LangEnglish, false},
|
|
{"Valid - Spanish", LangSpanish, false},
|
|
{"Invalid - French", "fr", true},
|
|
{"Invalid - Empty", "", true},
|
|
{"Invalid - Random", "xyz", true},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
err := ValidateLang(tt.lang)
|
|
if (err != nil) != tt.wantError {
|
|
t.Errorf("ValidateLang(%q) error = %v, wantError %v", tt.lang, err, tt.wantError)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestConstants(t *testing.T) {
|
|
// Test that default language is English
|
|
if LangDefault != LangEnglish {
|
|
t.Errorf("LangDefault = %q, want %q", LangDefault, LangEnglish)
|
|
}
|
|
|
|
// Test supported languages map
|
|
if !SupportedLanguages[LangEnglish] {
|
|
t.Error("SupportedLanguages should contain English")
|
|
}
|
|
if !SupportedLanguages[LangSpanish] {
|
|
t.Error("SupportedLanguages should contain Spanish")
|
|
}
|
|
if SupportedLanguages["fr"] {
|
|
t.Error("SupportedLanguages should not contain French")
|
|
}
|
|
}
|
|
|
|
func TestCVPreferenceConstants(t *testing.T) {
|
|
// Test CV preference values exist and are non-empty
|
|
if CVLengthShort == "" {
|
|
t.Error("CVLengthShort should not be empty")
|
|
}
|
|
if CVLengthLong == "" {
|
|
t.Error("CVLengthLong should not be empty")
|
|
}
|
|
if CVIconsShow == "" {
|
|
t.Error("CVIconsShow should not be empty")
|
|
}
|
|
if CVIconsHide == "" {
|
|
t.Error("CVIconsHide should not be empty")
|
|
}
|
|
if CVThemeDefault == "" {
|
|
t.Error("CVThemeDefault should not be empty")
|
|
}
|
|
if CVThemeClean == "" {
|
|
t.Error("CVThemeClean should not be empty")
|
|
}
|
|
}
|
|
|
|
func TestColorThemeConstants(t *testing.T) {
|
|
if ColorThemeLight == "" {
|
|
t.Error("ColorThemeLight should not be empty")
|
|
}
|
|
if ColorThemeDark == "" {
|
|
t.Error("ColorThemeDark should not be empty")
|
|
}
|
|
}
|
|
|
|
func TestCookieConstants(t *testing.T) {
|
|
if CookieMaxAge <= 0 {
|
|
t.Error("CookieMaxAge should be positive")
|
|
}
|
|
if CookiePath != "/" {
|
|
t.Error("CookiePath should be '/'")
|
|
}
|
|
}
|
|
|
|
func TestEnvironmentConstants(t *testing.T) {
|
|
if EnvProduction == "" {
|
|
t.Error("EnvProduction should not be empty")
|
|
}
|
|
if EnvDevelopment == "" {
|
|
t.Error("EnvDevelopment should not be empty")
|
|
}
|
|
if DefaultPort == "" {
|
|
t.Error("DefaultPort should not be empty")
|
|
}
|
|
}
|