@@ -85,3 +85,40 @@ func TestCacheResize(t *testing.T) {
8585 t .Errorf ("want %d entries, got %d" , want , got )
8686 }
8787}
88+
89+ func TestCacheWithLang (t * testing.T ) {
90+ c := NewCache (10 )
91+ ip := net .ParseIP ("192.0.2.1" )
92+
93+ // Test different lang parameters create different cache entries
94+ responseZh := Response {IP : ip , Country : "中国" }
95+ responseEn := Response {IP : ip , Country : "China" }
96+ responseDefault := Response {IP : ip , Country : "Default" }
97+
98+ c .SetWithLang (ip , "zh" , responseZh )
99+ c .SetWithLang (ip , "en" , responseEn )
100+ c .SetWithLang (ip , "" , responseDefault )
101+
102+ // Should have 3 different cache entries
103+ if got , want := len (c .entries ), 3 ; got != want {
104+ t .Errorf ("want %d entries, got %d" , want , got )
105+ }
106+
107+ // Test retrieval
108+ if resp , ok := c .GetWithLang (ip , "zh" ); ! ok || resp .Country != "中国" {
109+ t .Errorf ("GetWithLang(ip, 'zh') = (%v, %t), want (Response{Country: '中国'}, true)" , resp , ok )
110+ }
111+
112+ if resp , ok := c .GetWithLang (ip , "en" ); ! ok || resp .Country != "China" {
113+ t .Errorf ("GetWithLang(ip, 'en') = (%v, %t), want (Response{Country: 'China'}, true)" , resp , ok )
114+ }
115+
116+ if resp , ok := c .GetWithLang (ip , "" ); ! ok || resp .Country != "Default" {
117+ t .Errorf ("GetWithLang(ip, '') = (%v, %t), want (Response{Country: 'Default'}, true)" , resp , ok )
118+ }
119+
120+ // Test backward compatibility
121+ if resp , ok := c .Get (ip ); ! ok || resp .Country != "Default" {
122+ t .Errorf ("Get(ip) = (%v, %t), want (Response{Country: 'Default'}, true)" , resp , ok )
123+ }
124+ }
0 commit comments