Skip to content

Commit

Permalink
fixed travis ci, added makefile, resolved lint issues
Browse files Browse the repository at this point in the history
Signed-off-by: Hitesh Sethi <hitesh.sethi@rapyuta-robotics.com>
  • Loading branch information
Hitesh Sethi committed May 19, 2021
1 parent 646f973 commit f94eaa5
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 10 deletions.
7 changes: 4 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ language: go

sudo: required

env:
- GO111MODULE=on

go:
- tip

Expand All @@ -10,10 +13,8 @@ service:

before_install:
- echo $TRAVIS_GO_VERSION
- go get github.com/mattn/goveralls
- go get go.etcd.io/etcd/clientv3
- docker pull quay.io/coreos/etcd:v3.3.10
- docker run -d -p 2379:2379 quay.io/coreos/etcd:v3.3.10 etcd --name casbin --listen-client-urls http://0.0.0.0:2379 --advertise-client-urls http://0.0.0.0:2379

script:
- $HOME/gopath/bin/goveralls -service=travis-ci
- make test
7 changes: 7 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
default: lint test

test:
go test -race -v .

lint:
golangci-lint run --verbose
7 changes: 5 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,17 @@ go 1.13

require (
github.com/casbin/casbin/v2 v2.30.2
github.com/cncf/udpa/go v0.0.0-20201120205902-5459f2c99403 // indirect
github.com/coreos/etcd v3.3.25+incompatible // indirect
github.com/coreos/go-semver v0.3.0 // indirect
github.com/coreos/go-systemd v0.0.0-20191104093116-d3cd4ed1dbcf // indirect
github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f // indirect
github.com/envoyproxy/go-control-plane v0.9.5 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/google/uuid v1.2.0 // indirect
github.com/stretchr/testify v1.5.1 // indirect
go.etcd.io/etcd v3.3.25+incompatible
go.uber.org/zap v1.16.0 // indirect
google.golang.org/genproto v0.0.0-20210518161634-ec7691c0a37d // indirect
google.golang.org/grpc v1.37.1 // indirect
google.golang.org/grpc v1.26.0 // indirect; updating this breaks etcd
)
7 changes: 7 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ github.com/casbin/casbin/v2 v2.30.2 h1:g+bXYucta9vCcWlIRzeVJLkey6UAUwFqk3gg/VW10
github.com/casbin/casbin/v2 v2.30.2/go.mod h1:vByNa/Fchek0KZUgG5wEsl7iFsiviAYKRtgrQfcJqHg=
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
github.com/cncf/udpa/go v0.0.0-20200313221541-5f7e5dd04533/go.mod h1:WmhPx2Nbnhtbo57+VJT5O0JRkEi1Wbu0z5j0R8u5Hbk=
github.com/cncf/udpa/go v0.0.0-20200629203442-efcf912fb354/go.mod h1:WmhPx2Nbnhtbo57+VJT5O0JRkEi1Wbu0z5j0R8u5Hbk=
github.com/cncf/udpa/go v0.0.0-20201120205902-5459f2c99403/go.mod h1:WmhPx2Nbnhtbo57+VJT5O0JRkEi1Wbu0z5j0R8u5Hbk=
github.com/coreos/etcd v0.5.0-alpha.5 h1:0Qi6Jzjk2CDuuGlIeecpu+em2nrjhOgz2wsIwCmQHmc=
github.com/coreos/etcd v3.3.24+incompatible h1:VTP6JXFEpcUyewV0VWQKC1dqeZ4mfq9SbRIyYvTq0nc=
Expand All @@ -23,6 +25,10 @@ github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSs
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
github.com/envoyproxy/go-control-plane v0.9.5/go.mod h1:OXl5to++W0ctG+EHWTFUjiypVxC/Y4VLc/KFU+al13s=
github.com/envoyproxy/go-control-plane v0.9.6/go.mod h1:GFqM7v0B62MraO4PWRedIbhThr/Rf7ev6aHOOPXeaDA=
github.com/envoyproxy/go-control-plane v0.9.7/go.mod h1:cwu0lG7PUMfa9snN8LXBig5ynNVH9qI8YYLbd1fK2po=
github.com/envoyproxy/go-control-plane v0.9.8/go.mod h1:cXg6YxExXjJnVBQHBLXeUAgxn2UodCpnH306RInaBQk=
github.com/envoyproxy/go-control-plane v0.9.9-0.20201210154907-fd9021fe5dad/go.mod h1:cXg6YxExXjJnVBQHBLXeUAgxn2UodCpnH306RInaBQk=
github.com/envoyproxy/go-control-plane v0.9.9-0.20210217033140-668b12f5399d/go.mod h1:cXg6YxExXjJnVBQHBLXeUAgxn2UodCpnH306RInaBQk=
github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c=
Expand Down Expand Up @@ -163,6 +169,7 @@ google.golang.org/grpc v1.25.1/go.mod h1:c3i+UQWmh7LiEpx4sFZnkU36qjEYZ0imhYfXVyQ
google.golang.org/grpc v1.26.0 h1:2dTRdpdFEEhJYQD8EMLB61nnrzSCTbG38PhqdhvOltg=
google.golang.org/grpc v1.26.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk=
google.golang.org/grpc v1.27.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk=
google.golang.org/grpc v1.36.1 h1:cmUfbeGKnz9+2DD/UYsMQXeqbHZqZDs4eQwW0sFOpBY=
google.golang.org/grpc v1.36.1/go.mod h1:qjiiYl8FncCW8feJPdyg3v6XW24KsRHe+dy9BAGRRjU=
google.golang.org/grpc v1.37.1 h1:ARnQJNWxGyYJpdf/JXscNlQr/uv607ZPU9Z7ogHi+iI=
google.golang.org/grpc v1.37.1/go.mod h1:NREThFqKR1f3iQ6oBuvc5LadQuXVGo9rkm5ZGrQdJfM=
Expand Down
4 changes: 3 additions & 1 deletion watcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@ func NewWatcher(endpoints []string, keyName string) (persist.Watcher, error) {
// Call the destructor when the object is released.
runtime.SetFinalizer(w, finalizer)

go w.startWatch()
go func() {
_ = w.startWatch()
}()

return w, nil
}
Expand Down
11 changes: 7 additions & 4 deletions watcher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func TestWatcher(t *testing.T) {
// listener represents any other Casbin enforcer instance that watches the change of policy in DB.
listener, _ := NewWatcher([]string{"http://127.0.0.1:2379"}, "/casbin")
// listener should set a callback that gets called when policy changes.
listener.SetUpdateCallback(updateCallback)
_ = listener.SetUpdateCallback(updateCallback)

// updater changes the policy, and sends the notifications.
err := updater.Update()
Expand All @@ -55,14 +55,17 @@ func TestWithEnforcer(t *testing.T) {
e, _ := casbin.NewEnforcer("examples/rbac_model.conf", "examples/rbac_policy.csv")

// Set the watcher for the enforcer.
e.SetWatcher(w)
_ = e.SetWatcher(w)

// By default, the watcher's callback is automatically set to the
// enforcer's LoadPolicy() in the SetWatcher() call.
// We can change it by explicitly setting a callback.
w.SetUpdateCallback(updateCallback)
_ = w.SetUpdateCallback(updateCallback)

// Update the policy to test the effect.
// You should see "[New revision detected: X]" in the log.
e.SavePolicy()
err := e.SavePolicy()
if err != nil {
t.Fail()
}
}

0 comments on commit f94eaa5

Please sign in to comment.