Fix golangci-lint issues
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package internal
|
||||
|
||||
import (
|
||||
"crypto/md5"
|
||||
"fmt"
|
||||
"io"
|
||||
"math"
|
||||
@@ -180,7 +181,7 @@ func ParseWALSegmentPath(s string) (index int, offset int64, err error) {
|
||||
if i32 > math.MaxInt32 {
|
||||
return 0, 0, fmt.Errorf("index too large in wal segment path %q", s)
|
||||
}
|
||||
off64, _ := strconv.ParseInt(a[2], 16, 64)
|
||||
off64, _ := strconv.ParseUint(a[2], 16, 64)
|
||||
if off64 > math.MaxInt64 {
|
||||
return 0, 0, fmt.Errorf("offset too large in wal segment path %q", s)
|
||||
}
|
||||
@@ -228,3 +229,8 @@ func TruncateDuration(d time.Duration) time.Duration {
|
||||
}
|
||||
return d
|
||||
}
|
||||
|
||||
// MD5hash returns a hex-encoded MD5 hash of b.
|
||||
func MD5hash(b []byte) string {
|
||||
return fmt.Sprintf("%x", md5.Sum(b))
|
||||
}
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
package testingutil
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"io"
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"github.com/pierrec/lz4/v4"
|
||||
)
|
||||
|
||||
// ReadFile reads all data from filename. Fail on error.
|
||||
@@ -62,3 +65,26 @@ func Setenv(tb testing.TB, key, value string) func() {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func CompressLZ4(tb testing.TB, b []byte) []byte {
|
||||
tb.Helper()
|
||||
|
||||
var buf bytes.Buffer
|
||||
zw := lz4.NewWriter(&buf)
|
||||
if _, err := zw.Write(b); err != nil {
|
||||
tb.Fatal(err)
|
||||
} else if err := zw.Close(); err != nil {
|
||||
tb.Fatal(err)
|
||||
}
|
||||
return buf.Bytes()
|
||||
}
|
||||
|
||||
func DecompressLZ4(tb testing.TB, b []byte) []byte {
|
||||
tb.Helper()
|
||||
|
||||
buf, err := io.ReadAll(lz4.NewReader(bytes.NewReader(b)))
|
||||
if err != nil {
|
||||
tb.Fatal(err)
|
||||
}
|
||||
return buf
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user