generators_test.go 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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 register
  14. import (
  15. "reflect"
  16. "testing"
  17. genv1alpha1 "github.com/external-secrets/external-secrets/apis/generators/v1alpha1"
  18. awsgen "github.com/external-secrets/external-secrets/providers/v2/aws/generator"
  19. fakegen "github.com/external-secrets/external-secrets/providers/v2/fake/generator"
  20. )
  21. func TestProviderOwnedGeneratorsAreRegistered(t *testing.T) {
  22. t.Helper()
  23. testCases := []struct {
  24. kind string
  25. want any
  26. }{
  27. {
  28. kind: string(genv1alpha1.GeneratorKindECRAuthorizationToken),
  29. want: &awsgen.ECRGenerator{},
  30. },
  31. {
  32. kind: string(genv1alpha1.GeneratorKindSTSSessionToken),
  33. want: &awsgen.STSGenerator{},
  34. },
  35. {
  36. kind: string(genv1alpha1.GeneratorKindFake),
  37. want: &fakegen.Generator{},
  38. },
  39. }
  40. for _, tc := range testCases {
  41. got, ok := genv1alpha1.GetGeneratorByName(tc.kind)
  42. if !ok {
  43. t.Fatalf("generator %q not registered", tc.kind)
  44. }
  45. if tName, gName := typeName(tc.want), typeName(got); tName != gName {
  46. t.Fatalf("generator %q = %s, want %s", tc.kind, gName, tName)
  47. }
  48. }
  49. }
  50. func typeName(v any) string {
  51. return reflect.TypeOf(v).String()
  52. }