Skip to content

Commit

Permalink
Add property based testing to provision API using schemathesis
Browse files Browse the repository at this point in the history
Signed-off-by: Rodney Osodo <[email protected]>
  • Loading branch information
rodneyosodo committed Dec 15, 2023
1 parent 774fbca commit 759c9c6
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 28 deletions.
11 changes: 11 additions & 0 deletions .github/workflows/api-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ env:
BOOTSTRAP_URL: http://localhost:9013
CERTS_URL: http://localhost:9019
TWINS_URL: http://localhost:9018
PROVISION_URL: http://localhost:9016

jobs:
api-test:
Expand Down Expand Up @@ -210,6 +211,16 @@ jobs:
report: false
args: '--header "Authorization: Bearer ${{ env.USER_TOKEN }}" --contrib-unique-data --contrib-openapi-formats-uuid --hypothesis-suppress-health-check=filter_too_much --stateful=links'

- name: Run Provision API tests
if: steps.changes.outputs.provision == 'true'
uses: schemathesis/action@v1
with:
schema: api/openapi/provision.yml
base-url: ${{ env.PROVISION_URL }}
checks: all
report: false
args: '--header "Authorization: Bearer ${{ env.USER_TOKEN }}" --contrib-unique-data --contrib-openapi-formats-uuid --hypothesis-suppress-health-check=filter_too_much --stateful=links'

- name: Stop containers
if: always()
run: make run down args="-v"
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ test_api_auth: TEST_API_URL := http://localhost:8189
test_api_bootstrap: TEST_API_URL := http://localhost:9013
test_api_certs: TEST_API_URL := http://localhost:9019
test_api_twins: TEST_API_URL := http://localhost:9018
test_api_provision: TEST_API_URL := http://localhost:9016

$(TEST_API):
$(call test_api_service,$(@),$(TEST_API_URL))
Expand Down
28 changes: 18 additions & 10 deletions api/openapi/provision.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,17 @@ paths:
requestBody:
$ref: "#/components/requestBodies/ProvisionReq"
responses:
'201':
"201":
description: Created
'400':
"400":
description: Failed due to malformed JSON.
"401":
description: Missing or invalid access token provided.
'500':
"415":
description: Missing or invalid content type.
"422":
description: Database can't process request.
"500":
$ref: "#/components/responses/ServiceError"
get:
summary: Gets current mapping.
Expand All @@ -52,21 +56,25 @@ paths:
tags:
- provision
responses:
'200':
"200":
$ref: "#/components/responses/ProvisionRes"
"401":
description: Missing or invalid access token provided.
'500':
"415":
description: Missing or invalid content type.
"422":
description: Database can't process request.
"500":
$ref: "#/components/responses/ServiceError"
/health:
get:
summary: Retrieves service health check info.
tags:
- health
responses:
'200':
"200":
$ref: "#/components/responses/HealthRes"
'500':
"500":
$ref: "#/components/responses/ServiceError"

components:
Expand All @@ -84,9 +92,9 @@ components:
external_id:
type: string
external_key:
type: string
type: string
name:
type: string
type: string

responses:
ServiceError:
Expand All @@ -100,7 +108,7 @@ components:
HealthRes:
description: Service Health Check.
content:
application/json:
application/health+json:
schema:
$ref: "./schemas/HealthInfo.yml"

Expand Down
32 changes: 14 additions & 18 deletions cmd/provision/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,25 +136,21 @@ func loadConfig() (provision.Config, error) {
}
}

cfg = provision.Config{
Bootstrap: provision.Bootstrap{
Content: content,
cfg.Bootstrap.Content = content
// This is default conf for provision if there is no config file
cfg.Channels = []mggroups.Group{
{
Name: "control-channel",
Metadata: map[string]interface{}{"type": "control"},
}, {
Name: "data-channel",
Metadata: map[string]interface{}{"type": "data"},
},
// This is default conf for provision if there is no config file
Channels: []mggroups.Group{
{
Name: "control-channel",
Metadata: map[string]interface{}{"type": "control"},
}, {
Name: "data-channel",
Metadata: map[string]interface{}{"type": "data"},
},
},
Things: []mgclients.Client{
{
Name: "thing",
Metadata: map[string]interface{}{"external_id": "xxxxxx"},
},
}
cfg.Things = []mgclients.Client{
{
Name: "thing",
Metadata: map[string]interface{}{"external_id": "xxxxxx"},
},
}

Expand Down

0 comments on commit 759c9c6

Please sign in to comment.