Skip to content

Commit

Permalink
Merge pull request #18 from iFaceless/fix-test-error
Browse files Browse the repository at this point in the history
🐛 fix: test error
  • Loading branch information
iFaceless committed Jul 1, 2020
2 parents 5337638 + 7b98dda commit 55d35f4
Show file tree
Hide file tree
Showing 7 changed files with 74 additions and 29 deletions.
6 changes: 4 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@ go:
- 1.12.x
- 1.13.x
before_install:
- 'export GO111MODULE=on'
- 'go get -v golang.org/x/lint/golint'
- 'go get -v github.com/kisielk/errcheck'
- 'go get -u github.com/golangci/golangci-lint/cmd/golangci-lint'
- 'go get -v golang.org/x/tools/cmd/cover'
- 'go get -v github.com/mattn/goveralls'
- 'export GO111MODULE=on'
- curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.27.0


script:
- 'go mod tidy'
- '`go env GOPATH`/bin/golangci-lint run'
Expand Down
42 changes: 24 additions & 18 deletions cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package portal

import (
"fmt"
"sync/atomic"
"testing"
"time"

Expand Down Expand Up @@ -116,7 +117,7 @@ func TestDumpNestedWithCache(t *testing.T) {
assert.Equal(t, 1, nameCounter)
}

var metaCounter int
var metaCounter int32

type Food struct {
ID int
Expand All @@ -128,7 +129,7 @@ type meta struct {
}

func (f *Food) Meta() meta {
metaCounter += 1
atomic.AddInt32(&metaCounter, 1)
return meta{Weight: 10, Size: 20}
}

Expand All @@ -154,33 +155,38 @@ type FoodSchemaThree struct {
func TestDumpWithCacheDisabled(t *testing.T) {
SetCache(DefaultCache)
defer SetCache(nil)
metaCounter = 0
atomic.StoreInt32(&metaCounter, 0)

f := Food{
ID: 1,
}

var ff FoodSchema
Dump(&ff, &f)
assert.Equal(t, 2, metaCounter)
metaCounter = 0
err := Dump(&ff, &f)
assert.Nil(t, err)
assert.Equal(t, int32(2), atomic.LoadInt32(&metaCounter))
atomic.StoreInt32(&metaCounter, 0)

var ff2 FoodSchemaTwo
Dump(&ff2, &f)
assert.Equal(t, 2, metaCounter)
metaCounter = 0
err = Dump(&ff2, &f)
assert.Nil(t, err)
assert.Equal(t, int32(2), atomic.LoadInt32(&metaCounter))
atomic.StoreInt32(&metaCounter, 0)

var ff3 FoodSchemaThree
Dump(&ff3, &f)
assert.Equal(t, 1, metaCounter)
metaCounter = 0
err = Dump(&ff3, &f)
assert.Nil(t, err)
assert.Equal(t, int32(1), atomic.LoadInt32(&metaCounter))
atomic.StoreInt32(&metaCounter, 0)

Dump(&ff3, &f, DisableCache())
assert.Equal(t, 2, metaCounter)
metaCounter = 0
err = Dump(&ff3, &f, DisableCache())
assert.Nil(t, err)
assert.Equal(t, int32(2), atomic.LoadInt32(&metaCounter))
atomic.StoreInt32(&metaCounter, 0)

SetCache(nil)
Dump(&ff3, &f)
assert.Equal(t, 2, metaCounter)
metaCounter = 0
err = Dump(&ff3, &f)
assert.Nil(t, err)
assert.Equal(t, int32(2), atomic.LoadInt32(&metaCounter))
atomic.StoreInt32(&metaCounter, 0)
}
2 changes: 1 addition & 1 deletion chell.go
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ func (c *Chell) dumpMany(ctx context.Context, dst, src interface{}, onlyFields,
if field != "" {
panic(fmt.Sprintf("input src must be a slice, current processing field is `%s`", field))
} else {
panic(fmt.Sprintf("input src must be a slice"))
panic("input src must be a slice")
}
}

Expand Down
48 changes: 41 additions & 7 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,47 @@ module github.com/ifaceless/portal
go 1.13

require (
github.com/Djarvur/go-err113 v0.1.0 // indirect
github.com/bombsimon/wsl/v3 v3.1.0 // indirect
github.com/fatih/color v1.9.0 // indirect
github.com/fatih/structs v1.1.0
github.com/kr/pretty v0.1.0 // indirect
github.com/fsnotify/fsnotify v1.4.9 // indirect
github.com/go-critic/go-critic v0.5.0 // indirect
github.com/gogo/protobuf v1.3.1 // indirect
github.com/golangci/gocyclo v0.0.0-20180528144436-0a533e8fa43d // indirect
github.com/golangci/golangci-lint v1.26.0 // indirect
github.com/golangci/misspell v0.3.5 // indirect
github.com/golangci/revgrep v0.0.0-20180812185044-276a5c0a1039 // indirect
github.com/gostaticanalysis/analysisutil v0.1.0 // indirect
github.com/jirfag/go-printf-func-name v0.0.0-20200119135958-7558a9eaa5af // indirect
github.com/kisielk/errcheck v1.3.0 // indirect
github.com/mattn/go-colorable v0.1.7 // indirect
github.com/mitchellh/mapstructure v1.3.2 // indirect
github.com/panjf2000/ants/v2 v2.1.1
github.com/pkg/errors v0.8.1
github.com/sirupsen/logrus v1.4.2
github.com/spf13/cast v1.3.0
github.com/stretchr/testify v1.4.0
golang.org/x/sync v0.0.0-20200317015054-43a5402ce75a
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 // indirect
github.com/pelletier/go-toml v1.8.0 // indirect
github.com/pkg/errors v0.9.1
github.com/quasilyte/regex/syntax v0.0.0-20200419152657-af9db7f4a3ab // indirect
github.com/securego/gosec/v2 v2.3.0 // indirect
github.com/sirupsen/logrus v1.6.0
github.com/sourcegraph/go-diff v0.5.3 // indirect
github.com/spf13/afero v1.3.1 // indirect
github.com/spf13/cast v1.3.1
github.com/spf13/cobra v1.0.0 // indirect
github.com/spf13/jwalterweatherman v1.1.0 // indirect
github.com/spf13/viper v1.7.0 // indirect
github.com/stretchr/testify v1.6.1
github.com/tdakkota/asciicheck v0.0.0-20200416200610-e657995f937b // indirect
github.com/tetafro/godot v0.3.7 // indirect
github.com/timakin/bodyclose v0.0.0-20200424151742-cb6215831a94 // indirect
golang.org/x/lint v0.0.0-20200302205851-738671d3881b // indirect
golang.org/x/mod v0.3.0 // indirect
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e
golang.org/x/sys v0.0.0-20200625212154-ddb9806d33ae // indirect
golang.org/x/text v0.3.3 // indirect
golang.org/x/tools v0.0.0-20200701000337-a32c0cb1d5b2 // indirect
gopkg.in/ini.v1 v1.57.0 // indirect
gopkg.in/yaml.v3 v3.0.0-20200615113413-eeeca48fe776 // indirect
honnef.co/go/tools v0.0.1-2020.1.4 // indirect
mvdan.cc/unparam v0.0.0-20200501210554-b37ab49443f7 // indirect
sourcegraph.com/sqs/pbtypes v1.0.0 // indirect
)
File renamed without changes.
5 changes: 4 additions & 1 deletion utils.go → util.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,10 @@ func invokeWithCache(ctx context.Context, any reflect.Value, method reflect.Valu
}
ret, err := invoke(ctx, any, method, methodName, args...)
if err == nil {
cg.cache.Set(ctx, *cacheKey, ret)
err = cg.cache.Set(ctx, *cacheKey, ret)
if err != nil {
return nil, errors.WithStack(err)
}
return ret, nil
}
return ret, errors.WithStack(err)
Expand Down
File renamed without changes.

0 comments on commit 55d35f4

Please sign in to comment.