Skip to content

Commit

Permalink
fixed issues with unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
miampf committed Feb 14, 2024
1 parent 81da6bb commit 4af622a
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 16 deletions.
21 changes: 10 additions & 11 deletions cli/internal/cmd/apply.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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)
}
}
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
}

Expand All @@ -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
}

Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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")
Expand All @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion cli/internal/cmd/apply_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions cli/internal/cmd/create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion cli/internal/cmd/init_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion cli/internal/cmd/upgradeapply_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 4af622a

Please sign in to comment.