-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add testutils to DRY up provider tests
- Loading branch information
1 parent
edb41de
commit c776af8
Showing
5 changed files
with
142 additions
and
161 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package testutils | ||
|
||
import ( | ||
. "github.com/smartystreets/goconvey/convey" | ||
|
||
plugin_v1 "github.com/cyberark/secretless-broker/internal/plugin/v1" | ||
) | ||
|
||
// CanProvideTestCase captures a test case where a provider is expected to return a value | ||
// and no error | ||
type CanProvideTestCase struct { | ||
Description string | ||
ID string | ||
ExpectedValue string | ||
} | ||
|
||
// CanProvide calls GetValues on the provider and ensures that the provider response for | ||
// the given id has the expected value and no error | ||
func CanProvide(provider plugin_v1.Provider, id string, expectedValue string) func() { | ||
return func() { | ||
values, err := provider.GetValues(id) | ||
|
||
So(err, ShouldBeNil) | ||
So(values[id], ShouldNotBeNil) | ||
So(values[id].Error, ShouldBeNil) | ||
So(values[id].Value, ShouldNotBeNil) | ||
So(string(values[id].Value), ShouldEqual, expectedValue) | ||
} | ||
} | ||
|
||
// ReportsTestCase captures a test case where a provider is expected to return an error | ||
type ReportsTestCase struct { | ||
Description string | ||
ID string | ||
ExpectedErrString string | ||
} | ||
|
||
// Reports calls GetValues on the provider and ensures that the provider response for the | ||
// given id has the expected error and no value | ||
func Reports(provider plugin_v1.Provider, id string, expectedErrString string) func() { | ||
return func() { | ||
values, err := provider.GetValues(id) | ||
|
||
So(err, ShouldBeNil) | ||
So(values, ShouldContainKey, id) | ||
So(values[id].Value, ShouldBeNil) | ||
So(values[id].Error, ShouldNotBeNil) | ||
So(values[id].Error.Error(), ShouldEqual, expectedErrString) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.