From e39821f3defb7f31a52ff48f5e1b01433dd713a3 Mon Sep 17 00:00:00 2001 From: Anthony Romano Date: Wed, 13 Sep 2017 13:27:42 -0700 Subject: [PATCH] *: fix gofmt errors and makefile test --- Makefile | 15 ++++++----- bolt_unix.go | 6 ++--- bolt_unix_solaris.go | 4 +-- bolt_windows.go | 4 +-- db_test.go | 2 +- freelist_test.go | 62 ++++++++++++++++++++++---------------------- 6 files changed, 48 insertions(+), 45 deletions(-) diff --git a/Makefile b/Makefile index d3f6ed2..43b94f3 100644 --- a/Makefile +++ b/Makefile @@ -7,13 +7,16 @@ default: build race: @go test -v -race -test.run="TestSimulate_(100op|1000op)" -# go get honnef.co/go/tools/simple -# go get honnef.co/go/tools/unused fmt: - gosimple ./... - unused ./... - gofmt -l -s -d $(find -name \*.go) + !(gofmt -l -s -d $(shell find . -name \*.go) | grep '[a-z]') +# go get honnef.co/go/tools/simple +gosimple: + gosimple ./... + +# go get honnef.co/go/tools/unused +unused: + unused ./... # go get github.com/kisielk/errcheck errcheck: @@ -24,4 +27,4 @@ test: # Note: gets "program not an importable package" in out of path builds go test -v ./cmd/bolt -.PHONY: race fmt errcheck test +.PHONY: race fmt errcheck test gosimple unused diff --git a/bolt_unix.go b/bolt_unix.go index 17be1e4..06592a0 100644 --- a/bolt_unix.go +++ b/bolt_unix.go @@ -14,14 +14,14 @@ import ( func flock(db *DB, mode os.FileMode, exclusive bool, timeout time.Duration) error { var t time.Time if timeout != 0 { - t = time.Now() + t = time.Now() } fd := db.file.Fd() flag := syscall.LOCK_NB if exclusive { flag |= syscall.LOCK_EX } else { - flag |= syscall.LOCK_SH + flag |= syscall.LOCK_SH } for { // Attempt to obtain an exclusive lock. @@ -33,7 +33,7 @@ func flock(db *DB, mode os.FileMode, exclusive bool, timeout time.Duration) erro } // If we timed out then return an error. - if timeout != 0 && time.Since(t) > timeout - flockRetryTimeout { + if timeout != 0 && time.Since(t) > timeout-flockRetryTimeout { return ErrTimeout } diff --git a/bolt_unix_solaris.go b/bolt_unix_solaris.go index c397f87..fd8335e 100644 --- a/bolt_unix_solaris.go +++ b/bolt_unix_solaris.go @@ -14,7 +14,7 @@ import ( func flock(db *DB, mode os.FileMode, exclusive bool, timeout time.Duration) error { var t time.Time if timeout != 0 { - t = time.Now() + t = time.Now() } fd := db.file.Fd() var lockType int16 @@ -34,7 +34,7 @@ func flock(db *DB, mode os.FileMode, exclusive bool, timeout time.Duration) erro } // If we timed out then return an error. - if timeout != 0 && time.Since(t) > timeout - flockRetryTimeout { + if timeout != 0 && time.Since(t) > timeout-flockRetryTimeout { return ErrTimeout } diff --git a/bolt_windows.go b/bolt_windows.go index cad774c..77b66f8 100644 --- a/bolt_windows.go +++ b/bolt_windows.go @@ -60,7 +60,7 @@ func flock(db *DB, mode os.FileMode, exclusive bool, timeout time.Duration) erro var t time.Time if timeout != 0 { - t = time.Now() + t = time.Now() } fd := db.file.Fd() var flag uint32 = flagLockFailImmediately @@ -77,7 +77,7 @@ func flock(db *DB, mode os.FileMode, exclusive bool, timeout time.Duration) erro } // If we timed oumercit then return an error. - if timeout != 0 && time.Since(t) > timeout - flockRetryTimeout { + if timeout != 0 && time.Since(t) > timeout-flockRetryTimeout { return ErrTimeout } diff --git a/db_test.go b/db_test.go index 64a59dd..bd4927b 100644 --- a/db_test.go +++ b/db_test.go @@ -450,7 +450,7 @@ func TestDB_Open_ReadOnly(t *testing.T) { // Read from a read-only transaction. if err := readOnlyDB.View(func(tx *bolt.Tx) error { value := tx.Bucket([]byte("widgets")).Get([]byte("foo")) - if bytes.Compare(value, []byte("bar")) != 0 { + if !bytes.Equal(value, []byte("bar")) { t.Fatal("expect value 'bar', got", value) } return nil diff --git a/freelist_test.go b/freelist_test.go index 6b6c0ac..24ed4cf 100644 --- a/freelist_test.go +++ b/freelist_test.go @@ -65,83 +65,83 @@ func TestFreelist_releaseRange(t *testing.T) { }{ { title: "Single pending in range", - pagesIn: []testPage{testPage{id: 3, n: 1, allocTxn: 100, freeTxn: 200}}, - releaseRanges: []testRange{testRange{1, 300}}, + pagesIn: []testPage{{id: 3, n: 1, allocTxn: 100, freeTxn: 200}}, + releaseRanges: []testRange{{1, 300}}, wantFree: []pgid{3}, }, { title: "Single pending with minimum end range", - pagesIn: []testPage{testPage{id: 3, n: 1, allocTxn: 100, freeTxn: 200}}, - releaseRanges: []testRange{testRange{1, 200}}, + pagesIn: []testPage{{id: 3, n: 1, allocTxn: 100, freeTxn: 200}}, + releaseRanges: []testRange{{1, 200}}, wantFree: []pgid{3}, }, { title: "Single pending outsize minimum end range", - pagesIn: []testPage{testPage{id: 3, n: 1, allocTxn: 100, freeTxn: 200}}, - releaseRanges: []testRange{testRange{1, 199}}, + pagesIn: []testPage{{id: 3, n: 1, allocTxn: 100, freeTxn: 200}}, + releaseRanges: []testRange{{1, 199}}, wantFree: nil, }, { title: "Single pending with minimum begin range", - pagesIn: []testPage{testPage{id: 3, n: 1, allocTxn: 100, freeTxn: 200}}, - releaseRanges: []testRange{testRange{100, 300}}, + pagesIn: []testPage{{id: 3, n: 1, allocTxn: 100, freeTxn: 200}}, + releaseRanges: []testRange{{100, 300}}, wantFree: []pgid{3}, }, { title: "Single pending outside minimum begin range", - pagesIn: []testPage{testPage{id: 3, n: 1, allocTxn: 100, freeTxn: 200}}, - releaseRanges: []testRange{testRange{101, 300}}, + pagesIn: []testPage{{id: 3, n: 1, allocTxn: 100, freeTxn: 200}}, + releaseRanges: []testRange{{101, 300}}, wantFree: nil, }, { title: "Single pending in minimum range", - pagesIn: []testPage{testPage{id: 3, n: 1, allocTxn: 199, freeTxn: 200}}, - releaseRanges: []testRange{testRange{199, 200}}, + pagesIn: []testPage{{id: 3, n: 1, allocTxn: 199, freeTxn: 200}}, + releaseRanges: []testRange{{199, 200}}, wantFree: []pgid{3}, }, { title: "Single pending and read transaction at 199", - pagesIn: []testPage{testPage{id: 3, n: 1, allocTxn: 199, freeTxn: 200}}, - releaseRanges: []testRange{testRange{100, 198}, testRange{200, 300}}, + pagesIn: []testPage{{id: 3, n: 1, allocTxn: 199, freeTxn: 200}}, + releaseRanges: []testRange{{100, 198}, {200, 300}}, wantFree: nil, }, { title: "Adjacent pending and read transactions at 199, 200", pagesIn: []testPage{ - testPage{id: 3, n: 1, allocTxn: 199, freeTxn: 200}, - testPage{id: 4, n: 1, allocTxn: 200, freeTxn: 201}, + {id: 3, n: 1, allocTxn: 199, freeTxn: 200}, + {id: 4, n: 1, allocTxn: 200, freeTxn: 201}, }, releaseRanges: []testRange{ - testRange{100, 198}, - testRange{200, 199}, // Simulate the ranges db.freePages might produce. - testRange{201, 300}, + {100, 198}, + {200, 199}, // Simulate the ranges db.freePages might produce. + {201, 300}, }, wantFree: nil, }, { title: "Out of order ranges", pagesIn: []testPage{ - testPage{id: 3, n: 1, allocTxn: 199, freeTxn: 200}, - testPage{id: 4, n: 1, allocTxn: 200, freeTxn: 201}, + {id: 3, n: 1, allocTxn: 199, freeTxn: 200}, + {id: 4, n: 1, allocTxn: 200, freeTxn: 201}, }, releaseRanges: []testRange{ - testRange{201, 199}, - testRange{201, 200}, - testRange{200, 200}, + {201, 199}, + {201, 200}, + {200, 200}, }, wantFree: nil, }, { title: "Multiple pending, read transaction at 150", pagesIn: []testPage{ - testPage{id: 3, n: 1, allocTxn: 100, freeTxn: 200}, - testPage{id: 4, n: 1, allocTxn: 100, freeTxn: 125}, - testPage{id: 5, n: 1, allocTxn: 125, freeTxn: 150}, - testPage{id: 6, n: 1, allocTxn: 125, freeTxn: 175}, - testPage{id: 7, n: 2, allocTxn: 150, freeTxn: 175}, - testPage{id: 9, n: 2, allocTxn: 175, freeTxn: 200}, + {id: 3, n: 1, allocTxn: 100, freeTxn: 200}, + {id: 4, n: 1, allocTxn: 100, freeTxn: 125}, + {id: 5, n: 1, allocTxn: 125, freeTxn: 150}, + {id: 6, n: 1, allocTxn: 125, freeTxn: 175}, + {id: 7, n: 2, allocTxn: 150, freeTxn: 175}, + {id: 9, n: 2, allocTxn: 175, freeTxn: 200}, }, - releaseRanges: []testRange{testRange{50, 149}, testRange{151, 300}}, + releaseRanges: []testRange{{50, 149}, {151, 300}}, wantFree: []pgid{4, 9}, }, }