From b4d56f12e7fbfe436db3715c58cdaeb719f08ddf Mon Sep 17 00:00:00 2001 From: Carlos Eduardo Arango Gutierrez Date: Wed, 24 Apr 2024 15:38:14 +0200 Subject: [PATCH] E2E test: instanciate a logger for helm outputs Signed-off-by: Carlos Eduardo Arango Gutierrez --- tests/e2e/framework/framework.go | 47 ++++++-------------------------- 1 file changed, 9 insertions(+), 38 deletions(-) diff --git a/tests/e2e/framework/framework.go b/tests/e2e/framework/framework.go index 9bab2db18..b0494b24b 100644 --- a/tests/e2e/framework/framework.go +++ b/tests/e2e/framework/framework.go @@ -24,10 +24,9 @@ package framework import ( "context" "fmt" + "log" "math/rand" "os" - "path/filepath" - "strings" "time" helm "github.com/mittwald/go-helm-client" @@ -72,7 +71,11 @@ type Framework struct { clientConfig *rest.Config ClientSet clientset.Interface - HelmClient helm.Client + + // Helm + HelmClient helm.Client + HelmLogFile *os.File + HelmLogger *log.Logger // configuration for framework's client Options Options @@ -107,27 +110,6 @@ func (f *Framework) ClientConfig() *rest.Config { return ret } -// helmDebugLog prints the debug log of the helm client into a file in the test directory. -func (f *Framework) helmDebugLog(format string, v ...interface{}) { - // check if directory for logs exists and create it if not - if _, err := os.Stat(filepath.Dir(TestContext.HelmLogFile)); os.IsNotExist(err) { - err := os.MkdirAll(filepath.Dir(TestContext.HelmLogFile), 0755) - gomega.Expect(err).NotTo(gomega.HaveOccurred()) - } - - outFile, err := os.OpenFile(TestContext.HelmLogFile, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644) - gomega.Expect(err).NotTo(gomega.HaveOccurred()) - - defer outFile.Close() - - // if formart doesn't end with newline, add it - if !strings.HasSuffix(format, "\n") { - format += "\n" - } - - fmt.Fprintf(outFile, format, v...) -} - // BeforeEach gets a client and makes a namespace. func (f *Framework) BeforeEach(ctx context.Context) { // DeferCleanup, in contrast to AfterEach, triggers execution in @@ -164,20 +146,6 @@ func (f *Framework) BeforeEach(ctx context.Context) { // not guaranteed to be unique, but very likely f.UniqueName = fmt.Sprintf("%s-%08x", f.BaseName, rand.Int31()) } - - ginkgo.By("Creating a helm client") - helmRestConfOpt := &helm.RestConfClientOptions{ - RestConfig: config, - Options: &helm.Options{ - Namespace: f.Namespace.Name, - RepositoryCache: "/tmp/.helmcache", - RepositoryConfig: "/tmp/.helmrepo", - Debug: true, - DebugLog: f.helmDebugLog, - }, - } - f.HelmClient, err = helm.NewClientFromRestConf(helmRestConfOpt) - gomega.Expect(err).NotTo(gomega.HaveOccurred()) } // AfterEach deletes the namespace, after reading its events. @@ -220,6 +188,9 @@ func (f *Framework) AfterEach(ctx context.Context) { } }() + // Close helm log file + err := f.HelmLogFile.Close() + gomega.Expect(err).To(gomega.BeNil()) } // CreateNamespace creates a namespace for e2e testing.