From a81147dfed21e1725e5489ddfebfab6b4ea1bd7e Mon Sep 17 00:00:00 2001 From: Adam Scarr Date: Thu, 23 Aug 2018 11:52:09 +1000 Subject: [PATCH] Add a PR template --- .github/PULL_REQUEST_TEMPLATE.md | 5 ++++ TESTING.md | 40 ++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+) create mode 100644 .github/PULL_REQUEST_TEMPLATE.md create mode 100644 TESTING.md diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md new file mode 100644 index 0000000000..0d87bf9a0f --- /dev/null +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -0,0 +1,5 @@ +Describe your PR and link to any relevant issues. + +I have: + - [ ] Added tests covering the bug / feature (see [testing](https://github.com/99designs/gqlgen/blob/master/TESTING.md)) + - [ ] Updated any relevant documentation (see [docs](https://github.com/99designs/gqlgen/tree/master/docs/content)) diff --git a/TESTING.md b/TESTING.md new file mode 100644 index 0000000000..ad7e63352a --- /dev/null +++ b/TESTING.md @@ -0,0 +1,40 @@ +How to write tests for gqlgen +=== + +Testing generated code is a little tricky, heres how its currently set up. + +### Testing responses from a server + +There is a server in `codegen/testserver` that is generated as part +of `go generate ./...`, and tests written against it. + +There are also a bunch of tests in against the examples, feel free to take examples from there. + + +### Testing the errors generated by the binary + +These tests are **really** slow, because they need to run the whole codegen step. Use them very sparingly. If you can, find a way to unit test it instead. + +Take a look at `codegen/input_test.go` for an example. + +### Testing introspection + +Introspection is tested by diffing the output of `graphql get-schema` against an expected output. + +Setting up the integration environment is a little tricky: +```bash +cd integration +go generate ./... +go run ./server/server.go +``` +in another terminal +```bash +cd integration +npm install +SERVER_URL=http://localhost:8080/query ./node_modules/.bin/graphql get-schema +``` + +will write the schema to `integration/schema-fetched.graphql`, compare that with `schema-expected.graphql` + +CI will run this and fail the build if the two files dont match. +