common_test.go 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. /*
  2. Licensed under the Apache License, Version 2.0 (the "License");
  3. you may not use this file except in compliance with the License.
  4. You may obtain a copy of the License at
  5. http://www.apache.org/licenses/LICENSE-2.0
  6. Unless required by applicable law or agreed to in writing, software
  7. distributed under the License is distributed on an "AS IS" BASIS,
  8. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  9. See the License for the specific language governing permissions and
  10. limitations under the License.
  11. */
  12. package crds
  13. // import (
  14. // "context"
  15. // "time"
  16. // . "github.com/onsi/ginkgo/v2"
  17. // . "github.com/onsi/gomega"
  18. // corev1 "k8s.io/api/core/v1"
  19. // apiextensions "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
  20. // metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
  21. // "k8s.io/apimachinery/pkg/types"
  22. // esapi "github.com/external-secrets/external-secrets/apis/externalsecrets/v1beta1"
  23. // )
  24. // type testCase struct {
  25. // crd apiextensions.CustomResourceDefinition
  26. // assert func()
  27. // }
  28. // var _ = Describe("CRD reconcile", func() {
  29. // var test *testCase
  30. // BeforeEach(func() {
  31. // test = makeDefaultTestcase()
  32. // })
  33. // AfterEach(func() {
  34. // Expect(k8sClient.Delete(context.Background(), &test.crd)).ToNot(HaveOccurred())
  35. // })
  36. // // a invalid provider config should be reflected
  37. // // in the store status condition
  38. // PatchesCRD := func(tc *testCase) {
  39. // tc.assert = func() {
  40. // Eventually(func() bool {
  41. // ss := apiextensions.CustomResourceDefinition{}
  42. // err := k8sClient.Get(context.Background(), types.NamespacedName{
  43. // Name: "secrestores.external-secrets.io",
  44. // }, &ss)
  45. // if err != nil {
  46. // return false
  47. // }
  48. // return ss.Spec.Conversion.Strategy == "Webhook"
  49. // }).
  50. // WithTimeout(time.Second * 10).
  51. // WithPolling(time.Second).
  52. // Should(BeTrue())
  53. // }
  54. // }
  55. // // if controllerClass does not match the controller
  56. // // should not touch this store
  57. // ignoreNonTargetCRDs := func(tc *testCase) {
  58. // tc.assert = func() {
  59. // Consistently(func() bool {
  60. // ss := apiextensions.CustomResourceDefinition{}
  61. // err := k8sClient.Get(context.Background(), types.NamespacedName{
  62. // Name: defaultStoreName,
  63. // }, &ss)
  64. // if err != nil {
  65. // return false
  66. // }
  67. // return ss.Spec.Conversion == tc.crd.Spec.Conversion
  68. // }).
  69. // WithTimeout(time.Second * 3).
  70. // WithPolling(time.Millisecond * 500).
  71. // Should(BeTrue())
  72. // }
  73. // }
  74. // DescribeTable("Controller Reconcile logic", func(muts ...func(tc *testCase)) {
  75. // for _, mut := range muts {
  76. // mut(test)
  77. // }
  78. // err := k8sClient.Create(context.Background(), test.store.Copy())
  79. // Expect(err).ToNot(HaveOccurred())
  80. // test.assert()
  81. // },
  82. // // namespaced store
  83. // Entry("[namespace] invalid provider with secretStore should set InvalidStore condition", invalidProvider),
  84. // Entry("[namespace] ignore stores with non-matching class", ignoreControllerClass),
  85. // Entry("[namespace] valid provider has status=ready", validProvider),
  86. // // cluster store
  87. // Entry("[cluster] invalid provider with secretStore should set InvalidStore condition", invalidProvider, useClusterStore),
  88. // Entry("[cluster] ignore stores with non-matching class", ignoreControllerClass, useClusterStore),
  89. // Entry("[cluster] valid provider has status=ready", validProvider, useClusterStore),
  90. // )
  91. // })
  92. // const (
  93. // defaultStoreName = "default-store"
  94. // defaultControllerClass = "test-ctrl"
  95. // )
  96. // func makeDefaultTestcase() *testCase {
  97. // return &testCase{
  98. // assert: func() {
  99. // // this is a noop by default
  100. // },
  101. // crd: &apiextensions.CustomResourceDefinition{
  102. // TypeMeta: metav1.TypeMeta{
  103. // Kind: esapi.SecretStoreKind,
  104. // APIVersion: esapi.SecretStoreKindAPIVersion,
  105. // },
  106. // ObjectMeta: metav1.ObjectMeta{
  107. // Name: defaultStoreName,
  108. // Namespace: "default",
  109. // },
  110. // Spec: esapi.SecretStoreSpec{
  111. // Controller: defaultControllerClass,
  112. // // empty provider
  113. // // a testCase mutator must fill in the concrete provider
  114. // Provider: &esapi.SecretStoreProvider{
  115. // Vault: &esapi.VaultProvider{
  116. // Version: esapi.VaultKVStoreV1,
  117. // },
  118. // },
  119. // },
  120. // },
  121. // }
  122. // }
  123. // func hasEvent(involvedKind, name, reason string) bool {
  124. // el := &corev1.EventList{}
  125. // err := k8sClient.List(context.Background(), el)
  126. // if err != nil {
  127. // return false
  128. // }
  129. // for i := range el.Items {
  130. // ev := el.Items[i]
  131. // if ev.InvolvedObject.Kind == involvedKind && ev.InvolvedObject.Name == name {
  132. // if ev.Reason == reason {
  133. // return true
  134. // }
  135. // }
  136. // }
  137. // return false
  138. // }