suite_test.go 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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 controllers
  13. import (
  14. "path/filepath"
  15. "testing"
  16. . "github.com/onsi/ginkgo"
  17. . "github.com/onsi/gomega"
  18. "k8s.io/client-go/kubernetes/scheme"
  19. "k8s.io/client-go/rest"
  20. "sigs.k8s.io/controller-runtime/pkg/client"
  21. "sigs.k8s.io/controller-runtime/pkg/envtest"
  22. "sigs.k8s.io/controller-runtime/pkg/envtest/printer"
  23. logf "sigs.k8s.io/controller-runtime/pkg/log"
  24. "sigs.k8s.io/controller-runtime/pkg/log/zap"
  25. externalsecretsv1alpha1 "github.com/external-secrets/external-secrets/api/v1alpha1"
  26. // +kubebuilder:scaffold:imports
  27. )
  28. // These tests use Ginkgo (BDD-style Go testing framework). Refer to
  29. // http://onsi.github.io/ginkgo/ to learn more about Ginkgo.
  30. var cfg *rest.Config
  31. var k8sClient client.Client
  32. var testEnv *envtest.Environment
  33. func TestAPIs(t *testing.T) {
  34. RegisterFailHandler(Fail)
  35. RunSpecsWithDefaultAndCustomReporters(t,
  36. "Controller Suite",
  37. []Reporter{printer.NewlineReporter{}})
  38. }
  39. var _ = BeforeSuite(func(done Done) {
  40. logf.SetLogger(zap.LoggerTo(GinkgoWriter, true))
  41. By("bootstrapping test environment")
  42. testEnv = &envtest.Environment{
  43. CRDDirectoryPaths: []string{filepath.Join("..", "config", "crd", "bases")},
  44. }
  45. var err error
  46. cfg, err = testEnv.Start()
  47. Expect(err).ToNot(HaveOccurred())
  48. Expect(cfg).ToNot(BeNil())
  49. err = externalsecretsv1alpha1.AddToScheme(scheme.Scheme)
  50. Expect(err).NotTo(HaveOccurred())
  51. err = externalsecretsv1alpha1.AddToScheme(scheme.Scheme)
  52. Expect(err).NotTo(HaveOccurred())
  53. // +kubebuilder:scaffold:scheme
  54. k8sClient, err = client.New(cfg, client.Options{Scheme: scheme.Scheme})
  55. Expect(err).ToNot(HaveOccurred())
  56. Expect(k8sClient).ToNot(BeNil())
  57. close(done)
  58. }, 60)
  59. var _ = AfterSuite(func() {
  60. By("tearing down the test environment")
  61. err := testEnv.Stop()
  62. Expect(err).ToNot(HaveOccurred())
  63. })