Skip to content

Commit

Permalink
Merge 86de19c into f29d7bd
Browse files Browse the repository at this point in the history
  • Loading branch information
jirenius committed Mar 12, 2020
2 parents f29d7bd + 86de19c commit 6b26013
Show file tree
Hide file tree
Showing 8 changed files with 86 additions and 69 deletions.
22 changes: 8 additions & 14 deletions .travis.yml
@@ -1,21 +1,15 @@
language: go
go:
- 1.12.x
- 1.13.4
- 1.13.x
- 1.14
install:
- go get github.com/mattn/goveralls
- go get honnef.co/go/tools/cmd/staticcheck
- go get github.com/client9/misspell/cmd/misspell
- go get -t ./...
- ./scripts/install-checks.sh
before_script:
- PACKAGES=$(go list ./...)
- go get -d ./...
- if [[ "$TRAVIS_GO_VERSION" =~ ^1\.14(\.[0-9]+)?$ ]]; then ./scripts/check.sh; fi
- go build
- $(exit $(go fmt $PACKAGES | wc -l))
- go vet $PACKAGES
- misspell -error -locale US .
- staticcheck $PACKAGES
- if [[ "$TRAVIS_GO_VERSION" =~ ^1\.13\. ]] && [ "$TRAVIS_TAG" != "" ]; then ./scripts/cross_compile.sh $TRAVIS_TAG; fi
- if [[ "$TRAVIS_GO_VERSION" =~ ^1\.14(\.[0-9]+)?$ ]] && [ "$TRAVIS_TAG" != "" ]; then ./scripts/cross_compile.sh $TRAVIS_TAG; fi
script:
- if [[ "$TRAVIS_GO_VERSION" =~ ^1\.13\. ]]; then ./scripts/cover.sh TRAVIS; else go test -v -race $PACKAGES; fi
- if [[ "$TRAVIS_GO_VERSION" =~ ^1\.14(\.[0-9]+)?$ ]]; then ./scripts/cover.sh TRAVIS; else go test -v -race $PACKAGES; fi
after_success:
- if [[ "$TRAVIS_GO_VERSION" =~ ^1\.13\. ]] && [ "$TRAVIS_TAG" != "" ]; then ghr --owner resgateio --token $GITHUB_TOKEN --draft --replace $TRAVIS_TAG pkg/; fi
- if [[ "$TRAVIS_GO_VERSION" =~ ^1\.14(\.[0-9]+)?$ ]] && [ "$TRAVIS_TAG" != "" ]; then ghr --owner resgateio --token $GITHUB_TOKEN --draft --replace $TRAVIS_TAG pkg/; fi
4 changes: 2 additions & 2 deletions docs/res-service-protocol.md
Expand Up @@ -402,7 +402,7 @@ A delete action is a JSON object used when a property has been deleted from a mo
`event.<resourceName>.add`

Add events are sent when a value is added to a [collection](res-protocol.md#collections).
Any previous value at the same index or higher will implicity be shifted one step to a higher index.
Any previous value at the same index or higher will implicitly be shifted one step to a higher index.
MUST NOT be sent on [models](res-protocol.md#models).
The event payload has the following parameters:

Expand All @@ -427,7 +427,7 @@ MUST be a number that is zero or greater and less than or equal to the length of
`event.<resourceName>.remove`

Remove events are sent when a value is removed from a [collection](res-protocol.md#collections).
Any previous value at a higher index will implicity be shifted one step to a lower index.
Any previous value at a higher index will implicitly be shifted one step to a lower index.
MUST NOT be sent on [models](res-protocol.md#models).
The event payload has the following parameter:

Expand Down
16 changes: 16 additions & 0 deletions scripts/check.sh
@@ -0,0 +1,16 @@
#!/bin/bash -e
# Run from directory above via ./scripts/check.sh

echo "Checking formatting..."
if [ -n "$(gofmt -s -l .)" ]; then
echo "Code is not formatted. Run 'gofmt -s -w .'"
exit 1
fi
echo "Checking with go vet..."
go vet ./...
echo "Checking with staticcheck..."
staticcheck ./...
echo "Checking with golint..."
golint -set_exit_status ./...
echo "Checking with misspell..."
misspell -error -locale US .
8 changes: 8 additions & 0 deletions scripts/install-checks.sh
@@ -0,0 +1,8 @@
#!/bin/bash -e

pushd /tmp > /dev/null
go get -u github.com/mattn/goveralls
go get -u honnef.co/go/tools/cmd/staticcheck
go get -u golang.org/x/lint/golint
go get -u github.com/client9/misspell/cmd/misspell
popd > /dev/null
1 change: 0 additions & 1 deletion server/rescache/rescache.go
Expand Up @@ -123,7 +123,6 @@ func (c *Cache) Subscribe(sub Subscriber) {
eventSub.addSubscriber(sub)
}


// Access sends an access request
func (c *Cache) Access(sub Subscriber, token interface{}, callback func(access *Access)) {
rname := sub.ResourceName()
Expand Down
40 changes: 20 additions & 20 deletions test/01subscribe_test.go
Expand Up @@ -187,29 +187,29 @@ func TestSubscribe(t *testing.T) {

responses := map[string][]string{
// Model responses
"test.model": []string{"test.model"},
"test.model.parent": []string{"test.model.parent", "test.model"},
"test.model.grandparent": []string{"test.model.grandparent", "test.model.parent", "test.model"},
"test.model.secondparent": []string{"test.model.secondparent", "test.model"},
"test.model.brokenchild": []string{"test.model.brokenchild", "test.err.notFound"},
"test.model": {"test.model"},
"test.model.parent": {"test.model.parent", "test.model"},
"test.model.grandparent": {"test.model.grandparent", "test.model.parent", "test.model"},
"test.model.secondparent": {"test.model.secondparent", "test.model"},
"test.model.brokenchild": {"test.model.brokenchild", "test.err.notFound"},
// Cyclic model responses
"test.m.a": []string{"test.m.a"},
"test.m.b": []string{"test.m.b", "test.m.c"},
"test.m.d": []string{"test.m.d", "test.m.e", "test.m.f"},
"test.m.g": []string{"test.m.d", "test.m.e", "test.m.f", "test.m.g"},
"test.m.h": []string{"test.m.d", "test.m.e", "test.m.f", "test.m.h"},
"test.m.a": {"test.m.a"},
"test.m.b": {"test.m.b", "test.m.c"},
"test.m.d": {"test.m.d", "test.m.e", "test.m.f"},
"test.m.g": {"test.m.d", "test.m.e", "test.m.f", "test.m.g"},
"test.m.h": {"test.m.d", "test.m.e", "test.m.f", "test.m.h"},
// Collection responses
"test.collection": []string{"test.collection"},
"test.collection.parent": []string{"test.collection.parent", "test.collection"},
"test.collection.grandparent": []string{"test.collection.grandparent", "test.collection.parent", "test.collection"},
"test.collection.secondparent": []string{"test.collection.secondparent", "test.collection"},
"test.collection.brokenchild": []string{"test.collection.brokenchild", "test.err.notFound"},
"test.collection": {"test.collection"},
"test.collection.parent": {"test.collection.parent", "test.collection"},
"test.collection.grandparent": {"test.collection.grandparent", "test.collection.parent", "test.collection"},
"test.collection.secondparent": {"test.collection.secondparent", "test.collection"},
"test.collection.brokenchild": {"test.collection.brokenchild", "test.err.notFound"},
// Cyclic collection responses
"test.c.a": []string{"test.c.a"},
"test.c.b": []string{"test.c.b", "test.c.c"},
"test.c.d": []string{"test.c.d", "test.c.e", "test.c.f"},
"test.c.g": []string{"test.c.d", "test.c.e", "test.c.f", "test.c.g"},
"test.c.h": []string{"test.c.d", "test.c.e", "test.c.f", "test.c.h"},
"test.c.a": {"test.c.a"},
"test.c.b": {"test.c.b", "test.c.c"},
"test.c.d": {"test.c.d", "test.c.e", "test.c.f"},
"test.c.g": {"test.c.d", "test.c.e", "test.c.f", "test.c.g"},
"test.c.h": {"test.c.d", "test.c.e", "test.c.f", "test.c.h"},
}

for i, l := range sequenceTable {
Expand Down
58 changes: 29 additions & 29 deletions test/resources.go
Expand Up @@ -44,49 +44,49 @@ func resourceData(rid string) string {

var resources = map[string]resource{
// Model resources
"test.model": resource{typeModel, `{"string":"foo","int":42,"bool":true,"null":null}`, nil},
"test.model.parent": resource{typeModel, `{"name":"parent","child":{"rid":"test.model"}}`, nil},
"test.model.secondparent": resource{typeModel, `{"name":"secondparent","child":{"rid":"test.model"}}`, nil},
"test.model.grandparent": resource{typeModel, `{"name":"grandparent","child":{"rid":"test.model.parent"}}`, nil},
"test.model.brokenchild": resource{typeModel, `{"name":"brokenchild","child":{"rid":"test.err.notFound"}}`, nil},
"test.model": {typeModel, `{"string":"foo","int":42,"bool":true,"null":null}`, nil},
"test.model.parent": {typeModel, `{"name":"parent","child":{"rid":"test.model"}}`, nil},
"test.model.secondparent": {typeModel, `{"name":"secondparent","child":{"rid":"test.model"}}`, nil},
"test.model.grandparent": {typeModel, `{"name":"grandparent","child":{"rid":"test.model.parent"}}`, nil},
"test.model.brokenchild": {typeModel, `{"name":"brokenchild","child":{"rid":"test.err.notFound"}}`, nil},

// Cyclic model resources
"test.m.a": resource{typeModel, `{"a":{"rid":"test.m.a"}}`, nil},
"test.m.a": {typeModel, `{"a":{"rid":"test.m.a"}}`, nil},

"test.m.b": resource{typeModel, `{"c":{"rid":"test.m.c"}}`, nil},
"test.m.c": resource{typeModel, `{"b":{"rid":"test.m.b"}}`, nil},
"test.m.b": {typeModel, `{"c":{"rid":"test.m.c"}}`, nil},
"test.m.c": {typeModel, `{"b":{"rid":"test.m.b"}}`, nil},

"test.m.d": resource{typeModel, `{"e":{"rid":"test.m.e"},"f":{"rid":"test.m.f"}}`, nil},
"test.m.e": resource{typeModel, `{"d":{"rid":"test.m.d"}}`, nil},
"test.m.f": resource{typeModel, `{"d":{"rid":"test.m.d"}}`, nil},
"test.m.d": {typeModel, `{"e":{"rid":"test.m.e"},"f":{"rid":"test.m.f"}}`, nil},
"test.m.e": {typeModel, `{"d":{"rid":"test.m.d"}}`, nil},
"test.m.f": {typeModel, `{"d":{"rid":"test.m.d"}}`, nil},

"test.m.g": resource{typeModel, `{"e":{"rid":"test.m.e"},"f":{"rid":"test.m.f"}}`, nil},
"test.m.h": resource{typeModel, `{"e":{"rid":"test.m.e"}}`, nil},
"test.m.g": {typeModel, `{"e":{"rid":"test.m.e"},"f":{"rid":"test.m.f"}}`, nil},
"test.m.h": {typeModel, `{"e":{"rid":"test.m.e"}}`, nil},

// Collection resources
"test.collection": resource{typeCollection, `["foo",42,true,null]`, nil},
"test.collection.parent": resource{typeCollection, `["parent",{"rid":"test.collection"}]`, nil},
"test.collection.secondparent": resource{typeCollection, `["secondparent",{"rid":"test.collection"}]`, nil},
"test.collection.grandparent": resource{typeCollection, `["grandparent",{"rid":"test.collection.parent"}]`, nil},
"test.collection.brokenchild": resource{typeCollection, `["brokenchild",{"rid":"test.err.notFound"}]`, nil},
"test.collection": {typeCollection, `["foo",42,true,null]`, nil},
"test.collection.parent": {typeCollection, `["parent",{"rid":"test.collection"}]`, nil},
"test.collection.secondparent": {typeCollection, `["secondparent",{"rid":"test.collection"}]`, nil},
"test.collection.grandparent": {typeCollection, `["grandparent",{"rid":"test.collection.parent"}]`, nil},
"test.collection.brokenchild": {typeCollection, `["brokenchild",{"rid":"test.err.notFound"}]`, nil},

// Cyclic collection resources
"test.c.a": resource{typeCollection, `[{"rid":"test.c.a"}]`, nil},
"test.c.a": {typeCollection, `[{"rid":"test.c.a"}]`, nil},

"test.c.b": resource{typeCollection, `[{"rid":"test.c.c"}]`, nil},
"test.c.c": resource{typeCollection, `[{"rid":"test.c.b"}]`, nil},
"test.c.b": {typeCollection, `[{"rid":"test.c.c"}]`, nil},
"test.c.c": {typeCollection, `[{"rid":"test.c.b"}]`, nil},

"test.c.d": resource{typeCollection, `[{"rid":"test.c.e"},{"rid":"test.c.f"}]`, nil},
"test.c.e": resource{typeCollection, `[{"rid":"test.c.d"}]`, nil},
"test.c.f": resource{typeCollection, `[{"rid":"test.c.d"}]`, nil},
"test.c.d": {typeCollection, `[{"rid":"test.c.e"},{"rid":"test.c.f"}]`, nil},
"test.c.e": {typeCollection, `[{"rid":"test.c.d"}]`, nil},
"test.c.f": {typeCollection, `[{"rid":"test.c.d"}]`, nil},

"test.c.g": resource{typeCollection, `[{"rid":"test.c.e"},{"rid":"test.c.f"}]`, nil},
"test.c.h": resource{typeCollection, `[{"rid":"test.c.e"}]`, nil},
"test.c.g": {typeCollection, `[{"rid":"test.c.e"},{"rid":"test.c.f"}]`, nil},
"test.c.h": {typeCollection, `[{"rid":"test.c.e"}]`, nil},

// Errors
"test.err.notFound": resource{typeError, "", reserr.ErrNotFound},
"test.err.internalError": resource{typeError, "", reserr.ErrInternalError},
"test.err.timeout": resource{typeError, "", reserr.ErrTimeout},
"test.err.notFound": {typeError, "", reserr.ErrNotFound},
"test.err.internalError": {typeError, "", reserr.ErrInternalError},
"test.err.timeout": {typeError, "", reserr.ErrTimeout},
}

// Call responses
Expand Down
6 changes: 3 additions & 3 deletions test/test.go
Expand Up @@ -33,7 +33,7 @@ func setup(t *testing.T, cfgs ...func(*server.Config)) *Session {
l := NewCountLogger(true, true)

c := NewNATSTestClient(l)
serv, err := server.NewService(c, TestConfig(cfgs...))
serv, err := server.NewService(c, DefaultConfig(cfgs...))
if err != nil {
t.Fatalf("error creating new service: %s", err)
}
Expand Down Expand Up @@ -138,8 +138,8 @@ func teardown(s *Session) {
}
}

// TestConfig returns a default server configuration used for testing
func TestConfig(cfgs ...func(*server.Config)) server.Config {
// DefaultConfig returns a default server configuration used for testing
func DefaultConfig(cfgs ...func(*server.Config)) server.Config {
var cfg server.Config
cfg.SetDefault()
cfg.NoHTTP = true
Expand Down

0 comments on commit 6b26013

Please sign in to comment.