From 8e4d21715183dc1a8d8994e1595a391a7fedd1fe Mon Sep 17 00:00:00 2001 From: Jordan Olshevski Date: Fri, 17 Nov 2023 13:33:45 -0600 Subject: [PATCH] Refactor --- internal/testutil/testutil.go | 51 ++++++++++++++++++----------------- 1 file changed, 27 insertions(+), 24 deletions(-) diff --git a/internal/testutil/testutil.go b/internal/testutil/testutil.go index 0261bdcb..40d45783 100644 --- a/internal/testutil/testutil.go +++ b/internal/testutil/testutil.go @@ -94,34 +94,37 @@ func NewManager(t *testing.T) *Manager { DownstreamRestConfig: cfg, // possible override below } - if dir := os.Getenv("DOWNSTREAM_KUBEBUILDER_ASSETS"); dir != "" { - downstreamEnv := &envtest.Environment{ - BinaryAssetsDirectory: dir, - } + dir := os.Getenv("DOWNSTREAM_KUBEBUILDER_ASSETS") + if dir == "" { + return m // only one env needed + } - // k8s <1.13 will not start if these flags are set - version, _ := strconv.Atoi(os.Getenv("DOWNSTREAM_VERSION_MINOR")) - if version < 13 { - conf := downstreamEnv.ControlPlane.GetAPIServer().Configure() - conf.Disable("service-account-signing-key-file") - conf.Disable("service-account-issuer") - } + downstreamEnv := &envtest.Environment{ + BinaryAssetsDirectory: dir, + } - t.Cleanup(func() { - err := downstreamEnv.Stop() - if err != nil { - panic(err) - } - }) - m.DownstreamRestConfig, err = downstreamEnv.Start() - require.NoError(t, err) + // k8s <1.13 will not start if these flags are set + version, _ := strconv.Atoi(os.Getenv("DOWNSTREAM_VERSION_MINOR")) + if version < 13 { + conf := downstreamEnv.ControlPlane.GetAPIServer().Configure() + conf.Disable("service-account-signing-key-file") + conf.Disable("service-account-issuer") + } - disc, err := discovery.NewDiscoveryClientForConfig(m.DownstreamRestConfig) + t.Cleanup(func() { + err := downstreamEnv.Stop() + if err != nil { + panic(err) + } + }) + m.DownstreamRestConfig, err = downstreamEnv.Start() + require.NoError(t, err) + + disc, err := discovery.NewDiscoveryClientForConfig(m.DownstreamRestConfig) + if err == nil { + version, err := disc.ServerVersion() if err == nil { - version, err := disc.ServerVersion() - if err == nil { - t.Logf("downstream control plane version: %s", version.String()) - } + t.Logf("downstream control plane version: %s", version.String()) } }