Skip to content

Commit 4134f0e

Browse files
authoredJul 14, 2020
Merge pull request #18 from dsrhub/zz/add-functional-test
Add functional test
2 parents 06cefc1 + ff6e074 commit 4134f0e

19 files changed

+281
-165
lines changed
 

‎.circleci/config.yml

+11-2
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,23 @@
11
version: 2
22
jobs:
3-
unittest:
3+
unit_test:
44
docker:
55
- image: circleci/golang:1.14
66
steps:
77
- checkout
88
- run: make test
9+
functional_test:
10+
docker:
11+
- image: checkr/docker-docker-compose
12+
steps:
13+
- checkout
14+
- setup_remote_docker:
15+
version: 18.09.3
16+
- run: make docker_functional_test
917

1018
workflows:
1119
version: 2
1220
test:
1321
jobs:
14-
- unittest
22+
- unit_test
23+
- functional_test

‎.dockerignore

+2
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,5 @@ vendor/
1717
go.mod
1818
go.sum
1919
Makefile
20+
docker-compose.yaml
21+
/.circleci

‎Makefile

+12-1
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,23 @@ docker_build:
2020
docker_run:
2121
docker-compose up --remove-orphans --force-recreate
2222

23+
docker_functional_test:
24+
docker-compose down -v
25+
docker-compose build
26+
docker-compose up --no-start
27+
for f in ./mocks/openmock_templates/*.yaml; do docker cp $$f dsrhub_openmock:/data/templates/; done
28+
for f in ./sql/schema.sql; do docker cp $$f dsrhub_db:/docker-entrypoint-initdb.d/; done
29+
for f in ./templates/*.yaml; do docker cp $$f dsrhub_utask:/app/templates/; done
30+
for f in ./functional_test/*.yaml; do docker cp $$f dsrhub_functional_test:/var/local/; done
31+
docker-compose up -d
32+
docker-compose exec -w /var/local functional_test venom run --log info '*'
33+
2334
gen_proto:
2435
docker run --rm \
2536
-v $(PWD)/idl_dsrhub:/defs \
2637
-v $(PWD)/idl_dsrhub:/go/src/github.com/dsrhub/dsrhub/idl_dsrhub \
2738
-v $(PWD)/idl_dsrhub/dsrhub.swagger.json:/go/src/dsrhub.swagger.json \
28-
namely/protoc-all:1.29_2 -i . -d . -l go -o /go/src --with-gateway --with-swagger-json-names
39+
namely/protoc-all:1.29_2 -i . -d . -l go -o /go/src --with-gateway
2940

3041
_install_cmd_golangci_lint:
3142
ifndef CMD_GOLANGCILINT

‎docker-compose.yaml

+13-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
version: "3.8"
1+
version: "2.4"
22
services:
33
utask:
44
build: .
5+
container_name: dsrhub_utask
56
restart: on-failure
67
command: ["/wait-for-it.sh", "db:5432", "--", "/app/utask"]
78
environment:
@@ -15,20 +16,24 @@ services:
1516
ports:
1617
- "8081:8081"
1718
volumes:
18-
- "./templates:/app/templates:ro"
19+
- "./templates:/app/templates"
1920
depends_on:
2021
- db
22+
2123
db:
2224
image: postgres:9.5.3
25+
container_name: dsrhub_db
2326
restart: on-failure
2427
environment:
2528
POSTGRES_USER: user
2629
POSTGRES_PASSWORD: pass
2730
POSTGRES_DB: utask
2831
volumes:
2932
- "./sql:/docker-entrypoint-initdb.d"
33+
3034
openmock:
3135
build: ./mocks
36+
container_name: dsrhub_openmock
3237
restart: on-failure
3338
environment:
3439
OPENMOCK_TEMPLATES_DIR: '/data/templates'
@@ -39,3 +44,9 @@ services:
3944
ports:
4045
- "9999:9999"
4146
- "50051:50051"
47+
48+
functional_test:
49+
image: zhouzhuojie/docker-venom
50+
container_name: dsrhub_functional_test
51+
entrypoint: ''
52+
command: sh -c "tail -F /dev/null"

‎functional_test/dsrhub_openmock.yaml

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
name: TestSuite of dsrhub's openmock
2+
testcases:
3+
- name: Make sure openmock is ready to serve POST /:service/dsrhub/exchange_identity
4+
steps:
5+
- type: http
6+
method: POST
7+
url: http://openmock:9999/test_email_service/dsrhub/exchange_identity
8+
retry: 20
9+
delay: 5
10+
assertions:
11+
- result.statuscode ShouldEqual 200
12+
- result.body ShouldContainSubstring email
13+
14+
- name: Make sure openmock is ready to serve POST /:service_name/dsrhub/create_dsr_request
15+
steps:
16+
- type: http
17+
method: POST
18+
url: http://openmock:9999/test_email_service/dsrhub/create_dsr_request
19+
retry: 20
20+
delay: 5
21+
assertions:
22+
- result.statuscode ShouldEqual 200
23+
- result.body ShouldContainSubstring email

‎functional_test/dsrhub_utask.yaml

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
name: TestSuite of dsrhub's utask
2+
testcases:
3+
- name: getUnsecuredStats
4+
steps:
5+
- type: http
6+
method: GET
7+
url: http://utask:8081/unsecured/stats
8+
retry: 20
9+
delay: 5
10+
headers:
11+
accept: application/json
12+
assertions:
13+
- result.statuscode ShouldEqual 200
14+
15+
- name: createTask
16+
steps:
17+
- type: http
18+
method: POST
19+
url: http://utask:8081/task
20+
retry: 10
21+
delay: 5
22+
headers:
23+
Content-Type: application/json
24+
Authorization: Basic YWRtaW46MTIzNA== # admin:1234
25+
body: >
26+
{
27+
"template_name": "example-complex-dsrhub-workflow",
28+
"input": {"email":"zzzz@example.com"}
29+
}
30+
assertions:
31+
- result.statuscode ShouldEqual 201
32+
- result.bodyjson.state ShouldEqual TODO
33+
34+
- name: getTaskState
35+
steps:
36+
- type: http
37+
method: GET
38+
url: http://utask:8081/task/{{.createTask.result.bodyjson.id}}
39+
retry: 60
40+
delay: 2
41+
headers:
42+
Content-Type: application/json
43+
Authorization: Basic YWRtaW46MTIzNA== # admin:1234
44+
assertions:
45+
- result.statuscode ShouldEqual 200
46+
- result.bodyjson.state ShouldEqual DONE

‎idl_dsrhub/dsrhub.pb.go

+38-37
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎idl_dsrhub/dsrhub.proto

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ option (grpc.gateway.protoc_gen_swagger.options.openapiv2_swagger) = {
2323
message CreateDSRRequest {
2424
option (grpc.gateway.protoc_gen_swagger.options.openapiv2_schema) = {
2525
json_schema: {
26-
required: ["regulation", "subjectRequestId", "subjectRequestType", "identityValue"]
26+
required: ["regulation", "subject_request_id", "subject_request_type", "identity_value"]
2727
}
2828
};
2929

@@ -50,7 +50,7 @@ message CreateDSRResponse {
5050
message ExchangeIdentityRequest {
5151
option (grpc.gateway.protoc_gen_swagger.options.openapiv2_schema) = {
5252
json_schema: {
53-
required: ["identityValue"]
53+
required: ["identity_value"]
5454
}
5555
};
5656

‎idl_dsrhub/dsrhub.swagger.json

+24-24
Original file line numberDiff line numberDiff line change
@@ -90,30 +90,30 @@
9090
"regulation": {
9191
"type": "string"
9292
},
93-
"statusCallbackUrl": {
93+
"status_callback_url": {
9494
"type": "string"
9595
},
96-
"subjectRequestId": {
96+
"subject_request_id": {
9797
"type": "string"
9898
},
99-
"subjectRequestType": {
99+
"subject_request_type": {
100100
"type": "string"
101101
},
102-
"identityType": {
102+
"identity_type": {
103103
"type": "string"
104104
},
105-
"identityFormat": {
105+
"identity_format": {
106106
"type": "string"
107107
},
108-
"identityValue": {
108+
"identity_value": {
109109
"type": "string"
110110
}
111111
},
112112
"required": [
113113
"regulation",
114-
"subjectRequestId",
115-
"subjectRequestType",
116-
"identityValue"
114+
"subject_request_id",
115+
"subject_request_type",
116+
"identity_value"
117117
]
118118
},
119119
"dsrhubCreateDSRResponse": {
@@ -122,64 +122,64 @@
122122
"regulation": {
123123
"type": "string"
124124
},
125-
"requestStatus": {
125+
"request_status": {
126126
"type": "string"
127127
},
128-
"subjectRequestId": {
128+
"subject_request_id": {
129129
"type": "string"
130130
},
131-
"subjectRequestType": {
131+
"subject_request_type": {
132132
"type": "string"
133133
},
134-
"identityType": {
134+
"identity_type": {
135135
"type": "string"
136136
},
137-
"identityFormat": {
137+
"identity_format": {
138138
"type": "string"
139139
},
140-
"identityValue": {
140+
"identity_value": {
141141
"type": "string"
142142
},
143-
"controllerId": {
143+
"controller_id": {
144144
"type": "string"
145145
}
146146
}
147147
},
148148
"dsrhubExchangeIdentityRequest": {
149149
"type": "object",
150150
"properties": {
151-
"identityType": {
151+
"identity_type": {
152152
"type": "string"
153153
},
154-
"identityFormat": {
154+
"identity_format": {
155155
"type": "string"
156156
},
157-
"identityValue": {
157+
"identity_value": {
158158
"type": "string"
159159
}
160160
},
161161
"required": [
162-
"identityValue"
162+
"identity_value"
163163
]
164164
},
165165
"dsrhubExchangeIdentityResponse": {
166166
"type": "object",
167167
"properties": {
168-
"identityType": {
168+
"identity_type": {
169169
"type": "string"
170170
},
171-
"identityFormat": {
171+
"identity_format": {
172172
"type": "string"
173173
},
174-
"identityValue": {
174+
"identity_value": {
175175
"type": "string"
176176
}
177177
}
178178
},
179179
"protobufAny": {
180180
"type": "object",
181181
"properties": {
182-
"typeUrl": {
182+
"type_url": {
183183
"type": "string",
184184
"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."
185185
},

0 commit comments

Comments
 (0)
Please sign in to comment.