Skip to content

Commit

Permalink
feat: add cypress e2e tests (#334)
Browse files Browse the repository at this point in the history
  • Loading branch information
aeneasr authored May 1, 2020
1 parent eae48b3 commit abc0e91
Show file tree
Hide file tree
Showing 68 changed files with 2,245 additions and 199 deletions.
95 changes: 94 additions & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ jobs:
image: cockroachdb/cockroach:v19.2.0
command: start --insecure
-
image: oryd/hydra:v1.2.2
image: oryd/hydra:v1.4.10
environment:
- DSN=memory
- URLS_SELF_ISSUER=http://127.0.0.1:4444/
Expand Down Expand Up @@ -72,6 +72,55 @@ jobs:
-
run: test -z "$CIRCLE_PR_NUMBER" && goveralls -service=circle-ci -coverprofile=coverage.txt -repotoken=$COVERALLS_REPO_TOKEN || echo "forks are not allowed to push to coveralls"

test-e2e:
parameters:
flavor:
type: string
docker:
- image: oryd/e2e-env:latest
environment:
- GO111MODULE=on
- TEST_DATABASE_MYSQL=mysql://root:test@(localhost:3306)/mysql?parseTime=true&multiStatements=true
- TEST_DATABASE_COCKROACHDB=cockroach://root@localhost:26257/defaultdb?sslmode=disable
- TEST_DATABASE_POSTGRESQL=postgres://test:test@localhost:5432/kratos?sslmode=disable
- image: postgres:9.6
environment:
- POSTGRES_USER=test
- POSTGRES_PASSWORD=test
- POSTGRES_DB=kratos
- image: cockroachdb/cockroach:v2.1.6
command: start --insecure
- image: mysql:5.7
environment:
- MYSQL_ROOT_PASSWORD=test
- image: oryd/mailslurper:latest-smtps
working_directory: /go/src/github.com/ory/kratos
steps:
- checkout
# core node_modules cache
- restore_cache:
keys:
- v1-deps-{{ checksum "package-lock.json" }}
- v1-deps
- run: npm ci
- save_cache:
key: v1-deps-{{ checksum "package-lock.json" }}
# cache NPM modules and the folder with the Cypress binary
paths:
- ~/.npm
- ~/.cache
# go modules cache
- restore_cache:
keys:
- go-mod-v1-{{ checksum "go.sum" }}
- run: go mod download
- save_cache:
key: go-mod-v1-{{ checksum "go.sum" }}
paths:
- "/go/pkg/mod"
- run: make deps
- run: ./test/e2e/run.sh << parameters.flavor >>

workflows:
tbr:
jobs:
Expand All @@ -81,6 +130,30 @@ workflows:
filters:
tags:
only: /.*/
- test-e2e:
name: test-e2e-sqlite
flavor: sqlite
filters:
tags:
only: /.*/
- test-e2e:
name: test-e2e-postgres
flavor: postgres
filters:
tags:
only: /.*/
- test-e2e:
name: test-e2e-mysql
flavor: mysql
filters:
tags:
only: /.*/
- test-e2e:
name: test-e2e-cockroach
flavor: cockroach
filters:
tags:
only: /.*/
-
test:
filters:
Expand All @@ -90,6 +163,10 @@ workflows:
appname: Ory_Kratos
requires:
- test
- test-e2e-sqlite
- test-e2e-postgres
- test-e2e-mysql
- test-e2e-cockroach
- golangci/lint
filters:
tags:
Expand All @@ -99,6 +176,10 @@ workflows:
- docs/build:
requires:
- test
- test-e2e-sqlite
- test-e2e-postgres
- test-e2e-mysql
- test-e2e-cockroach
- golangci/lint
filters:
tags:
Expand All @@ -108,6 +189,10 @@ workflows:
- sdk/release:
requires:
- test
- test-e2e-sqlite
- test-e2e-postgres
- test-e2e-mysql
- test-e2e-cockroach
- golangci/lint
- sdk/generate
- goreleaser/release
Expand All @@ -119,6 +204,10 @@ workflows:
- changelog/generate:
requires:
- test
- test-e2e-sqlite
- test-e2e-postgres
- test-e2e-mysql
- test-e2e-cockroach
- golangci/lint
filters:
tags:
Expand All @@ -135,6 +224,10 @@ workflows:
requires:
- goreleaser/test
- test
- test-e2e-sqlite
- test-e2e-postgres
- test-e2e-mysql
- test-e2e-cockroach
- golangci/lint
filters:
branches:
Expand Down
11 changes: 11 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[*]
charset = utf-8
end_of_line = lf
indent_size = 2
indent_style = space
insert_final_newline = true
trim_trailing_whitespace = true

[*.go]
indent_size = 4
indent_style = tab
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,6 @@ packrd/
*-packr.go
dist/
node_modules
.bin/
.bin/*
cypress/videos
cypress/screenshots
30 changes: 15 additions & 15 deletions .schema/config.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@
"type": "boolean"
}
},
"additionalItems": false,
"additionalProperties": false,
"required": [
"default_redirect_url"
]
}
},
"additionalItems": false,
"additionalProperties": false,
"required": [
"hook",
"config"
Expand All @@ -50,7 +50,7 @@
"const": "revoke_active_sessions"
}
},
"additionalItems": false,
"additionalProperties": false,
"required": [
"hook"
]
Expand All @@ -62,7 +62,7 @@
"const": "verify"
}
},
"additionalItems": false,
"additionalProperties": false,
"required": [
"hook"
]
Expand All @@ -74,7 +74,7 @@
"const": "session"
}
},
"additionalItems": false,
"additionalProperties": false,
"required": [
"hook"
]
Expand Down Expand Up @@ -147,7 +147,7 @@
}
}
},
"additionalItems": false,
"additionalProperties": false,
"required": [
"id",
"provider",
Expand Down Expand Up @@ -272,7 +272,7 @@
},
"selfServiceBefore": {
"type": "object",
"additionalItems": false,
"additionalProperties": false,
"properties": {
"hooks": {
"type": "array",
Expand All @@ -296,18 +296,18 @@
"properties": {
"selfservice": {
"type": "object",
"additionalItems": false,
"additionalProperties": false,
"required": [
"logout"
],
"properties": {
"strategies": {
"type": "object",
"additionalItems": false,
"additionalProperties": false,
"properties": {
"password": {
"type": "object",
"additionalItems": false,
"additionalProperties": false,
"properties": {
"enabled": {
"type": "boolean"
Expand All @@ -316,14 +316,14 @@
},
"oidc": {
"type": "object",
"additionalItems": false,
"additionalProperties": false,
"properties": {
"enabled": {
"type": "boolean"
},
"config": {
"type": "object",
"additionalItems": false,
"additionalProperties": false,
"properties": {
"providers": {
"title": "OpenID Connect and OAuth2 Providers",
Expand Down Expand Up @@ -351,14 +351,14 @@
]
}
},
"additionalItems": false,
"additionalProperties": false,
"required": [
"redirect_to"
]
},
"settings": {
"type": "object",
"additionalItems": false,
"additionalProperties": false,
"properties": {
"request_lifespan": {
"type": "string",
Expand Down Expand Up @@ -434,7 +434,7 @@
"$ref": "#/definitions/selfServiceAfterLogin"
}
},
"additionalItems": false
"additionalProperties": false
},
"registration": {
"type": "object",
Expand Down
16 changes: 13 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ K := $(foreach exec,$(EXECUTABLES),\
$(if $(shell which $(exec)),some string,$(error "No $(exec) in PATH")))

export GO111MODULE := on
export PATH := .bin:${PATH}
export PATH := $(pwd)/.bin:${PATH}

deps:
ifneq ("v0", $(shell cat .bin/.lock))
Expand All @@ -18,7 +18,8 @@ ifneq ("v0", $(shell cat .bin/.lock))
go build -o .bin/goimports golang.org/x/tools/cmd/goimports
go build -o .bin/swagutil github.com/ory/sdk/swagutil
go build -o .bin/packr2 github.com/gobuffalo/packr/v2/packr2
npm i
go build -o .bin/yq github.com/mikefarah/yq
npm ci
echo "v0" > .bin/.lock
endif

Expand Down Expand Up @@ -60,7 +61,7 @@ test-resetdb:

.PHONY: test
test: test-resetdb
source scripts/test-envs.sh && go test -tags sqlite -count=1 ./...
source script/test-envs.sh && go test -tags sqlite -count=1 ./...

# Generates the SDKs
.PHONY: sdk
Expand Down Expand Up @@ -90,8 +91,17 @@ quickstart-dev:
.PHONY: format
format: deps
goreturns -w -local github.com/ory $$(listx .)
npm run format

# Runs tests in short mode, without database adapters
.PHONY: docker
docker:
docker build -f .docker/Dockerfile-build -t oryd/kratos:latest .

.PHONY: test-e2e
test-e2e: test-resetdb
source script/test-envs.sh
test/e2e/run.sh sqlite
test/e2e/run.sh postgres
test/e2e/run.sh cockroach
test/e2e/run.sh mysql
23 changes: 22 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<a href="#backers" alt="sponsors on Open Collective"><img src="https://opencollective.com/ory/backers/badge.svg" /></a> <a href="#sponsors" alt="Sponsors on Open Collective"><img src="https://opencollective.com/ory/sponsors/badge.svg" /></a>
</p>

ORY Kratos is the first and only cloud native Identity and User Management System in the world. Finally, it is no longer necessary to implement a User Login process for the umpteenth time!
ORY Kratos is the first and only cloud native Identity and User Management System in the world. Finally, it is no longer necessary to implement a User Login process for the umpteenth time!

<!-- START doctoc generated TOC please keep comment here to allow auto update -->
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
Expand Down Expand Up @@ -327,6 +327,12 @@ It is possible to develop ORY Kratos on Windows, but please be aware that all gu
When cloning ORY Kratos, run `make tools`. It will download several required dependencies. If you haven't run the command
in a while it's probably a good idea to run it again.

#### Install from source

```shell script
make install
```

#### Formatting Code

You can format all code using `make format`. Our CI checks if your code is properly formatted.
Expand Down Expand Up @@ -383,6 +389,21 @@ go test -tags sqlite ./...
cd client; go test -tags sqlite .
```

##### End-to-End Tests

We use [Cypress](https://www.cypress.io) to run our e2e tests. You can run all tests using:

```shell script
make test-e2e
```

If you intend developing e2e tests, run the following command for more details:

```shell script
./test/e2e/run.sh
```


#### Build Docker

You can build a development Docker Image using:
Expand Down
3 changes: 2 additions & 1 deletion cmd/daemon/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,10 +172,11 @@ func sqa(cmd *cobra.Command, d driver.Driver) *metricsx.Service {
func bgTasks(d driver.Driver, wg *sync.WaitGroup, cmd *cobra.Command, args []string) {
defer wg.Done()

d.Logger().Println("Courier worker started.")
if err := graceful.Graceful(d.Registry().Courier().Work, d.Registry().Courier().Shutdown); err != nil {
d.Logger().WithError(err).Fatalf("Failed to run courier worker.")
}
d.Logger().Println("courier worker was shutdown gracefully")
d.Logger().Println("Courier worker was shutdown gracefully.")
}

func ServeAll(d driver.Driver) func(cmd *cobra.Command, args []string) {
Expand Down
Loading

0 comments on commit abc0e91

Please sign in to comment.