suite_test.go 2.1 KB

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