From 4af622a6a8667403b2ce50e745f2a0f9592b9be2 Mon Sep 17 00:00:00 2001 From: miampf Date: Wed, 14 Feb 2024 13:53:45 +0100 Subject: [PATCH] fixed issues with unit tests --- cli/internal/cmd/apply.go | 21 ++++++++++----------- cli/internal/cmd/apply_test.go | 2 +- cli/internal/cmd/create_test.go | 4 ++-- cli/internal/cmd/init_test.go | 2 +- cli/internal/cmd/upgradeapply_test.go | 2 +- 5 files changed, 15 insertions(+), 16 deletions(-) diff --git a/cli/internal/cmd/apply.go b/cli/internal/cmd/apply.go index 2158b5be9f..1364b13b01 100644 --- a/cli/internal/cmd/apply.go +++ b/cli/internal/cmd/apply.go @@ -262,7 +262,7 @@ func runApply(cmd *cobra.Command, _ []string) error { defer cancel() cmd.SetContext(ctx) - return apply.apply(cmd, attestationconfigapi.NewFetcher(), upgradeDir, fileHandler) + return apply.apply(cmd, attestationconfigapi.NewFetcher(), upgradeDir) } type applyCmd struct { @@ -350,10 +350,10 @@ The control flow is as follows: └────────────────────┘ */ func (a *applyCmd) apply( - cmd *cobra.Command, configFetcher attestationconfigapi.Fetcher, upgradeDir string, debugFileHandler file.Handler, + cmd *cobra.Command, configFetcher attestationconfigapi.Fetcher, upgradeDir string, ) error { // Validate inputs - conf, stateFile, err := a.validateInputs(cmd, configFetcher, debugFileHandler) + conf, stateFile, err := a.validateInputs(cmd, configFetcher) if err != nil { return err } @@ -397,7 +397,7 @@ func (a *applyCmd) apply( // Apply Attestation Config if !a.flags.skipPhases.contains(skipAttestationConfigPhase) { a.log.Debug("Applying new attestation config to cluster") - if err := a.applyJoinConfig(cmd, conf.GetAttestationConfig(), stateFile.ClusterValues.MeasurementSalt, debugFileHandler); err != nil { + if err := a.applyJoinConfig(cmd, conf.GetAttestationConfig(), stateFile.ClusterValues.MeasurementSalt); err != nil { return fmt.Errorf("applying attestation config: %w", err) } } @@ -441,7 +441,7 @@ func (a *applyCmd) apply( return nil } -func (a *applyCmd) validateInputs(cmd *cobra.Command, configFetcher attestationconfigapi.Fetcher, debugFileHandler file.Handler) (*config.Config, *state.State, error) { +func (a *applyCmd) validateInputs(cmd *cobra.Command, configFetcher attestationconfigapi.Fetcher) (*config.Config, *state.State, error) { // Read user's config and state file a.log.Debug(fmt.Sprintf("Reading config from %s", a.flags.pathPrefixer.PrefixPrintablePath(constants.ConfigFilename))) conf, err := config.New(a.fileHandler, constants.ConfigFilename, configFetcher, a.flags.force) @@ -478,7 +478,7 @@ func (a *applyCmd) validateInputs(cmd *cobra.Command, configFetcher attestationc return nil, nil, preInitValidateErr } - if err := a.checkCreateFilesClean(debugFileHandler); err != nil { + if err := a.checkCreateFilesClean(); err != nil { return nil, nil, err } @@ -496,7 +496,7 @@ func (a *applyCmd) validateInputs(cmd *cobra.Command, configFetcher attestationc return nil, nil, postInitValidateErr } - if err := a.checkInitFilesClean(debugFileHandler); err != nil { + if err := a.checkInitFilesClean(); err != nil { return nil, nil, err } @@ -589,7 +589,6 @@ func (a *applyCmd) validateInputs(cmd *cobra.Command, configFetcher attestationc // applyJoinConfig creates or updates the cluster's join config. // If the config already exists, and is different from the new config, the user is asked to confirm the upgrade. func (a *applyCmd) applyJoinConfig(cmd *cobra.Command, newConfig config.AttestationCfg, measurementSalt []byte, - debugFileHandler file.Handler, ) error { clusterAttestationConfig, err := a.applier.GetClusterAttestationConfig(cmd.Context(), newConfig.GetVariant()) if err != nil { @@ -682,8 +681,8 @@ func (a *applyCmd) runK8sVersionUpgrade(cmd *cobra.Command, conf *config.Config) } // checkCreateFilesClean ensures that the workspace is clean before creating a new cluster. -func (a *applyCmd) checkCreateFilesClean(debugFileHandler file.Handler) error { - if err := a.checkInitFilesClean(debugFileHandler); err != nil { +func (a *applyCmd) checkCreateFilesClean() error { + if err := a.checkInitFilesClean(); err != nil { return err } a.log.Debug("Checking Terraform state") @@ -700,7 +699,7 @@ func (a *applyCmd) checkCreateFilesClean(debugFileHandler file.Handler) error { } // checkInitFilesClean ensures that the workspace is clean before running the init RPC. -func (a *applyCmd) checkInitFilesClean(debugFileHandler file.Handler) error { +func (a *applyCmd) checkInitFilesClean() error { a.log.Debug("Checking admin configuration file") if _, err := a.fileHandler.Stat(constants.AdminConfFilename); err == nil { return fmt.Errorf( diff --git a/cli/internal/cmd/apply_test.go b/cli/internal/cmd/apply_test.go index dfe8c9a1ad..55f0556697 100644 --- a/cli/internal/cmd/apply_test.go +++ b/cli/internal/cmd/apply_test.go @@ -447,7 +447,7 @@ func TestValidateInputs(t *testing.T) { flags: tc.flags, } - conf, state, err := a.validateInputs(cmd, &stubAttestationFetcher{}, file.NewHandler(afero.NewMemMapFs())) + conf, state, err := a.validateInputs(cmd, &stubAttestationFetcher{}) if tc.wantErr { assert.Error(err) return diff --git a/cli/internal/cmd/create_test.go b/cli/internal/cmd/create_test.go index f8aabbd1f9..fe3119ee38 100644 --- a/cli/internal/cmd/create_test.go +++ b/cli/internal/cmd/create_test.go @@ -237,7 +237,7 @@ func TestCreate(t *testing.T) { applier: &stubConstellApplier{}, } - err := a.apply(cmd, stubAttestationFetcher{}, "create", fileHandler) + err := a.apply(cmd, stubAttestationFetcher{}, "create") if tc.wantErr { assert.Error(err) @@ -296,7 +296,7 @@ func TestCheckDirClean(t *testing.T) { require.NoError(fh.Write(f, []byte{1, 2, 3}, file.OptNone)) } a := &applyCmd{log: logger.NewTest(t), fileHandler: fh} - err := a.checkInitFilesClean(file.NewHandler(afero.NewMemMapFs())) + err := a.checkInitFilesClean() if tc.wantErr { assert.Error(err) diff --git a/cli/internal/cmd/init_test.go b/cli/internal/cmd/init_test.go index 05dbba2013..de6278d660 100644 --- a/cli/internal/cmd/init_test.go +++ b/cli/internal/cmd/init_test.go @@ -247,7 +247,7 @@ func TestInitialize(t *testing.T) { }, } - err := i.apply(cmd, stubAttestationFetcher{}, "test", fileHandler) + err := i.apply(cmd, stubAttestationFetcher{}, "test") if tc.wantErr { assert.Error(err) diff --git a/cli/internal/cmd/upgradeapply_test.go b/cli/internal/cmd/upgradeapply_test.go index c8e83194f9..488a512d51 100644 --- a/cli/internal/cmd/upgradeapply_test.go +++ b/cli/internal/cmd/upgradeapply_test.go @@ -263,7 +263,7 @@ func TestUpgradeApply(t *testing.T) { }, imageFetcher: &stubImageFetcher{fetchReferenceErr: tc.fetchImageErr}, } - err := upgrader.apply(cmd, stubAttestationFetcher{}, "test", file.NewHandler(afero.NewMemMapFs())) + err := upgrader.apply(cmd, stubAttestationFetcher{}, "test") if tc.wantErr { assert.Error(err) return