-
Notifications
You must be signed in to change notification settings - Fork 138
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
CBG-1966 enable staticcheck #6556
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,7 +35,6 @@ func BenchmarkBcryptCostTimes(b *testing.B) { | |
|
||
for i := minCostToTest; i < maxCostToTest; i++ { | ||
b.Run(fmt.Sprintf("cost%d", i), func(bn *testing.B) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Benchmark looks wrong as-is anyway (no b.N loop) Maybe we should just swap this to a test that logs the values, as we get the same one-off benefit even without assertions. // TestBcryptCostTimes will output the time it takes to hash a password with each bcrypt cost value
func TestBcryptCostTimes(t *testing.T) {
// Little value in running this regularly. Might be useful for one-off informational purposes
t.Skip("Test disabled")
minCostToTest := bcrypt.DefaultCost
maxCostToTest := bcrypt.DefaultCost + 5
for i := minCostToTest; i < maxCostToTest; i++ {
t.Run(fmt.Sprintf("cost%d", i), func(t *testing.T) {
startTime := time.Now()
_, err := bcrypt.GenerateFromPassword([]byte("hunter2"), i)
duration := time.Since(startTime)
t.Logf("bcrypt.GenerateFromPassword with cost %d took: %v", i, duration)
assert.NoError(t, err)
})
}
}
|
||
bn.N = 1 | ||
_, err := bcrypt.GenerateFromPassword([]byte("hunter2"), i) | ||
assert.NoError(bn, err) | ||
}) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,8 +10,8 @@ package base | |
|
||
import ( | ||
"bytes" | ||
"crypto/rand" | ||
"fmt" | ||
"math/rand" | ||
"os" | ||
"path/filepath" | ||
"runtime" | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,12 +10,12 @@ package db | |
|
||
import ( | ||
"context" | ||
"crypto/rand" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This file/ There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. golang/go#20661 officially deprecates I don't know that we need cryptographic randomness anywhere, but I could see making this mistake. Most tools (goimports, etc) will add cryptographic rand anyway for new code. We could make an exception for this because I don't think that we currently need cryptographic randomness anywhere, but I don't think this is necessary. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks like the intention is to switch to a locally scoped |
||
"encoding/base64" | ||
"encoding/json" | ||
"errors" | ||
"fmt" | ||
"log" | ||
"math/rand" | ||
"net/http" | ||
"strconv" | ||
"strings" | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -413,10 +413,10 @@ func (db *DatabaseCollectionWithUser) GetDelta(ctx context.Context, docID, fromR | |
// db.DbStats.StatsDeltaSync().Add(base.StatKeyDeltaCacheHits, 1) | ||
db.dbStats().DeltaSync().DeltaCacheHit.Add(1) | ||
return fromRevision.Delta, nil, nil | ||
} else { | ||
// TODO: Recurse and merge deltas when gen(revCacheDelta.toRevID) < gen(toRevId) | ||
// until then, fall through to generating delta for given rev pair | ||
} | ||
} // else { | ||
// TODO: Recurse and merge deltas when gen(revCacheDelta.toRevID) < gen(toRevId) | ||
// until then, fall through to generating delta for given rev pair | ||
// } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd be OK removing this completely. Storage/memory vs. CPU tradeoff. |
||
} | ||
|
||
// Delta is unavailable, but the body is available. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,10 +13,10 @@ package rest | |
import ( | ||
"bytes" | ||
"compress/gzip" | ||
"crypto/rand" | ||
"fmt" | ||
"io" | ||
"log" | ||
"math/rand" | ||
"mime/multipart" | ||
"net/http" | ||
"strconv" | ||
|
@@ -26,6 +26,7 @@ import ( | |
"github.com/couchbase/sync_gateway/base" | ||
"github.com/couchbase/sync_gateway/db" | ||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestWriteMultipartDocument(t *testing.T) { | ||
|
@@ -163,7 +164,8 @@ func TestWriteJSONPart(t *testing.T) { | |
// a body larger than 300 bytes to test writeJSONPart with compression=true and compression=false | ||
mockFakeBody := func() db.Body { | ||
bytes := make([]byte, 139) | ||
rand.Read(bytes) | ||
_, err := rand.Read(bytes) | ||
require.NoError(t, err) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Doesn't need crypto rand |
||
value := fmt.Sprintf("%x", bytes) | ||
return db.Body{"key": "foo", "value": value} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't quite look right - comparing greater than
0
seems unintentional.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is right, because it is checking that this value got updated - are you suggesting I remove this check, or move
lastUpdated
time lower thanuser.SetJWTLastUpdated(time.Now())
and useAssertTimestampGreaterThan
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nevermind, this doesn't get updated.