Skip to content

Commit

Permalink
add test covering parent path containing more than just the version a…
Browse files Browse the repository at this point in the history
…nd the resource name
  • Loading branch information
dikhan committed Jul 24, 2019
1 parent 4903237 commit dbd80d2
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions openapi/openapi_v2_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -592,6 +592,48 @@ func TestParentResourceInfo(t *testing.T) {
})
})

Convey("Given a SpecV2Resource configured with a base path and the 2 level parent starts with some base path too and it's not versionied", t, func() {
r := SpecV2Resource{
Path: "/api/v1/cdns/{id}/something/firewalls/{id}/v3/rules",
Paths: map[string]spec.PathItem{
"/api/v1/cdns": {
PathItemProps: spec.PathItemProps{
Post: &spec.Operation{},
},
},
"/api/v1/cdns/{id}/something/firewalls": {
PathItemProps: spec.PathItemProps{
Post: &spec.Operation{},
},
},
},
}
Convey("When parentResourceInfo is called", func() {
parentResourceInfo := r.getParentResourceInfo()
Convey("Then the the parentResourceInfo struct returned shouldn't be nil", func() {
So(parentResourceInfo, ShouldNotBeNil)
})
Convey("And the parentResourceNames should not be empty and contain the right items", func() {
So(len(parentResourceInfo.parentResourceNames), ShouldEqual, 2)
So(parentResourceInfo.parentResourceNames[0], ShouldEqual, "cdns_v1")
So(parentResourceInfo.parentResourceNames[1], ShouldEqual, "firewalls")
})
Convey("And the fullParentResourceName should match the expected name", func() {
So(parentResourceInfo.fullParentResourceName, ShouldEqual, "cdns_v1_firewalls")
})
Convey("And the parentURIs contain the expected parent URIs", func() {
So(len(parentResourceInfo.parentURIs), ShouldEqual, 2)
So(parentResourceInfo.parentURIs[0], ShouldEqual, "/api/v1/cdns")
So(parentResourceInfo.parentURIs[1], ShouldEqual, "/api/v1/cdns/{id}/something/firewalls")
})
Convey("And the parentInstanceURIs contain the expected instances URIs", func() {
So(len(parentResourceInfo.parentInstanceURIs), ShouldEqual, 2)
So(parentResourceInfo.parentInstanceURIs[0], ShouldEqual, "/api/v1/cdns/{id}")
So(parentResourceInfo.parentInstanceURIs[1], ShouldEqual, "/api/v1/cdns/{id}/something/firewalls/{id}")
})
})
})

Convey("Given a SpecV2Resource configured with a path that is indeed a sub-resource (no versioning)", t, func() {
r := SpecV2Resource{
Path: "/cdns/{id}/firewalls",
Expand Down

0 comments on commit dbd80d2

Please sign in to comment.