Skip to content

Commit

Permalink
add test for subresource paths findMatchingResourceRootPath
Browse files Browse the repository at this point in the history
- makes sure the root path is calculated property given a subresource instance path
  • Loading branch information
dikhan committed Oct 30, 2019
1 parent 944abca commit dbdd80f
Showing 1 changed file with 125 additions and 0 deletions.
125 changes: 125 additions & 0 deletions openapi/openapi_v2_spec_analyser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1380,6 +1380,131 @@ definitions:
})
})
})

Convey("Given an apiSpecAnalyser with a valid resource path that is sub-resource", t, func() {
swaggerContent := `swagger: "2.0"
schemes:
- "http"
paths:
######################
#### CDN Resource ####
######################
/v1/cdns:
post:
x-terraform-resource-name: "cdn"
summary: "Create cdn"
operationId: "ContentDeliveryNetworkCreateV1"
parameters:
- in: "body"
name: "body"
description: "Created CDN"
required: true
schema:
$ref: "#/definitions/ContentDeliveryNetworkV1"
responses:
201:
description: "successful operation"
schema:
$ref: "#/definitions/ContentDeliveryNetworkV1"
/v1/cdns/{cdn_id}:
get:
summary: "Get cdn by id"
description: ""
operationId: "ContentDeliveryNetworkGetV1"
parameters:
- name: "cdn_id"
in: "path"
description: "The cdn id that needs to be fetched."
required: true
type: "string"
responses:
200:
description: "successful operation"
schema:
$ref: "#/definitions/ContentDeliveryNetworkV1"
######################
## CDN sub-resource
######################
/v1/cdns/{cdn_id}/v1/firewalls:
post:
summary: "Create cdn firewall"
operationId: "ContentDeliveryNetworkFirewallCreateV1"
parameters:
- name: "cdn_id"
in: "path"
description: "The cdn id that contains the firewall to be fetched."
required: true
type: "string"
- in: "body"
name: "body"
description: "Created CDN firewall"
required: true
schema:
$ref: "#/definitions/ContentDeliveryNetworkFirewallV1"
responses:
201:
description: "successful operation"
schema:
$ref: "#/definitions/ContentDeliveryNetworkFirewallV1"
/v1/cdns/{cdn_id}/v1/firewalls/{id}:
get:
summary: "Get cdn firewall by id"
description: ""
operationId: "ContentDeliveryNetworkFirewallGetV1"
parameters:
- name: "cdn_id"
in: "path"
description: "The cdn id that contains the firewall to be fetched."
required: true
type: "string"
- name: "id"
in: "path"
description: "The cdn firewall id that needs to be fetched."
required: true
type: "string"
responses:
200:
description: "successful operation"
schema:
$ref: "#/definitions/ContentDeliveryNetworkFirewallV1"
definitions:
ContentDeliveryNetworkFirewallV1:
type: "object"
properties:
id:
type: "string"
readOnly: true
label:
type: "string"
ContentDeliveryNetworkV1:
type: "object"
required:
- label
properties:
id:
type: "string"
readOnly: true
label:
type: "string"`
a := initAPISpecAnalyser(swaggerContent)
Convey("When findMatchingResourceRootPath method is called with subresource instance path '/v1/cdns/{cdn_id}/v1/firewalls/{id}'", func() {
resourceRootPath, err := a.findMatchingResourceRootPath("/v1/cdns/{cdn_id}/v1/firewalls/{id}")
Convey("Then the error returned should be nil", func() {
So(err, ShouldBeNil)
})
Convey("And the value returned should be '/v1/cdns/{cdn_id}/v1/firewalls/{id}'", func() {
So(resourceRootPath, ShouldEqual, "/v1/cdns/{cdn_id}/v1/firewalls")
})
})
})

}

func TestPostIsPresent(t *testing.T) {
Expand Down

0 comments on commit dbdd80f

Please sign in to comment.