validate_test.go 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /*
  2. Copyright © The ESO Authors
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. https://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. */
  13. package ovh
  14. import (
  15. "errors"
  16. "testing"
  17. kclient "sigs.k8s.io/controller-runtime/pkg/client"
  18. "github.com/external-secrets/external-secrets/providers/v1/ovh/fake"
  19. )
  20. func TestValidate(t *testing.T) {
  21. testCases := map[string]struct {
  22. kube kclient.Client
  23. okmsClient fake.FakeOkmsClient
  24. errshould string
  25. }{
  26. "Error case": {
  27. errshould: "failed to validate secret store: custom error",
  28. okmsClient: fake.FakeOkmsClient{
  29. ListSecretV2Fn: fake.NewListSecretV2Fn(errors.New("custom error")),
  30. },
  31. },
  32. "Valid case": {
  33. errshould: "",
  34. },
  35. }
  36. for name, testCase := range testCases {
  37. t.Run(name, func(t *testing.T) {
  38. cl := ovhClient{
  39. kube: testCase.kube,
  40. okmsClient: testCase.okmsClient,
  41. }
  42. _, err := cl.Validate()
  43. if testCase.errshould != "" {
  44. if err != nil && testCase.errshould != err.Error() {
  45. t.Errorf("\nexpected error: %s\nactual error: %v\n\n", testCase.errshould, err)
  46. }
  47. if err == nil {
  48. t.Errorf("\nexpected error: %s\nactual error: <nil>\n\n", testCase.errshould)
  49. }
  50. } else if err != nil {
  51. t.Errorf("\nunexpected error: %v\n\n", err)
  52. }
  53. })
  54. }
  55. }