Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions cmd/bundle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,9 +155,6 @@ func TestBundleCmdWithRuntime(t *testing.T) {
mockShell.GetProjectRootFunc = func() (string, error) {
return tmpDir, nil
}
mockShell.InitializeFunc = func() error {
return nil
}
injector.Register("shell", mockShell)

// Mock config handler
Expand All @@ -168,9 +165,6 @@ func TestBundleCmdWithRuntime(t *testing.T) {
mockConfigHandler.GetContextFunc = func() string {
return "test-context"
}
mockConfigHandler.InitializeFunc = func() error {
return nil
}
injector.Register("configHandler", mockConfigHandler)

// Mock kubernetes manager
Expand Down
37 changes: 2 additions & 35 deletions cmd/check_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ import (
"strings"
"testing"

"github.com/windsorcli/cli/pkg/di"
"github.com/windsorcli/cli/pkg/provisioner/cluster"
"github.com/windsorcli/cli/pkg/runtime/config"
"github.com/windsorcli/cli/pkg/runtime/shell"
"github.com/windsorcli/cli/pkg/runtime/tools"
"github.com/windsorcli/cli/pkg/di"
"github.com/windsorcli/cli/pkg/provisioner/cluster"
)

func TestCheckCmd(t *testing.T) {
Expand Down Expand Up @@ -69,9 +69,6 @@ func TestCheckCmd(t *testing.T) {
mockConfigHandler.LoadConfigFunc = func() error {
return nil
}
mockConfigHandler.InitializeFunc = func() error {
return nil
}
mockConfigHandler.GetContextFunc = func() string {
return "test-context"
}
Expand Down Expand Up @@ -110,9 +107,6 @@ func TestCheckCmd(t *testing.T) {
mockConfigHandler.LoadConfigFunc = func() error {
return nil
}
mockConfigHandler.InitializeFunc = func() error {
return nil
}
mockConfigHandler.GetContextFunc = func() string {
return "test-context"
}
Expand Down Expand Up @@ -163,9 +157,6 @@ func TestCheckCmd_ErrorScenarios(t *testing.T) {
mockShell.GetProjectRootFunc = func() (string, error) {
return "", fmt.Errorf("project root error")
}
mockShell.InitializeFunc = func() error {
return nil
}
injector.Register("shell", mockShell)

ctx := stdcontext.WithValue(stdcontext.Background(), injectorKey, injector)
Expand Down Expand Up @@ -214,9 +205,6 @@ func TestCheckCmd_ErrorScenarios(t *testing.T) {
mockConfigHandler.LoadConfigFunc = func() error {
return fmt.Errorf("config load failed")
}
mockConfigHandler.InitializeFunc = func() error {
return nil
}
mockConfigHandler.GetContextFunc = func() string {
return "test-context"
}
Expand All @@ -229,9 +217,6 @@ func TestCheckCmd_ErrorScenarios(t *testing.T) {
mockShell.CheckTrustedDirectoryFunc = func() error {
return nil
}
mockShell.InitializeFunc = func() error {
return nil
}
injector.Register("shell", mockShell)

ctx := stdcontext.WithValue(stdcontext.Background(), injectorKey, injector)
Expand All @@ -256,9 +241,6 @@ func TestCheckCmd_ErrorScenarios(t *testing.T) {
mockConfigHandler.LoadConfigFunc = func() error {
return nil
}
mockConfigHandler.InitializeFunc = func() error {
return nil
}
mockConfigHandler.GetContextFunc = func() string {
return "test-context"
}
Expand Down Expand Up @@ -357,9 +339,6 @@ func TestCheckNodeHealthCmd(t *testing.T) {
mockConfigHandler.LoadConfigFunc = func() error {
return nil
}
mockConfigHandler.InitializeFunc = func() error {
return nil
}
mockConfigHandler.GetContextFunc = func() string {
return "test-context"
}
Expand Down Expand Up @@ -481,9 +460,6 @@ func TestCheckNodeHealthCmd_ErrorScenarios(t *testing.T) {
mockShell.GetProjectRootFunc = func() (string, error) {
return "", fmt.Errorf("project root error")
}
mockShell.InitializeFunc = func() error {
return nil
}
injector.Register("shell", mockShell)

ctx := stdcontext.WithValue(stdcontext.Background(), injectorKey, injector)
Expand Down Expand Up @@ -532,9 +508,6 @@ func TestCheckNodeHealthCmd_ErrorScenarios(t *testing.T) {
mockConfigHandler.LoadConfigFunc = func() error {
return fmt.Errorf("config load failed")
}
mockConfigHandler.InitializeFunc = func() error {
return nil
}
mockConfigHandler.GetContextFunc = func() string {
return "test-context"
}
Expand All @@ -547,9 +520,6 @@ func TestCheckNodeHealthCmd_ErrorScenarios(t *testing.T) {
mockShell.CheckTrustedDirectoryFunc = func() error {
return nil
}
mockShell.InitializeFunc = func() error {
return nil
}
injector.Register("shell", mockShell)

ctx := stdcontext.WithValue(stdcontext.Background(), injectorKey, injector)
Expand All @@ -574,9 +544,6 @@ func TestCheckNodeHealthCmd_ErrorScenarios(t *testing.T) {
mockConfigHandler.LoadConfigFunc = func() error {
return nil
}
mockConfigHandler.InitializeFunc = func() error {
return nil
}
mockConfigHandler.GetContextFunc = func() string {
return "test-context"
}
Expand Down
26 changes: 1 addition & 25 deletions cmd/context_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import (
"strings"
"testing"

"github.com/windsorcli/cli/pkg/di"
"github.com/windsorcli/cli/pkg/runtime/config"
"github.com/windsorcli/cli/pkg/runtime/shell"
"github.com/windsorcli/cli/pkg/di"
)

func TestContextCmd(t *testing.T) {
Expand Down Expand Up @@ -196,9 +196,6 @@ func TestContextCmd_ErrorScenarios(t *testing.T) {
mockShell.GetProjectRootFunc = func() (string, error) {
return "", fmt.Errorf("project root error")
}
mockShell.InitializeFunc = func() error {
return nil
}
injector.Register("shell", mockShell)
ctx := context.WithValue(context.Background(), injectorKey, injector)
rootCmd.SetContext(ctx)
Expand All @@ -223,9 +220,6 @@ func TestContextCmd_ErrorScenarios(t *testing.T) {
mockConfigHandler.LoadConfigFunc = func() error {
return fmt.Errorf("config load failed")
}
mockConfigHandler.InitializeFunc = func() error {
return nil
}
mockConfigHandler.GetContextFunc = func() string {
return "test-context"
}
Expand All @@ -235,9 +229,6 @@ func TestContextCmd_ErrorScenarios(t *testing.T) {
mockShell.GetProjectRootFunc = func() (string, error) {
return t.TempDir(), nil
}
mockShell.InitializeFunc = func() error {
return nil
}
injector.Register("shell", mockShell)

ctx := context.WithValue(context.Background(), injectorKey, injector)
Expand All @@ -263,9 +254,6 @@ func TestContextCmd_ErrorScenarios(t *testing.T) {
mockShell.GetProjectRootFunc = func() (string, error) {
return "", fmt.Errorf("project root error")
}
mockShell.InitializeFunc = func() error {
return nil
}
injector.Register("shell", mockShell)
ctx := context.WithValue(context.Background(), injectorKey, injector)
rootCmd.SetContext(ctx)
Expand All @@ -290,9 +278,6 @@ func TestContextCmd_ErrorScenarios(t *testing.T) {
mockConfigHandler.LoadConfigFunc = func() error {
return fmt.Errorf("config load failed")
}
mockConfigHandler.InitializeFunc = func() error {
return nil
}
mockConfigHandler.GetContextFunc = func() string {
return "test-context"
}
Expand All @@ -302,9 +287,6 @@ func TestContextCmd_ErrorScenarios(t *testing.T) {
mockShell.GetProjectRootFunc = func() (string, error) {
return t.TempDir(), nil
}
mockShell.InitializeFunc = func() error {
return nil
}
injector.Register("shell", mockShell)

ctx := context.WithValue(context.Background(), injectorKey, injector)
Expand Down Expand Up @@ -352,9 +334,6 @@ func TestContextCmd_ErrorScenarios(t *testing.T) {
mockConfigHandler.LoadConfigFunc = func() error {
return nil
}
mockConfigHandler.InitializeFunc = func() error {
return nil
}
mockConfigHandler.GetContextFunc = func() string {
return "test-context"
}
Expand All @@ -370,9 +349,6 @@ func TestContextCmd_ErrorScenarios(t *testing.T) {
mockShell.WriteResetTokenFunc = func() (string, error) {
return "mock-reset-token", nil
}
mockShell.InitializeFunc = func() error {
return nil
}
injector.Register("shell", mockShell)

ctx := context.WithValue(context.Background(), injectorKey, injector)
Expand Down
14 changes: 1 addition & 13 deletions cmd/env_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ import (
"strings"
"testing"

"github.com/windsorcli/cli/pkg/di"
"github.com/windsorcli/cli/pkg/runtime/config"
"github.com/windsorcli/cli/pkg/runtime/env"
"github.com/windsorcli/cli/pkg/runtime/shell"
"github.com/windsorcli/cli/pkg/di"
)

// TestEnvCmd tests the Windsor CLI 'env' command for correct environment variable output and error handling across success and decrypt scenarios.
Expand Down Expand Up @@ -242,9 +242,6 @@ func TestEnvCmd_ErrorScenarios(t *testing.T) {
mockShell.GetProjectRootFunc = func() (string, error) {
return "", fmt.Errorf("project root error")
}
mockShell.InitializeFunc = func() error {
return nil
}
injector.Register("shell", mockShell)
ctx := context.WithValue(context.Background(), injectorKey, injector)
rootCmd.SetContext(ctx)
Expand Down Expand Up @@ -336,9 +333,6 @@ func TestEnvCmd_ErrorScenarios(t *testing.T) {
mockConfigHandler.LoadConfigFunc = func() error {
return fmt.Errorf("config load failed")
}
mockConfigHandler.InitializeFunc = func() error {
return nil
}
mockConfigHandler.GetContextFunc = func() string {
return "test-context"
}
Expand All @@ -354,9 +348,6 @@ func TestEnvCmd_ErrorScenarios(t *testing.T) {
mockShell.CheckResetFlagsFunc = func() (bool, error) {
return false, nil
}
mockShell.InitializeFunc = func() error {
return nil
}
injector.Register("shell", mockShell)

ctx := context.WithValue(context.Background(), injectorKey, injector)
Expand Down Expand Up @@ -499,9 +490,6 @@ func TestEnvCmd_ErrorScenarios(t *testing.T) {
}
return ""
}
mockConfigHandler.InitializeFunc = func() error {
return nil
}
mockConfigHandler.LoadConfigFunc = func() error {
return nil
}
Expand Down
14 changes: 1 addition & 13 deletions cmd/exec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ import (
"testing"

"github.com/spf13/cobra"
"github.com/windsorcli/cli/pkg/di"
"github.com/windsorcli/cli/pkg/runtime/config"
"github.com/windsorcli/cli/pkg/runtime/env"
"github.com/windsorcli/cli/pkg/runtime/shell"
"github.com/windsorcli/cli/pkg/di"
)

func TestExecCmd(t *testing.T) {
Expand Down Expand Up @@ -158,9 +158,6 @@ func TestExecCmd_ErrorScenarios(t *testing.T) {
mockShell.GetProjectRootFunc = func() (string, error) {
return "", fmt.Errorf("project root error")
}
mockShell.InitializeFunc = func() error {
return nil
}
injector.Register("shell", mockShell)
ctx := context.WithValue(context.Background(), injectorKey, injector)
rootCmd.SetContext(ctx)
Expand Down Expand Up @@ -253,9 +250,6 @@ func TestExecCmd_ErrorScenarios(t *testing.T) {
mockConfigHandler.LoadConfigFunc = func() error {
return fmt.Errorf("config load failed")
}
mockConfigHandler.InitializeFunc = func() error {
return nil
}
mockConfigHandler.GetContextFunc = func() string {
return "test-context"
}
Expand All @@ -271,9 +265,6 @@ func TestExecCmd_ErrorScenarios(t *testing.T) {
mockShell.CheckResetFlagsFunc = func() (bool, error) {
return false, nil
}
mockShell.InitializeFunc = func() error {
return nil
}
injector.Register("shell", mockShell)

ctx := context.WithValue(context.Background(), injectorKey, injector)
Expand Down Expand Up @@ -306,9 +297,6 @@ func TestExecCmd_ErrorScenarios(t *testing.T) {
mockConfigHandler.LoadConfigFunc = func() error {
return nil
}
mockConfigHandler.InitializeFunc = func() error {
return nil
}
mockConfigHandler.GetContextFunc = func() string {
return "test-context"
}
Expand Down
11 changes: 3 additions & 8 deletions cmd/root_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ import (

"github.com/spf13/cobra"
blueprintpkg "github.com/windsorcli/cli/pkg/composer/blueprint"
"github.com/windsorcli/cli/pkg/di"
"github.com/windsorcli/cli/pkg/provisioner/kubernetes"
"github.com/windsorcli/cli/pkg/runtime/config"
envvars "github.com/windsorcli/cli/pkg/runtime/env"
"github.com/windsorcli/cli/pkg/runtime/secrets"
"github.com/windsorcli/cli/pkg/runtime/shell"
"github.com/windsorcli/cli/pkg/di"
"github.com/windsorcli/cli/pkg/provisioner/kubernetes"
)

// =============================================================================
Expand Down Expand Up @@ -147,7 +147,7 @@ func setupMocks(t *testing.T, opts ...*SetupOptions) *Mocks {
// Create config handler
var configHandler config.ConfigHandler
if options.ConfigHandler == nil {
configHandler = config.NewConfigHandler(injector)
configHandler = config.NewConfigHandler(mockShell)
} else {
configHandler = options.ConfigHandler
// If it's a mock config handler, set GetConfigRootFunc to use tmpDir
Expand All @@ -163,11 +163,6 @@ func setupMocks(t *testing.T, opts ...*SetupOptions) *Mocks {
// Register config handler
injector.Register("configHandler", configHandler)

// Initialize config handler
if err := configHandler.Initialize(); err != nil {
t.Fatalf("Failed to initialize config handler: %v", err)
}

// Load config if ConfigStr is provided
if options.ConfigStr != "" {
if err := configHandler.LoadConfigString(options.ConfigStr); err != nil {
Expand Down
3 changes: 1 addition & 2 deletions cmd/up_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ func setupUpTest(t *testing.T, opts ...*SetupOptions) *UpMocks {

// Create mock config handler to control IsDevMode
mockConfigHandler := config.NewMockConfigHandler()
mockConfigHandler.InitializeFunc = func() error { return nil }
mockConfigHandler.GetContextFunc = func() string { return "test-context" }
mockConfigHandler.IsDevModeFunc = func(contextName string) bool { return false }
mockConfigHandler.GetStringFunc = func(key string, defaultValue ...string) string {
Expand Down Expand Up @@ -112,7 +111,7 @@ func setupUpTest(t *testing.T, opts ...*SetupOptions) *UpMocks {
baseMocks.Injector.Register("kubernetesManager", mockKubernetesManager)

// Add terraform env printer (required by terraform stack)
terraformEnvPrinter := envvars.NewTerraformEnvPrinter(baseMocks.Injector)
terraformEnvPrinter := envvars.NewTerraformEnvPrinter(baseMocks.Shell, baseMocks.ConfigHandler)
baseMocks.Injector.Register("terraformEnv", terraformEnvPrinter)

// Add mock tools manager (required by runInit)
Expand Down
Loading
Loading