Skip to content

Commit

Permalink
more ignoring the linter (#32)
Browse files Browse the repository at this point in the history
Insecure random number generation isn't a problem in tests.
  • Loading branch information
dangermike authored Jun 18, 2024
1 parent beb671b commit 70f4b10
Show file tree
Hide file tree
Showing 10 changed files with 21 additions and 20 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.vscode/
.DS_Store
test-results/
dist/
8 changes: 4 additions & 4 deletions bench/lazylru_benchmark_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ func (bc benchconfig) Generic(b *testing.B) {
runtime.GC()
b.ResetTimer()
for i := 0; i < b.N; i++ {
ix := rand.IntN(bc.keyCount)
if rand.Float64() < bc.readRate {
ix := rand.IntN(bc.keyCount) //nolint:gosec
if rand.Float64() < bc.readRate { //nolint:gosec
lru.Get(keys[ix])
} else {
lru.Set(keys[ix], ix)
Expand All @@ -67,8 +67,8 @@ func (bc benchconfig) GenInterface(b *testing.B) {
runtime.GC()
b.ResetTimer()
for i := 0; i < b.N; i++ {
ix := rand.IntN(bc.keyCount)
if rand.Float64() < bc.readRate {
ix := rand.IntN(bc.keyCount) //nolint:gosec
if rand.Float64() < bc.readRate { //nolint:gosec
lru.Get(keys[ix])
} else {
lru.Set(keys[ix], ix)
Expand Down
4 changes: 2 additions & 2 deletions bench/test_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const validChars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ01234567
func randomString(size int) string {
retval := make([]byte, size)
for i := 0; i < len(retval); i++ {
retval[i] = validChars[rand.IntN(len(validChars))]
retval[i] = validChars[rand.IntN(len(validChars))] //nolint:gosec
}
return string(retval)
}
Expand Down Expand Up @@ -40,7 +40,7 @@ func NewTestData(count int) TestDataSimple {

// RandomKV retrieves a random key/value pair
func (td TestDataSimple) RandomKV() (string, string) {
kv := td[rand.IntN(len(td))]
kv := td[rand.IntN(len(td))] //nolint:gosec
return kv.Key, kv.Value
}

Expand Down
2 changes: 1 addition & 1 deletion containers/heap/heap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ func TestFix(t *testing.T) {
h.verify(t, 0)

for i := 100; i > 0; i-- {
elem := rand.IntN(h.Len())
elem := rand.IntN(h.Len()) //nolint:gosec
if i&1 == 0 {
(*h)[elem] *= 2
} else {
Expand Down
2 changes: 1 addition & 1 deletion generic/containers/heap/heap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ func TestFix(t *testing.T) {
h.verify(t, 0)

for i := 100; i > 0; i-- {
elem := rand.IntN(h.Len())
elem := rand.IntN(h.Len()) //nolint:gosec
if i&1 == 0 {
(*h)[elem] *= 2
} else {
Expand Down
2 changes: 1 addition & 1 deletion generic/lazylru.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ func (lru *LazyLRU[K, V]) reap(start int, deathList []*item[K, V]) {
break
}
if start < 0 {
start = rand.IntN(len(lru.items))
start = rand.IntN(len(lru.items)) //nolint:gosec
}
end := start + 100 // why 100? no idea
if end > len(lru.items) {
Expand Down
12 changes: 6 additions & 6 deletions generic/lazylru_benchmark_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func (bc benchconfig) InterfaceArray(b *testing.B) {
b.ResetTimer()
for i := 0; i < b.N; i++ {
ix := i % bc.keyCount
if rand.Float64() < bc.readRate {
if rand.Float64() < bc.readRate { //nolint:gosec
// if true {
if iv, ok := lru.Get(keys[ix]); !ok {
continue
Expand Down Expand Up @@ -91,7 +91,7 @@ func (bc benchconfig) GenericArray(b *testing.B) {
b.ResetTimer()
for i := 0; i < b.N; i++ {
ix := i % bc.keyCount
if rand.Float64() < bc.readRate {
if rand.Float64() < bc.readRate { //nolint:gosec
// if true {
if v, ok := lru.Get(keys[ix]); !ok {
continue
Expand All @@ -114,7 +114,7 @@ func (bc benchconfig) InterfaceStructPtr(b *testing.B) {
b.ResetTimer()
for i := 0; i < b.N; i++ {
ix := i % bc.keyCount
if rand.Float64() < bc.readRate {
if rand.Float64() < bc.readRate { //nolint:gosec
// if true {
if iv, ok := lru.Get(keys[ix]); !ok {
continue
Expand Down Expand Up @@ -143,7 +143,7 @@ func (bc benchconfig) GenericStructPtr(b *testing.B) {
b.ResetTimer()
for i := 0; i < b.N; i++ {
ix := i % bc.keyCount
if rand.Float64() < bc.readRate {
if rand.Float64() < bc.readRate { //nolint:gosec
// if true {
if v, ok := lru.Get(keys[ix]); !ok {
continue
Expand All @@ -166,7 +166,7 @@ func (bc benchconfig) InterfaceValue(b *testing.B) {
b.ResetTimer()
for i := 0; i < b.N; i++ {
ix := i % bc.keyCount
if rand.Float64() < bc.readRate {
if rand.Float64() < bc.readRate { //nolint:gosec
// if true {
if iv, ok := lru.Get(keys[ix]); !ok {
continue
Expand Down Expand Up @@ -195,7 +195,7 @@ func (bc benchconfig) GenericValue(b *testing.B) {
b.ResetTimer()
for i := 0; i < b.N; i++ {
ix := i % bc.keyCount
if rand.Float64() < bc.readRate {
if rand.Float64() < bc.readRate { //nolint:gosec
// if true {
if v, ok := lru.Get(keys[ix]); !ok {
continue
Expand Down
4 changes: 2 additions & 2 deletions generic/sharded/lazylru_benchmark_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ func (bc benchconfig) Run(b *testing.B) {
for c := 0; c < bc.concurrency; c++ {
go func(c int) {
for i := c; i < b.N; i += bc.concurrency {
ix := rand.IntN(bc.keyCount)
if rand.Float64() < bc.readRate {
ix := rand.IntN(bc.keyCount) //nolint:gosec
if rand.Float64() < bc.readRate { //nolint:gosec
lru.Get(keys[ix])
} else {
lru.Set(keys[ix], ix)
Expand Down
2 changes: 1 addition & 1 deletion lazylru_benchmark_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ func (bc benchconfig) GenericValue(b *testing.B) {
b.ResetTimer()
for i := 0; i < b.N; i++ {
ix := i % bc.keyCount
if rand.Float64() < bc.readRate {
if rand.Float64() < bc.readRate { //nolint:gosec
// if true {
if v, ok := lru.Get(keys[ix]); !ok {
continue
Expand Down
4 changes: 2 additions & 2 deletions sharded/lazylru_benchmark_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ func (bc benchconfig) Run(b *testing.B) {
for c := 0; c < bc.concurrency; c++ {
go func(c int) {
for i := c; i < b.N; i += bc.concurrency {
ix := rand.IntN(bc.keyCount)
if rand.Float64() < bc.readRate {
ix := rand.IntN(bc.keyCount) //nolint:gosec
if rand.Float64() < bc.readRate { //nolint:gosec
lru.Get(keys[ix])
} else {
lru.Set(keys[ix], ix)
Expand Down

0 comments on commit 70f4b10

Please sign in to comment.