framework_test.go 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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 framework
  14. import (
  15. "testing"
  16. "k8s.io/client-go/kubernetes"
  17. "k8s.io/client-go/rest"
  18. crclient "sigs.k8s.io/controller-runtime/pkg/client"
  19. crfake "sigs.k8s.io/controller-runtime/pkg/client/fake"
  20. )
  21. func TestRefreshClientsReloadsFrameworkClients(t *testing.T) {
  22. t.Helper()
  23. originalNewConfig := newFrameworkConfig
  24. t.Cleanup(func() {
  25. newFrameworkConfig = originalNewConfig
  26. })
  27. wantConfig := &rest.Config{Host: "https://refreshed.example"}
  28. wantClientset := &kubernetes.Clientset{}
  29. wantCRClient := crfake.NewClientBuilder().Build()
  30. newFrameworkConfig = func() (*rest.Config, *kubernetes.Clientset, crclient.Client) {
  31. return wantConfig, wantClientset, wantCRClient
  32. }
  33. f := &Framework{
  34. KubeConfig: &rest.Config{Host: "https://stale.example"},
  35. KubeClientSet: &kubernetes.Clientset{},
  36. CRClient: crfake.NewClientBuilder().Build(),
  37. }
  38. f.refreshClients()
  39. if f.KubeConfig != wantConfig {
  40. t.Fatalf("expected refreshed kube config")
  41. }
  42. if f.KubeClientSet != wantClientset {
  43. t.Fatalf("expected refreshed kube clientset")
  44. }
  45. if f.CRClient != wantCRClient {
  46. t.Fatalf("expected refreshed controller-runtime client")
  47. }
  48. }