From 49816eb1720cdb42b4fcb6fe2cfb05541d91509a Mon Sep 17 00:00:00 2001 From: Tanvir Tatla Date: Thu, 4 Jan 2024 08:12:45 +0000 Subject: [PATCH] Fix eksa installer unit test with real manifest (#7055) * Fix eksa installer unit test with real manifest * fix no timeout test as well --- pkg/clustermanager/eksa_installer_test.go | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/pkg/clustermanager/eksa_installer_test.go b/pkg/clustermanager/eksa_installer_test.go index 800f4466e08c..eef5af2abcf9 100644 --- a/pkg/clustermanager/eksa_installer_test.go +++ b/pkg/clustermanager/eksa_installer_test.go @@ -2,6 +2,8 @@ package clustermanager_test import ( "context" + "os" + "strings" "testing" "github.com/go-logr/logr" @@ -69,8 +71,14 @@ func newInstallerTest(t *testing.T, opts ...clustermanager.EKSAInstallerOpt) *in func TestEKSAInstallerInstallSuccessWithRealManifest(t *testing.T) { tt := newInstallerTest(t) tt.newSpec.VersionsBundles["1.19"].Eksa.Components.URI = "../../config/manifest/eksa-components.yaml" + file, err := os.ReadFile("../../config/manifest/eksa-components.yaml") + if err != nil { + t.Fatalf("could not read eksa-components") + } + manifest := string(file) + expectedObjectCount := strings.Count(manifest, "---") tt.client.EXPECT().Apply(tt.ctx, tt.cluster.KubeconfigFile, gomock.AssignableToTypeOf(&appsv1.Deployment{})) - tt.client.EXPECT().Apply(tt.ctx, tt.cluster.KubeconfigFile, gomock.Any()).Times(37) // there are 37 objects in the manifest + tt.client.EXPECT().Apply(tt.ctx, tt.cluster.KubeconfigFile, gomock.Any()).Times(expectedObjectCount) tt.client.EXPECT().WaitForDeployment(tt.ctx, tt.cluster, "30m0s", "Available", "eksa-controller-manager", "eksa-system") tt.Expect(tt.installer.Install(tt.ctx, test.NewNullLogger(), tt.cluster, tt.newSpec)).To(Succeed()) @@ -146,7 +154,13 @@ func TestEKSAInstallerInstallSuccessWithNoTimeout(t *testing.T) { tt := newInstallerTest(t, clustermanager.WithEKSAInstallerNoTimeouts()) tt.newSpec.VersionsBundles["1.19"].Eksa.Components.URI = "../../config/manifest/eksa-components.yaml" tt.client.EXPECT().Apply(tt.ctx, tt.cluster.KubeconfigFile, gomock.AssignableToTypeOf(&appsv1.Deployment{})) - tt.client.EXPECT().Apply(tt.ctx, tt.cluster.KubeconfigFile, gomock.Any()).Times(37) // there are 37 objects in the manifest + file, err := os.ReadFile("../../config/manifest/eksa-components.yaml") + if err != nil { + t.Fatalf("could not read eksa-components") + } + manifest := string(file) + expectedObjectCount := strings.Count(manifest, "---") + tt.client.EXPECT().Apply(tt.ctx, tt.cluster.KubeconfigFile, gomock.Any()).Times(expectedObjectCount) tt.client.EXPECT().WaitForDeployment(tt.ctx, tt.cluster, maxTime.String(), "Available", "eksa-controller-manager", "eksa-system") tt.Expect(tt.installer.Install(tt.ctx, test.NewNullLogger(), tt.cluster, tt.newSpec)).To(Succeed())