Skip to content

Commit 4b0cefc

Browse files
authored
Merge pull request #67 from someone1/lint-race
Add lint and race checks with associated fixes
2 parents 66b7fd6 + 66b184b commit 4b0cefc

File tree

14 files changed

+227
-112
lines changed

14 files changed

+227
-112
lines changed

.travis.yml

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
language: go
22
sudo: false
33
go:
4-
- 1.10.x
54
- 1.11.x
5+
- 1.12.x
66
env:
7-
- REDIS_ADDR="localhost:6379" APPENGINE_DEV_APPSERVER="$HOME/google-cloud-sdk/bin/dev_appserver.py" GO111MODULE="on"
7+
- REDIS_ADDR="localhost:6379" APPENGINE_DEV_APPSERVER="$HOME/google-cloud-sdk/bin/dev_appserver.py" GO111MODULE="on" DATASTORE_EMULATOR_HOST="localhost:8432" DATASTORE_PROJECT_ID="nds-test"
88
services:
99
- redis-server
1010
before_install:
@@ -16,13 +16,15 @@ install:
1616
- "$HOME/google-cloud-sdk/bin/gcloud components install app-engine-python --quiet"
1717
- "$HOME/google-cloud-sdk/bin/gcloud components install app-engine-go --quiet"
1818
- go get -v -d -t ./...
19+
- go get github.com/golangci/golangci-lint/cmd/golangci-lint
1920
before_script:
2021
- "$HOME/google-cloud-sdk/bin/gcloud config set project nds-test"
21-
- "$HOME/google-cloud-sdk/bin/gcloud beta emulators datastore start --quiet &"
22-
- sleep 15
23-
- "$($HOME/google-cloud-sdk/bin/gcloud beta emulators datastore env-init)"
22+
- "$HOME/google-cloud-sdk/bin/gcloud beta emulators datastore start --quiet --no-store-on-disk --consistency=1 --host-port=localhost:8432 &"
23+
- timeout 300 bash -c 'while [[ "$(curl -s -o /dev/null -w ''%{http_code}'' $DATASTORE_EMULATOR_HOST)" != "200" ]]; do sleep 5; done' || false
2424
script:
2525
- go test -covermode=count -coverprofile=profile.cov -coverpkg=$(go list ./... | grep -v '/vendor/' | paste -sd, -) ./...
26+
- go test -race ./...
27+
- golangci-lint run ./...
2628
after_success:
2729
- go get -v github.com/mattn/goveralls
2830
- export PATH=$PATH:$HOME/gopath/bin

cache_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ func CacherImplementationTest(ctx context.Context, cacher nds.Cacher) func(t *te
232232
} else if got == nil {
233233
if result, err := cacher.GetMulti(tt.args.c, keys); err != nil {
234234
t.Errorf("expected err = nil, got %v", err)
235-
} else if result != nil && len(result) != 0 {
235+
} else if len(result) != 0 {
236236
t.Errorf("expected len(cacher.GetMulti()) = 0, got %d", len(result))
237237
}
238238
}

cachers/memcache/memcache.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99
"github.com/qedus/nds/v2"
1010
)
1111

12-
type backend struct {}
12+
type backend struct{}
1313

1414
// NewCacher will return a nds.Cacher backed by AppEngine's memcache.
1515
func NewCacher() nds.Cacher {

cachers/memory/memory.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,9 @@ func (m *memory) CompareAndSwapMulti(ctx context.Context, items []*nds.Item) err
7272
Value: append([]byte(nil), obj.value...),
7373
}
7474
hasher := sha1.New()
75-
binary.Write(hasher, binary.LittleEndian, ndsItem.Flags)
76-
hasher.Write(ndsItem.Value) // err is always nil
77-
if bytes.Compare(item.GetCASInfo().([]byte), hasher.Sum(nil)) == 0 {
75+
_ = binary.Write(hasher, binary.LittleEndian, ndsItem.Flags)
76+
_, _ = hasher.Write(ndsItem.Value) // err is always nil
77+
if bytes.Equal(item.GetCASInfo().([]byte), hasher.Sum(nil)) {
7878
m.store.Set(item.Key, &object{flags: item.Flags, value: append([]byte(nil), item.Value...)}, item.Expiration)
7979
} else {
8080
hasErr = true
@@ -134,8 +134,8 @@ func (m *memory) GetMulti(ctx context.Context, keys []string) (map[string]*nds.I
134134
Value: append([]byte(nil), obj.value...),
135135
}
136136
hasher := sha1.New()
137-
binary.Write(hasher, binary.LittleEndian, ndsItem.Flags)
138-
hasher.Write(ndsItem.Value)
137+
_ = binary.Write(hasher, binary.LittleEndian, ndsItem.Flags)
138+
_, _ = hasher.Write(ndsItem.Value)
139139
ndsItem.SetCASInfo(hasher.Sum(nil))
140140
result[key] = ndsItem
141141
}

0 commit comments

Comments
 (0)