Skip to content

Commit

Permalink
Move mock strongbox functions closer to definitions
Browse files Browse the repository at this point in the history
  • Loading branch information
ffilippopoulos committed Jun 1, 2023
1 parent eee597e commit bb43368
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 23 deletions.
9 changes: 0 additions & 9 deletions run/runner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,6 @@ import (
"github.com/utilitywarehouse/kube-applier/metrics"
)

type mockStrongboxer struct{}

func (m *mockStrongboxer) SetupGitConfigForStrongbox(ctx context.Context, homeDir string, env []string) error {
return nil
}
func (m *mockStrongboxer) SetupStrongboxKeyring(ctx context.Context, kubeClient *client.Client, waybill *kubeapplierv1alpha1.Waybill, homeDir string) error {
return nil
}

func TestApplyOptions_pruneWhitelist(t *testing.T) {
assert := assert.New(t)

Expand Down
41 changes: 27 additions & 14 deletions run/strongbox.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,9 @@ type StrongboxInterface interface {
SetupStrongboxKeyring(ctx context.Context, kubeClient *client.Client, waybill *kubeapplierv1alpha1.Waybill, homeDir string) error
}

type Strongboxer struct{}
type strongboxBase struct{}

func (s *Strongboxer) SetupGitConfigForStrongbox(ctx context.Context, homeDir string, env []string) error {
cmd := exec.CommandContext(ctx, "strongbox", "-git-config")
cmd.Dir = homeDir
cmd.Env = append(env, fmt.Sprintf("PATH=%s", os.Getenv("PATH")))
stderr, err := cmd.CombinedOutput()
if err != nil {
return fmt.Errorf("error running strongbox err:%s %w ", stderr, err)
}

return nil
}

func (s *Strongboxer) SetupStrongboxKeyring(ctx context.Context, kubeClient *client.Client, waybill *kubeapplierv1alpha1.Waybill, homeDir string) error {
func (sb *strongboxBase) SetupStrongboxKeyring(ctx context.Context, kubeClient *client.Client, waybill *kubeapplierv1alpha1.Waybill, homeDir string) error {
if waybill.Spec.StrongboxKeyringSecretRef == nil {
return nil
}
Expand All @@ -55,3 +43,28 @@ func (s *Strongboxer) SetupStrongboxKeyring(ctx context.Context, kubeClient *cli
}
return nil
}

type Strongboxer struct {
strongboxBase
}

func (s *Strongboxer) SetupGitConfigForStrongbox(ctx context.Context, homeDir string, env []string) error {
cmd := exec.CommandContext(ctx, "strongbox", "-git-config")
cmd.Dir = homeDir
cmd.Env = append(env, fmt.Sprintf("PATH=%s", os.Getenv("PATH")))
stderr, err := cmd.CombinedOutput()
if err != nil {
return fmt.Errorf("error running strongbox err:%s %w ", stderr, err)
}

return nil
}

// Mock Strongboxer for testing
type mockStrongboxer struct {
strongboxBase
}

func (m *mockStrongboxer) SetupGitConfigForStrongbox(ctx context.Context, homeDir string, env []string) error {
return nil
}

0 comments on commit bb43368

Please sign in to comment.