Skip to content

Commit

Permalink
Merge pull request #18 from dsrhub/zz/add-functional-test
Browse files Browse the repository at this point in the history
Add functional test
  • Loading branch information
zhouzhuojie authored Jul 14, 2020
2 parents 06cefc1 + ff6e074 commit 4134f0e
Show file tree
Hide file tree
Showing 19 changed files with 281 additions and 165 deletions.
13 changes: 11 additions & 2 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,23 @@
version: 2
jobs:
unittest:
unit_test:
docker:
- image: circleci/golang:1.14
steps:
- checkout
- run: make test
functional_test:
docker:
- image: checkr/docker-docker-compose
steps:
- checkout
- setup_remote_docker:
version: 18.09.3
- run: make docker_functional_test

workflows:
version: 2
test:
jobs:
- unittest
- unit_test
- functional_test
2 changes: 2 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,5 @@ vendor/
go.mod
go.sum
Makefile
docker-compose.yaml
/.circleci
13 changes: 12 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,23 @@ docker_build:
docker_run:
docker-compose up --remove-orphans --force-recreate

docker_functional_test:
docker-compose down -v
docker-compose build
docker-compose up --no-start
for f in ./mocks/openmock_templates/*.yaml; do docker cp $$f dsrhub_openmock:/data/templates/; done
for f in ./sql/schema.sql; do docker cp $$f dsrhub_db:/docker-entrypoint-initdb.d/; done
for f in ./templates/*.yaml; do docker cp $$f dsrhub_utask:/app/templates/; done
for f in ./functional_test/*.yaml; do docker cp $$f dsrhub_functional_test:/var/local/; done
docker-compose up -d
docker-compose exec -w /var/local functional_test venom run --log info '*'

gen_proto:
docker run --rm \
-v $(PWD)/idl_dsrhub:/defs \
-v $(PWD)/idl_dsrhub:/go/src/github.com/dsrhub/dsrhub/idl_dsrhub \
-v $(PWD)/idl_dsrhub/dsrhub.swagger.json:/go/src/dsrhub.swagger.json \
namely/protoc-all:1.29_2 -i . -d . -l go -o /go/src --with-gateway --with-swagger-json-names
namely/protoc-all:1.29_2 -i . -d . -l go -o /go/src --with-gateway

_install_cmd_golangci_lint:
ifndef CMD_GOLANGCILINT
Expand Down
15 changes: 13 additions & 2 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
version: "3.8"
version: "2.4"
services:
utask:
build: .
container_name: dsrhub_utask
restart: on-failure
command: ["/wait-for-it.sh", "db:5432", "--", "/app/utask"]
environment:
Expand All @@ -15,20 +16,24 @@ services:
ports:
- "8081:8081"
volumes:
- "./templates:/app/templates:ro"
- "./templates:/app/templates"
depends_on:
- db

db:
image: postgres:9.5.3
container_name: dsrhub_db
restart: on-failure
environment:
POSTGRES_USER: user
POSTGRES_PASSWORD: pass
POSTGRES_DB: utask
volumes:
- "./sql:/docker-entrypoint-initdb.d"

openmock:
build: ./mocks
container_name: dsrhub_openmock
restart: on-failure
environment:
OPENMOCK_TEMPLATES_DIR: '/data/templates'
Expand All @@ -39,3 +44,9 @@ services:
ports:
- "9999:9999"
- "50051:50051"

functional_test:
image: zhouzhuojie/docker-venom
container_name: dsrhub_functional_test
entrypoint: ''
command: sh -c "tail -F /dev/null"
23 changes: 23 additions & 0 deletions functional_test/dsrhub_openmock.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: TestSuite of dsrhub's openmock
testcases:
- name: Make sure openmock is ready to serve POST /:service/dsrhub/exchange_identity
steps:
- type: http
method: POST
url: http://openmock:9999/test_email_service/dsrhub/exchange_identity
retry: 20
delay: 5
assertions:
- result.statuscode ShouldEqual 200
- result.body ShouldContainSubstring email

- name: Make sure openmock is ready to serve POST /:service_name/dsrhub/create_dsr_request
steps:
- type: http
method: POST
url: http://openmock:9999/test_email_service/dsrhub/create_dsr_request
retry: 20
delay: 5
assertions:
- result.statuscode ShouldEqual 200
- result.body ShouldContainSubstring email
46 changes: 46 additions & 0 deletions functional_test/dsrhub_utask.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: TestSuite of dsrhub's utask
testcases:
- name: getUnsecuredStats
steps:
- type: http
method: GET
url: http://utask:8081/unsecured/stats
retry: 20
delay: 5
headers:
accept: application/json
assertions:
- result.statuscode ShouldEqual 200

- name: createTask
steps:
- type: http
method: POST
url: http://utask:8081/task
retry: 10
delay: 5
headers:
Content-Type: application/json
Authorization: Basic YWRtaW46MTIzNA== # admin:1234
body: >
{
"template_name": "example-complex-dsrhub-workflow",
"input": {"email":"[email protected]"}
}
assertions:
- result.statuscode ShouldEqual 201
- result.bodyjson.state ShouldEqual TODO

- name: getTaskState
steps:
- type: http
method: GET
url: http://utask:8081/task/{{.createTask.result.bodyjson.id}}
retry: 60
delay: 2
headers:
Content-Type: application/json
Authorization: Basic YWRtaW46MTIzNA== # admin:1234
assertions:
- result.statuscode ShouldEqual 200
- result.bodyjson.state ShouldEqual DONE
75 changes: 38 additions & 37 deletions idl_dsrhub/dsrhub.pb.go

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

4 changes: 2 additions & 2 deletions idl_dsrhub/dsrhub.proto
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ option (grpc.gateway.protoc_gen_swagger.options.openapiv2_swagger) = {
message CreateDSRRequest {
option (grpc.gateway.protoc_gen_swagger.options.openapiv2_schema) = {
json_schema: {
required: ["regulation", "subjectRequestId", "subjectRequestType", "identityValue"]
required: ["regulation", "subject_request_id", "subject_request_type", "identity_value"]
}
};

Expand All @@ -50,7 +50,7 @@ message CreateDSRResponse {
message ExchangeIdentityRequest {
option (grpc.gateway.protoc_gen_swagger.options.openapiv2_schema) = {
json_schema: {
required: ["identityValue"]
required: ["identity_value"]
}
};

Expand Down
48 changes: 24 additions & 24 deletions idl_dsrhub/dsrhub.swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -90,30 +90,30 @@
"regulation": {
"type": "string"
},
"statusCallbackUrl": {
"status_callback_url": {
"type": "string"
},
"subjectRequestId": {
"subject_request_id": {
"type": "string"
},
"subjectRequestType": {
"subject_request_type": {
"type": "string"
},
"identityType": {
"identity_type": {
"type": "string"
},
"identityFormat": {
"identity_format": {
"type": "string"
},
"identityValue": {
"identity_value": {
"type": "string"
}
},
"required": [
"regulation",
"subjectRequestId",
"subjectRequestType",
"identityValue"
"subject_request_id",
"subject_request_type",
"identity_value"
]
},
"dsrhubCreateDSRResponse": {
Expand All @@ -122,64 +122,64 @@
"regulation": {
"type": "string"
},
"requestStatus": {
"request_status": {
"type": "string"
},
"subjectRequestId": {
"subject_request_id": {
"type": "string"
},
"subjectRequestType": {
"subject_request_type": {
"type": "string"
},
"identityType": {
"identity_type": {
"type": "string"
},
"identityFormat": {
"identity_format": {
"type": "string"
},
"identityValue": {
"identity_value": {
"type": "string"
},
"controllerId": {
"controller_id": {
"type": "string"
}
}
},
"dsrhubExchangeIdentityRequest": {
"type": "object",
"properties": {
"identityType": {
"identity_type": {
"type": "string"
},
"identityFormat": {
"identity_format": {
"type": "string"
},
"identityValue": {
"identity_value": {
"type": "string"
}
},
"required": [
"identityValue"
"identity_value"
]
},
"dsrhubExchangeIdentityResponse": {
"type": "object",
"properties": {
"identityType": {
"identity_type": {
"type": "string"
},
"identityFormat": {
"identity_format": {
"type": "string"
},
"identityValue": {
"identity_value": {
"type": "string"
}
}
},
"protobufAny": {
"type": "object",
"properties": {
"typeUrl": {
"type_url": {
"type": "string",
"description": "A URL/resource name that uniquely identifies the type of the serialized\nprotocol buffer message. This string must contain at least\none \"/\" character. The last segment of the URL's path must represent\nthe fully qualified name of the type (as in\n`path/google.protobuf.Duration`). The name should be in a canonical form\n(e.g., leading \".\" is not accepted).\n\nIn practice, teams usually precompile into the binary all types that they\nexpect it to use in the context of Any. However, for URLs which use the\nscheme `http`, `https`, or no scheme, one can optionally set up a type\nserver that maps type URLs to message definitions as follows:\n\n* If no scheme is provided, `https` is assumed.\n* An HTTP GET on the URL must yield a [google.protobuf.Type][]\n value in binary format, or produce an error.\n* Applications are allowed to cache lookup results based on the\n URL, or have them precompiled into a binary to avoid any\n lookup. Therefore, binary compatibility needs to be preserved\n on changes to types. (Use versioned type names to manage\n breaking changes.)\n\nNote: this functionality is not currently available in the official\nprotobuf release, and it is not used for type URLs beginning with\ntype.googleapis.com.\n\nSchemes other than `http`, `https` (or the empty scheme) might be\nused with implementation specific semantics."
},
Expand Down
Loading

0 comments on commit 4134f0e

Please sign in to comment.