@@ -156,19 +156,37 @@ func TestConstructCacheWithDefaultHasher(t *testing.T) {
156156 assertEqual (t , true , ok )
157157}
158158
159- func TestWillReturnErrorOnInvalidNumberOfPartitions (t * testing.T ) {
159+ func TestNewBigcacheValidation (t * testing.T ) {
160160 t .Parallel ()
161161
162- // given
163- cache , error := NewBigCache (Config {
164- Shards : 18 ,
165- LifeWindow : 5 * time .Second ,
166- MaxEntriesInWindow : 10 ,
167- MaxEntrySize : 256 ,
168- })
169-
170- assertEqual (t , (* BigCache )(nil ), cache )
171- assertEqual (t , "Shards number must be power of two" , error .Error ())
162+ for _ , tc := range []struct {
163+ cfg Config
164+ want string
165+ }{
166+ {
167+ cfg : Config {Shards : 18 },
168+ want : "Shards number must be power of two" ,
169+ },
170+ {
171+ cfg : Config {Shards : 16 , MaxEntriesInWindow : - 1 },
172+ want : "MaxEntriesInWindow must be >= 0" ,
173+ },
174+ {
175+ cfg : Config {Shards : 16 , MaxEntrySize : - 1 },
176+ want : "MaxEntrySize must be >= 0" ,
177+ },
178+ {
179+ cfg : Config {Shards : 16 , HardMaxCacheSize : - 1 },
180+ want : "HardMaxCacheSize must be >= 0" ,
181+ },
182+ } {
183+ t .Run (tc .want , func (t * testing.T ) {
184+ cache , error := NewBigCache (tc .cfg )
185+
186+ assertEqual (t , (* BigCache )(nil ), cache )
187+ assertEqual (t , tc .want , error .Error ())
188+ })
189+ }
172190}
173191
174192func TestEntryNotFound (t * testing.T ) {
0 commit comments