Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integration tests #279

Merged
merged 7 commits into from
Aug 9, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 42 additions & 14 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,20 +1,48 @@
version: 2
jobs:
build:
working_directory: /app
docker:
- image: golang:1.9
working_directory: /go/src/github.com/99designs/gqlgen
steps: &steps
- image: docker:18
steps:
- checkout
- run: >
curl -L -o /bin/dep https://github.com/golang/dep/releases/download/v0.4.1/dep-linux-amd64 &&
chmod +x /bin/dep &&
go get -u github.com/alecthomas/gometalinter github.com/vektah/gorunpkg &&
gometalinter --install &&
dep ensure -vendor-only
- run: go install -v . && go get -u github.com/vektah/dataloaden github.com/pkg/errors
- run: go generate ./... && if [[ $(git --no-pager diff) ]] ; then echo "you need to run go generate" ; git --no-pager diff ; exit 1 ; fi
- run: go vet ./...
- run: go test -race ./...
- run: gometalinter --vendor ./...
- setup_remote_docker:
docker_layer_caching: true
- run:
name: "docker build"
command: |
docker build -f .circleci/golang.Dockerfile -t gqlgen/golang .
docker build -f .circleci/node.Dockerfile -t gqlgen/node .

- run:
name: "golang tests"
command: docker run --rm gqlgen/golang .circleci/test.sh

- run:
name: "integration tests"
command: |
function cleanup {
echo "Cleaning up containers..."
docker kill $SERVER_CONTAINER 1>/dev/null 2>/dev/null || true
docker rm --force -v $SERVER_CONTAINER 1>/dev/null 2>/dev/null || true
}
trap cleanup EXIT

SERVER_CONTAINER=$(docker run -d \
-e PORT=1234 \
--name integration_server \
gqlgen/golang go run ./integration/server/server.go \
)

sleep 2

docker run \
-e SERVER_URL=http://integration_server:1234/query \
--link=integration_server \
gqlgen/node ../.circleci/integration.sh

echo "### server logs"
docker logs $SERVER_CONTAINER

exit $(docker inspect $SERVER_CONTAINER --format='{{.State.ExitCode}}')

12 changes: 12 additions & 0 deletions .circleci/golang.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
FROM golang:1.10

RUN curl -L -o /bin/dep https://github.com/golang/dep/releases/download/v0.4.1/dep-linux-amd64 && chmod +x /bin/dep
RUN go get -u github.com/alecthomas/gometalinter github.com/vektah/gorunpkg
RUN gometalinter --install

WORKDIR /go/src/github.com/99designs/gqlgen

COPY Gopkg.* /go/src/github.com/99designs/gqlgen/
RUN dep ensure -v --vendor-only

COPY . /go/src/github.com/99designs/gqlgen/
17 changes: 17 additions & 0 deletions .circleci/integration.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/bash

set -eu

echo "### running jest integration spec"
./node_modules/.bin/jest --color


echo "### validating introspected schema"
./node_modules/.bin/graphql get-schema

if ! diff <(tail -n +3 schema-expected.graphql) <(tail -n +3 schema-fetched.graphql) ; then
echo "The expected schema has changed, you need to update schema-expected.graphql with any expected changes"
exit 1
fi


9 changes: 9 additions & 0 deletions .circleci/node.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
FROM node:10

WORKDIR /gqlgen/integration


COPY integration/package*.json /gqlgen/integration/
RUN npm ci

COPY . /gqlgen/
18 changes: 18 additions & 0 deletions .circleci/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/bash

set -eu

echo "### go generating"
go generate $(go list ./... | grep -v codegen/tests)

if [[ $(git --no-pager diff) ]] ; then
echo "you need to run go generate"
git --no-pager diff
exit 1
fi

echo "### running testsuite"
go test -race $(go list ./... | grep -v codegen/tests)

echo "### linting"
gometalinter --vendor ./...
3 changes: 3 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/**/node_modules
/codegen/tests/gen
/vendor
2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ indent_size = 4
[*.{go,gotpl}]
indent_style = tab

[*.{yml}]
[*.yml]
indent_size = 2

# These often end up with go code inside, so lets keep tabs
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
/vendor
/docs/public
/example/chat/node_modules
/integration/node_modules
/integration/schema-fetched.graphql
/example/chat/package-lock.json
/codegen/tests/gen

Expand Down
7 changes: 5 additions & 2 deletions example/chat/generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions example/config/generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions example/dataloader/generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions example/scalars/generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions example/scalars/resolvers.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ func (r *queryResolver) User(ctx context.Context, id external.ObjectID) (*model.
ID: id,
Name: fmt.Sprintf("Test User %d", id),
Created: time.Now(),
Address: model.Address{ID: 1, Location: &model.Point{1, 2}},
Address: model.Address{ID: 1, Location: &model.Point{X: 1, Y: 2}},
Tier: model.TierC,
}, nil
}

func (r *queryResolver) Search(ctx context.Context, input model.SearchArgs) ([]model.User, error) {
location := model.Point{1, 2}
location := model.Point{X: 1, Y: 2}
if input.Location != nil {
location = *input.Location
}
Expand Down Expand Up @@ -70,5 +70,5 @@ func (r *userResolver) PrimitiveResolver(ctx context.Context, obj *model.User) (
}

func (r *userResolver) CustomResolver(ctx context.Context, obj *model.User) (model.Point, error) {
return model.Point{5, 1}, nil
return model.Point{X: 5, Y: 1}, nil
}
7 changes: 5 additions & 2 deletions example/selection/generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions example/starwars/generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions example/todo/generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 15 additions & 14 deletions graphql/introspection/type.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,25 +31,26 @@ func WrapTypeFromType(s *ast.Schema, typ *ast.Type) *Type {
}

func (t *Type) Kind() string {
if t.def != nil {
return string(t.def.Kind)
}
if t.typ != nil {
if t.typ.NonNull {
return "NON_NULL"
}

if t.typ.NonNull {
return "NOT_NULL"
if t.typ.Elem != nil {
return "LIST"
}
} else {
return string(t.def.Kind)
}

if t.typ.Elem != nil {
return "LIST"
}
return "UNKNOWN"
panic("UNKNOWN")
}

func (t *Type) Name() string {
func (t *Type) Name() *string {
if t.def == nil {
return ""
return nil
}
return t.def.Name
return &t.def.Name
}

func (t *Type) Description() string {
Expand Down Expand Up @@ -164,10 +165,10 @@ func (t *Type) OfType() *Type {
}
if t.typ.NonNull {
// fake non null nodes
cpy := t.typ
cpy := *t.typ
cpy.NonNull = false

return WrapTypeFromType(t.schema, cpy)
return WrapTypeFromType(t.schema, &cpy)
}
return WrapTypeFromType(t.schema, t.typ.Elem)
}
2 changes: 1 addition & 1 deletion graphql/introspection/type_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func TestType(t *testing.T) {
}

t.Run("name", func(t *testing.T) {
require.Equal(t, "Query", schemaType.Name())
require.Equal(t, "Query", *schemaType.Name())
})

t.Run("description", func(t *testing.T) {
Expand Down
3 changes: 3 additions & 0 deletions integration/.babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"presets": ["env"]
}
14 changes: 14 additions & 0 deletions integration/.graphqlconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"projects": {
"Project Name": {
"schemaPath": "schema-fetched.graphql",
"extensions": {
"endpoints": {
"dev": {
"url": "${env:SERVER_URL}"
}
}
}
}
}
}
Empty file added integration/config.yaml
Empty file.
Loading