Skip to content

Commit

Permalink
Remove erorr return from isResourceInstanceEndPoint signature
Browse files Browse the repository at this point in the history
- The function was never returning any error and therefore consumers of the method
would check for an error for no reason.
  • Loading branch information
dikhan committed Jul 13, 2021
1 parent a39b4c1 commit c4f84e5
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 18 deletions.
9 changes: 3 additions & 6 deletions openapi/openapi_v2_spec_analyser.go
Original file line number Diff line number Diff line change
Expand Up @@ -317,10 +317,7 @@ func (specAnalyser *specV2Analyser) isEndPointTerraformDataSourceCompliant(path
}

func (specAnalyser *specV2Analyser) validateInstancePath(path string) error {
isResourceInstance, err := specAnalyser.isResourceInstanceEndPoint(path)
if err != nil {
return fmt.Errorf("error occurred while checking if path '%s' is a resource instance path", path)
}
isResourceInstance := specAnalyser.isResourceInstanceEndPoint(path)
if !isResourceInstance {
return fmt.Errorf("path '%s' is not a resource instance path", path)
}
Expand Down Expand Up @@ -567,9 +564,9 @@ func (specAnalyser *specV2Analyser) getBodyParameterBodySchema(resourceRootPostO
}

// isResourceInstanceEndPoint checks if the given path is of form /resource/{id}
func (specAnalyser *specV2Analyser) isResourceInstanceEndPoint(p string) (bool, error) {
func (specAnalyser *specV2Analyser) isResourceInstanceEndPoint(p string) bool {
r, _ := regexp.Compile("^.*{.+}[\\/]?$")
return r.MatchString(p), nil
return r.MatchString(p)
}

// findMatchingResourceRootPath returns the corresponding POST root and path for a given end point
Expand Down
18 changes: 6 additions & 12 deletions openapi/openapi_v2_spec_analyser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2036,44 +2036,38 @@ func TestResourceInstanceEndPoint(t *testing.T) {
Convey("Given an specV2Analyser", t, func() {
a := specV2Analyser{}
Convey("When isResourceInstanceEndPoint method is called with a valid resource path such as '/resource/{id}'", func() {
resourceInstance, err := a.isResourceInstanceEndPoint("/resource/{id}")
resourceInstance := a.isResourceInstanceEndPoint("/resource/{id}")
Convey("And the value returned should be true", func() {
So(err, ShouldBeNil)
So(resourceInstance, ShouldBeTrue)
})
})
Convey("When isResourceInstanceEndPoint method is called with a long path such as '/very/long/path/{id}'", func() {
resourceInstance, err := a.isResourceInstanceEndPoint("/very/long/path/{id}")
resourceInstance := a.isResourceInstanceEndPoint("/very/long/path/{id}")
Convey("And the value returned should be true", func() {
So(err, ShouldBeNil)
So(resourceInstance, ShouldBeTrue)
})
})
Convey("When isResourceInstanceEndPoint method is called with a path that has path parameters '/resource/{name}/subresource/{id}'", func() {
resourceInstance, err := a.isResourceInstanceEndPoint("/resource/{name}/subresource/{id}")
resourceInstance := a.isResourceInstanceEndPoint("/resource/{name}/subresource/{id}")
Convey("And the value returned should be true", func() {
So(err, ShouldBeNil)
So(resourceInstance, ShouldBeTrue)
})
})
Convey("When isResourceInstanceEndPoint method is called with a path that has path parameters and ends with trailing slash '/resource/{name}/subresource/{id}/'", func() {
resourceInstance, err := a.isResourceInstanceEndPoint("/resource/{name}/subresource/{id}/")
resourceInstance := a.isResourceInstanceEndPoint("/resource/{name}/subresource/{id}/")
Convey("And the value returned should be true", func() {
So(err, ShouldBeNil)
So(resourceInstance, ShouldBeTrue)
})
})
Convey("When isResourceInstanceEndPoint method is called with a path that is a root path of a subresource '/resource/{name}/subresource'", func() {
resourceInstance, err := a.isResourceInstanceEndPoint("/resource/{name}/subresource")
resourceInstance := a.isResourceInstanceEndPoint("/resource/{name}/subresource")
Convey("And the value returned should be false since it's the sub-resource root endpoint", func() {
So(err, ShouldBeNil)
So(resourceInstance, ShouldBeFalse)
})
})
Convey("When isResourceInstanceEndPoint method is called with an invalid resource path such as '/resource/not/instance/path' not conforming with the expected pattern '/resource/{id}'", func() {
resourceInstance, err := a.isResourceInstanceEndPoint("/resource/not/valid/instance/path")
resourceInstance := a.isResourceInstanceEndPoint("/resource/not/valid/instance/path")
Convey("And the value returned should be false", func() {
So(err, ShouldBeNil)
So(resourceInstance, ShouldBeFalse)
})
})
Expand Down

0 comments on commit c4f84e5

Please sign in to comment.