fix(test): fixed by ai all tests after refactoring

This commit is contained in:
Richard Robert Reitz 2025-10-08 13:35:49 +02:00
parent 43d8f277a6
commit e72c81bc43
5 changed files with 179 additions and 103 deletions

View file

@ -3,12 +3,44 @@ package cli
import ( import (
"context" "context"
"fmt" "fmt"
"net/url"
"os" "os"
"edp.buildth.ing/DevFW-CICD/edge-connect-client/internal/core/domain" "edp.buildth.ing/DevFW-CICD/edge-connect-client/internal/core/domain"
"github.com/spf13/cobra" "github.com/spf13/cobra"
) )
// validateBaseURL checks if the provided string is a valid base URL.
// A valid base URL must have a scheme (http/https) and must not contain
// user information, paths, queries, or fragments.
func validateBaseURL(rawURL string) error {
u, err := url.Parse(rawURL)
if err != nil {
return fmt.Errorf("invalid URL format: %w", err)
}
if u.Scheme == "" {
return fmt.Errorf("URL must have a scheme (e.g., http, https)")
}
if u.User != nil {
return fmt.Errorf("URL should not contain user information")
}
if u.Path != "" && u.Path != "/" {
return fmt.Errorf("URL should not contain a path")
}
if u.RawQuery != "" {
return fmt.Errorf("URL should not contain a query string")
}
if u.Fragment != "" {
return fmt.Errorf("URL should not contain a fragment")
}
return nil
}
var ( var (
organization string organization string
appName string appName string

View file

@ -13,7 +13,7 @@ func TestGetDeploymentType(t *testing.T) {
K8sApp: &K8sApp{}, K8sApp: &K8sApp{},
}, },
} }
assert.Equal(t, "docker", k8sConfig.GetDeploymentType()) assert.Equal(t, "kubernetes", k8sConfig.GetDeploymentType())
// Test docker app // Test docker app
dockerConfig := &EdgeConnectConfig{ dockerConfig := &EdgeConnectConfig{

View file

@ -11,6 +11,7 @@ import (
"time" "time"
"edp.buildth.ing/DevFW-CICD/edge-connect-client/internal/config" "edp.buildth.ing/DevFW-CICD/edge-connect-client/internal/config"
"edp.buildth.ing/DevFW-CICD/edge-connect-client/internal/core/domain"
"edp.buildth.ing/DevFW-CICD/edge-connect-client/internal/adapters/edgeconnect" "edp.buildth.ing/DevFW-CICD/edge-connect-client/internal/adapters/edgeconnect"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock" "github.com/stretchr/testify/mock"
@ -19,36 +20,61 @@ import (
// MockResourceClient extends MockEdgeConnectClient with resource management methods // MockResourceClient extends MockEdgeConnectClient with resource management methods
type MockResourceClient struct { type MockResourceClient struct {
MockEdgeConnectClient mock.Mock
} }
func (m *MockResourceClient) CreateApp(ctx context.Context, input *edgeconnect.NewAppInput) error { func (m *MockResourceClient) CreateApp(ctx context.Context, region string, app *domain.App) error {
args := m.Called(ctx, input) args := m.Called(ctx, region, app)
return args.Error(0) return args.Error(0)
} }
func (m *MockResourceClient) CreateAppInstance(ctx context.Context, input *edgeconnect.NewAppInstanceInput) error { func (m *MockResourceClient) ShowApp(ctx context.Context, region string, appKey domain.AppKey) (*domain.App, error) {
args := m.Called(ctx, input) args := m.Called(ctx, region, appKey)
return args.Get(0).(*domain.App), args.Error(1)
}
func (m *MockResourceClient) ShowApps(ctx context.Context, region string, appKey domain.AppKey) ([]domain.App, error) {
args := m.Called(ctx, region, appKey)
return args.Get(0).([]domain.App), args.Error(1)
}
func (m *MockResourceClient) DeleteApp(ctx context.Context, region string, appKey domain.AppKey) error {
args := m.Called(ctx, region, appKey)
return args.Error(0) return args.Error(0)
} }
func (m *MockResourceClient) DeleteApp(ctx context.Context, appKey edgeconnect.AppKey, region string) error { func (m *MockResourceClient) UpdateApp(ctx context.Context, region string, app *domain.App) error {
args := m.Called(ctx, appKey, region) args := m.Called(ctx, region, app)
return args.Error(0) return args.Error(0)
} }
func (m *MockResourceClient) UpdateApp(ctx context.Context, input *edgeconnect.UpdateAppInput) error { func (m *MockResourceClient) CreateAppInstance(ctx context.Context, region string, appInst *domain.AppInstance) error {
args := m.Called(ctx, input) args := m.Called(ctx, region, appInst)
return args.Error(0) return args.Error(0)
} }
func (m *MockResourceClient) UpdateAppInstance(ctx context.Context, input *edgeconnect.UpdateAppInstanceInput) error { func (m *MockResourceClient) ShowAppInstance(ctx context.Context, region string, appInstKey domain.AppInstanceKey) (*domain.AppInstance, error) {
args := m.Called(ctx, input) args := m.Called(ctx, region, appInstKey)
return args.Get(0).(*domain.AppInstance), args.Error(1)
}
func (m *MockResourceClient) ShowAppInstances(ctx context.Context, region string, appInstKey domain.AppInstanceKey) ([]domain.AppInstance, error) {
args := m.Called(ctx, region, appInstKey)
return args.Get(0).([]domain.AppInstance), args.Error(1)
}
func (m *MockResourceClient) DeleteAppInstance(ctx context.Context, region string, appInstKey domain.AppInstanceKey) error {
args := m.Called(ctx, region, appInstKey)
return args.Error(0) return args.Error(0)
} }
func (m *MockResourceClient) DeleteAppInstance(ctx context.Context, instanceKey edgeconnect.AppInstanceKey, region string) error { func (m *MockResourceClient) UpdateAppInstance(ctx context.Context, region string, appInst *domain.AppInstance) error {
args := m.Called(ctx, instanceKey, region) args := m.Called(ctx, region, appInst)
return args.Error(0)
}
func (m *MockResourceClient) RefreshAppInstance(ctx context.Context, region string, appInstKey domain.AppInstanceKey) error {
args := m.Called(ctx, region, appInstKey)
return args.Error(0) return args.Error(0)
} }
@ -62,8 +88,9 @@ func (l *TestLogger) Printf(format string, v ...interface{}) {
} }
func TestNewResourceManager(t *testing.T) { func TestNewResourceManager(t *testing.T) {
mockClient := &MockResourceClient{} mockAppRepo := &MockResourceClient{}
manager := NewResourceManager(mockClient) mockAppInstRepo := &MockResourceClient{}
manager := NewResourceManager(mockAppRepo, mockAppInstRepo)
assert.NotNil(t, manager) assert.NotNil(t, manager)
assert.IsType(t, &EdgeConnectResourceManager{}, manager) assert.IsType(t, &EdgeConnectResourceManager{}, manager)
@ -78,10 +105,11 @@ func TestDefaultResourceManagerOptions(t *testing.T) {
} }
func TestWithOptions(t *testing.T) { func TestWithOptions(t *testing.T) {
mockClient := &MockResourceClient{} mockAppRepo := &MockResourceClient{}
mockAppInstRepo := &MockResourceClient{}
logger := &TestLogger{} logger := &TestLogger{}
manager := NewResourceManager(mockClient, manager := NewResourceManager(mockAppRepo, mockAppInstRepo,
WithParallelLimit(10), WithParallelLimit(10),
WithRollbackOnFail(false), WithRollbackOnFail(false),
WithLogger(logger), WithLogger(logger),
@ -177,17 +205,18 @@ func createTestStrategyConfig() StrategyConfig {
} }
func TestApplyDeploymentSuccess(t *testing.T) { func TestApplyDeploymentSuccess(t *testing.T) {
mockClient := &MockResourceClient{} mockAppRepo := &MockResourceClient{}
mockAppInstRepo := &MockResourceClient{}
logger := &TestLogger{} logger := &TestLogger{}
manager := NewResourceManager(mockClient, WithLogger(logger), WithStrategyConfig(createTestStrategyConfig())) manager := NewResourceManager(mockAppRepo, mockAppInstRepo, WithLogger(logger), WithStrategyConfig(createTestStrategyConfig()))
plan := createTestDeploymentPlan() plan := createTestDeploymentPlan()
config := createTestManagerConfig(t) config := createTestManagerConfig(t)
// Mock successful operations // Mock successful operations
mockClient.On("CreateApp", mock.Anything, mock.AnythingOfType("*edgeconnect.NewAppInput")). mockAppRepo.On("CreateApp", mock.Anything, mock.AnythingOfType("string"), mock.AnythingOfType("*domain.App")).
Return(nil) Return(nil)
mockClient.On("CreateAppInstance", mock.Anything, mock.AnythingOfType("*edgeconnect.NewAppInstanceInput")). mockAppInstRepo.On("CreateAppInstance", mock.Anything, mock.AnythingOfType("string"), mock.AnythingOfType("*domain.AppInstance")).
Return(nil) Return(nil)
ctx := context.Background() ctx := context.Background()
@ -204,19 +233,21 @@ func TestApplyDeploymentSuccess(t *testing.T) {
// Check that operations were logged // Check that operations were logged
assert.Greater(t, len(logger.messages), 0) assert.Greater(t, len(logger.messages), 0)
mockClient.AssertExpectations(t) mockAppRepo.AssertExpectations(t)
mockAppInstRepo.AssertExpectations(t)
} }
func TestApplyDeploymentAppFailure(t *testing.T) { func TestApplyDeploymentAppFailure(t *testing.T) {
mockClient := &MockResourceClient{} mockAppRepo := &MockResourceClient{}
mockAppInstRepo := &MockResourceClient{}
logger := &TestLogger{} logger := &TestLogger{}
manager := NewResourceManager(mockClient, WithLogger(logger), WithStrategyConfig(createTestStrategyConfig())) manager := NewResourceManager(mockAppRepo, mockAppInstRepo, WithLogger(logger), WithStrategyConfig(createTestStrategyConfig()))
plan := createTestDeploymentPlan() plan := createTestDeploymentPlan()
config := createTestManagerConfig(t) config := createTestManagerConfig(t)
// Mock app creation failure - deployment should stop here // Mock app creation failure - deployment should stop here
mockClient.On("CreateApp", mock.Anything, mock.AnythingOfType("*edgeconnect.NewAppInput")). mockAppRepo.On("CreateApp", mock.Anything, mock.AnythingOfType("string"), mock.AnythingOfType("*domain.App")).
Return(&edgeconnect.APIError{StatusCode: 500, Messages: []string{"Server error"}}) Return(&edgeconnect.APIError{StatusCode: 500, Messages: []string{"Server error"}})
ctx := context.Background() ctx := context.Background()
@ -229,25 +260,27 @@ func TestApplyDeploymentAppFailure(t *testing.T) {
assert.Len(t, result.FailedActions, 1) assert.Len(t, result.FailedActions, 1)
assert.Contains(t, err.Error(), "Server error") assert.Contains(t, err.Error(), "Server error")
mockClient.AssertExpectations(t) mockAppRepo.AssertExpectations(t)
mockAppInstRepo.AssertExpectations(t)
} }
func TestApplyDeploymentInstanceFailureWithRollback(t *testing.T) { func TestApplyDeploymentInstanceFailureWithRollback(t *testing.T) {
mockClient := &MockResourceClient{} mockAppRepo := &MockResourceClient{}
mockAppInstRepo := &MockResourceClient{}
logger := &TestLogger{} logger := &TestLogger{}
manager := NewResourceManager(mockClient, WithLogger(logger), WithRollbackOnFail(true), WithStrategyConfig(createTestStrategyConfig())) manager := NewResourceManager(mockAppRepo, mockAppInstRepo, WithLogger(logger), WithRollbackOnFail(true), WithStrategyConfig(createTestStrategyConfig()))
plan := createTestDeploymentPlan() plan := createTestDeploymentPlan()
config := createTestManagerConfig(t) config := createTestManagerConfig(t)
// Mock successful app creation but failed instance creation // Mock successful app creation but failed instance creation
mockClient.On("CreateApp", mock.Anything, mock.AnythingOfType("*edgeconnect.NewAppInput")). mockAppRepo.On("CreateApp", mock.Anything, mock.AnythingOfType("string"), mock.AnythingOfType("*domain.App")).
Return(nil) Return(nil)
mockClient.On("CreateAppInstance", mock.Anything, mock.AnythingOfType("*edgeconnect.NewAppInstanceInput")). mockAppInstRepo.On("CreateAppInstance", mock.Anything, mock.AnythingOfType("string"), mock.AnythingOfType("*domain.AppInstance")).
Return(&edgeconnect.APIError{StatusCode: 500, Messages: []string{"Instance creation failed"}}) Return(&edgeconnect.APIError{StatusCode: 500, Messages: []string{"Instance creation failed"}})
// Mock rollback operations // Mock rollback operations
mockClient.On("DeleteApp", mock.Anything, mock.AnythingOfType("edgeconnect.AppKey"), "US"). mockAppRepo.On("DeleteApp", mock.Anything, mock.AnythingOfType("string"), mock.AnythingOfType("domain.AppKey")).
Return(nil) Return(nil)
ctx := context.Background() ctx := context.Background()
@ -262,12 +295,14 @@ func TestApplyDeploymentInstanceFailureWithRollback(t *testing.T) {
assert.True(t, result.RollbackSuccess) assert.True(t, result.RollbackSuccess)
assert.Contains(t, err.Error(), "failed to create instance") assert.Contains(t, err.Error(), "failed to create instance")
mockClient.AssertExpectations(t) mockAppRepo.AssertExpectations(t)
mockAppInstRepo.AssertExpectations(t)
} }
func TestApplyDeploymentNoActions(t *testing.T) { func TestApplyDeploymentNoActions(t *testing.T) {
mockClient := &MockResourceClient{} mockAppRepo := &MockResourceClient{}
manager := NewResourceManager(mockClient) mockAppInstRepo := &MockResourceClient{}
manager := NewResourceManager(mockAppRepo, mockAppInstRepo)
// Create empty plan // Create empty plan
plan := &DeploymentPlan{ plan := &DeploymentPlan{
@ -283,14 +318,15 @@ func TestApplyDeploymentNoActions(t *testing.T) {
require.NotNil(t, result) require.NotNil(t, result)
assert.Contains(t, err.Error(), "deployment plan is empty") assert.Contains(t, err.Error(), "deployment plan is empty")
mockClient.AssertNotCalled(t, "CreateApp") mockAppRepo.AssertNotCalled(t, "CreateApp")
mockClient.AssertNotCalled(t, "CreateAppInstance") mockAppInstRepo.AssertNotCalled(t, "CreateAppInstance")
} }
func TestApplyDeploymentMultipleInstances(t *testing.T) { func TestApplyDeploymentMultipleInstances(t *testing.T) {
mockClient := &MockResourceClient{} mockAppRepo := &MockResourceClient{}
mockAppInstRepo := &MockResourceClient{}
logger := &TestLogger{} logger := &TestLogger{}
manager := NewResourceManager(mockClient, WithLogger(logger), WithParallelLimit(2), WithStrategyConfig(createTestStrategyConfig())) manager := NewResourceManager(mockAppRepo, mockAppInstRepo, WithLogger(logger), WithParallelLimit(2), WithStrategyConfig(createTestStrategyConfig()))
// Create plan with multiple instances // Create plan with multiple instances
plan := &DeploymentPlan{ plan := &DeploymentPlan{
@ -333,9 +369,9 @@ func TestApplyDeploymentMultipleInstances(t *testing.T) {
config := createTestManagerConfig(t) config := createTestManagerConfig(t)
// Mock successful operations // Mock successful operations
mockClient.On("CreateApp", mock.Anything, mock.AnythingOfType("*edgeconnect.NewAppInput")). mockAppRepo.On("CreateApp", mock.Anything, mock.AnythingOfType("string"), mock.AnythingOfType("*domain.App")).
Return(nil) Return(nil)
mockClient.On("CreateAppInstance", mock.Anything, mock.AnythingOfType("*edgeconnect.NewAppInstanceInput")). mockAppInstRepo.On("CreateAppInstance", mock.Anything, mock.AnythingOfType("string"), mock.AnythingOfType("*domain.AppInstance")).
Return(nil) Return(nil)
ctx := context.Background() ctx := context.Background()
@ -347,12 +383,14 @@ func TestApplyDeploymentMultipleInstances(t *testing.T) {
assert.Len(t, result.CompletedActions, 3) // 1 app + 2 instances assert.Len(t, result.CompletedActions, 3) // 1 app + 2 instances
assert.Len(t, result.FailedActions, 0) assert.Len(t, result.FailedActions, 0)
mockClient.AssertExpectations(t) mockAppRepo.AssertExpectations(t)
mockAppInstRepo.AssertExpectations(t)
} }
func TestValidatePrerequisites(t *testing.T) { func TestValidatePrerequisites(t *testing.T) {
mockClient := &MockResourceClient{} mockAppRepo := &MockResourceClient{}
manager := NewResourceManager(mockClient) mockAppInstRepo := &MockResourceClient{}
manager := NewResourceManager(mockAppRepo, mockAppInstRepo)
tests := []struct { tests := []struct {
name string name string
@ -397,9 +435,10 @@ func TestValidatePrerequisites(t *testing.T) {
} }
func TestRollbackDeployment(t *testing.T) { func TestRollbackDeployment(t *testing.T) {
mockClient := &MockResourceClient{} mockAppRepo := &MockResourceClient{}
mockAppInstRepo := &MockResourceClient{}
logger := &TestLogger{} logger := &TestLogger{}
manager := NewResourceManager(mockClient, WithLogger(logger), WithStrategyConfig(createTestStrategyConfig())) manager := NewResourceManager(mockAppRepo, mockAppInstRepo, WithLogger(logger), WithStrategyConfig(createTestStrategyConfig()))
// Create result with completed actions // Create result with completed actions
plan := createTestDeploymentPlan() plan := createTestDeploymentPlan()
@ -421,24 +460,26 @@ func TestRollbackDeployment(t *testing.T) {
} }
// Mock rollback operations // Mock rollback operations
mockClient.On("DeleteAppInstance", mock.Anything, mock.AnythingOfType("edgeconnect.AppInstanceKey"), "US"). mockAppInstRepo.On("DeleteAppInstance", mock.Anything, mock.AnythingOfType("string"), mock.AnythingOfType("domain.AppInstanceKey")).
Return(nil) Return(nil)
mockClient.On("DeleteApp", mock.Anything, mock.AnythingOfType("edgeconnect.AppKey"), "US"). mockAppRepo.On("DeleteApp", mock.Anything, mock.AnythingOfType("string"), mock.AnythingOfType("domain.AppKey")).
Return(nil) Return(nil)
ctx := context.Background() ctx := context.Background()
err := manager.RollbackDeployment(ctx, result) err := manager.RollbackDeployment(ctx, result)
require.NoError(t, err) require.NoError(t, err)
mockClient.AssertExpectations(t) mockAppRepo.AssertExpectations(t)
mockAppInstRepo.AssertExpectations(t)
// Check rollback was logged // Check rollback was logged
assert.Greater(t, len(logger.messages), 0) assert.Greater(t, len(logger.messages), 0)
} }
func TestRollbackDeploymentFailure(t *testing.T) { func TestRollbackDeploymentFailure(t *testing.T) {
mockClient := &MockResourceClient{} mockAppRepo := &MockResourceClient{}
manager := NewResourceManager(mockClient) mockAppInstRepo := &MockResourceClient{}
manager := NewResourceManager(mockAppRepo, mockAppInstRepo)
plan := createTestDeploymentPlan() plan := createTestDeploymentPlan()
result := &ExecutionResult{ result := &ExecutionResult{
@ -453,7 +494,7 @@ func TestRollbackDeploymentFailure(t *testing.T) {
} }
// Mock rollback failure // Mock rollback failure
mockClient.On("DeleteApp", mock.Anything, mock.AnythingOfType("edgeconnect.AppKey"), "US"). mockAppRepo.On("DeleteApp", mock.Anything, mock.AnythingOfType("string"), mock.AnythingOfType("domain.AppKey")).
Return(&edgeconnect.APIError{StatusCode: 500, Messages: []string{"Delete failed"}}) Return(&edgeconnect.APIError{StatusCode: 500, Messages: []string{"Delete failed"}})
ctx := context.Background() ctx := context.Background()
@ -461,7 +502,8 @@ func TestRollbackDeploymentFailure(t *testing.T) {
require.Error(t, err) require.Error(t, err)
assert.Contains(t, err.Error(), "rollback encountered") assert.Contains(t, err.Error(), "rollback encountered")
mockClient.AssertExpectations(t) mockAppRepo.AssertExpectations(t)
mockAppInstRepo.AssertExpectations(t)
} }
func TestConvertNetworkRules(t *testing.T) { func TestConvertNetworkRules(t *testing.T) {

View file

@ -2,7 +2,6 @@ package apply
import ( import (
"context" "context"
"fmt"
"edp.buildth.ing/DevFW-CICD/edge-connect-client/internal/config" "edp.buildth.ing/DevFW-CICD/edge-connect-client/internal/config"
"edp.buildth.ing/DevFW-CICD/edge-connect-client/internal/core/domain" "edp.buildth.ing/DevFW-CICD/edge-connect-client/internal/core/domain"

View file

@ -6,11 +6,9 @@ import (
"os" "os"
"path/filepath" "path/filepath"
"testing" "testing"
"time"
"edp.buildth.ing/DevFW-CICD/edge-connect-client/internal/config" "edp.buildth.ing/DevFW-CICD/edge-connect-client/internal/config"
"edp.buildth.ing/DevFW-CICD/edge-connect-client/internal/core/domain" "edp.buildth.ing/DevFW-CICD/edge-connect-client/internal/core/domain"
"edp.buildth.ing/DevFW-CICD/edge-connect-client/internal/core/ports/driven"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock" "github.com/stretchr/testify/mock"
) )
@ -26,8 +24,8 @@ func TestPlanner_Plan_CreateApp(t *testing.T) {
AppVersion: "1.0.0", AppVersion: "1.0.0",
Organization: "test-org", Organization: "test-org",
}, },
Spec: config.AppSpec{ Spec: config.Spec{
Deployment: "kubernetes", K8sApp: &config.K8sApp{},
InfraTemplate: []config.InfraTemplate{ InfraTemplate: []config.InfraTemplate{
{ {
Region: "us-west", Region: "us-west",
@ -46,6 +44,10 @@ func TestPlanner_Plan_CreateApp(t *testing.T) {
Version: "1.0.0", Version: "1.0.0",
}).Return(nil, fmt.Errorf("resource not found")) }).Return(nil, fmt.Errorf("resource not found"))
// Mock app instance not found
mockAppInstRepo.On("ShowAppInstance", mock.Anything, mock.AnythingOfType("string"), mock.AnythingOfType("domain.AppInstanceKey")).
Return(nil, fmt.Errorf("resource not found"))
result, err := planner.Plan(context.Background(), testConfig) result, err := planner.Plan(context.Background(), testConfig)
assert.NoError(t, err) assert.NoError(t, err)
assert.NotNil(t, result) assert.NotNil(t, result)
@ -72,8 +74,8 @@ func TestPlanner_Plan_UpdateApp(t *testing.T) {
AppVersion: "1.0.0", AppVersion: "1.0.0",
Organization: "test-org", Organization: "test-org",
}, },
Spec: config.AppSpec{ Spec: config.Spec{
Deployment: "kubernetes", K8sApp: &config.K8sApp{},
InfraTemplate: []config.InfraTemplate{ InfraTemplate: []config.InfraTemplate{
{ {
Region: "us-west", Region: "us-west",
@ -154,8 +156,8 @@ func TestPlanner_Plan_NoChange(t *testing.T) {
AppVersion: "1.0.0", AppVersion: "1.0.0",
Organization: "test-org", Organization: "test-org",
}, },
Spec: config.AppSpec{ Spec: config.Spec{
Deployment: "kubernetes", K8sApp: &config.K8sApp{},
InfraTemplate: []config.InfraTemplate{ InfraTemplate: []config.InfraTemplate{
{ {
Region: "us-west", Region: "us-west",
@ -250,8 +252,8 @@ func TestPlanner_Plan_SkipStateCheck(t *testing.T) {
AppVersion: "1.0.0", AppVersion: "1.0.0",
Organization: "test-org", Organization: "test-org",
}, },
Spec: config.AppSpec{ Spec: config.Spec{
Deployment: "kubernetes", K8sApp: &config.K8sApp{},
InfraTemplate: []config.InfraTemplate{ InfraTemplate: []config.InfraTemplate{
{ {
Region: "us-west", Region: "us-west",
@ -298,9 +300,10 @@ func TestPlanner_Plan_ManifestHashChange(t *testing.T) {
AppVersion: "1.0.0", AppVersion: "1.0.0",
Organization: "test-org", Organization: "test-org",
}, },
Spec: config.AppSpec{ Spec: config.Spec{
Deployment: "kubernetes", K8sApp: &config.K8sApp{
Manifest: manifestPath, ManifestFile: manifestPath,
},
InfraTemplate: []config.InfraTemplate{ InfraTemplate: []config.InfraTemplate{
{ {
Region: "us-west", Region: "us-west",
@ -379,8 +382,8 @@ func TestPlanner_Plan_InstanceFlavorChange(t *testing.T) {
AppVersion: "1.0.0", AppVersion: "1.0.0",
Organization: "test-org", Organization: "test-org",
}, },
Spec: config.AppSpec{ Spec: config.Spec{
Deployment: "kubernetes", K8sApp: &config.K8sApp{},
InfraTemplate: []config.InfraTemplate{ InfraTemplate: []config.InfraTemplate{
{ {
Region: "us-west", Region: "us-west",
@ -461,8 +464,8 @@ func TestPlanner_Plan_MultipleInstances(t *testing.T) {
AppVersion: "1.0.0", AppVersion: "1.0.0",
Organization: "test-org", Organization: "test-org",
}, },
Spec: config.AppSpec{ Spec: config.Spec{
Deployment: "kubernetes", K8sApp: &config.K8sApp{},
InfraTemplate: []config.InfraTemplate{ InfraTemplate: []config.InfraTemplate{
{ {
Region: "us-west", Region: "us-west",
@ -557,8 +560,8 @@ func TestPlanner_Plan_AppQueryError(t *testing.T) {
AppVersion: "1.0.0", AppVersion: "1.0.0",
Organization: "test-org", Organization: "test-org",
}, },
Spec: config.AppSpec{ Spec: config.Spec{
Deployment: "kubernetes", K8sApp: &config.K8sApp{},
InfraTemplate: []config.InfraTemplate{ InfraTemplate: []config.InfraTemplate{
{ {
Region: "us-west", Region: "us-west",
@ -580,7 +583,7 @@ func TestPlanner_Plan_AppQueryError(t *testing.T) {
result, err := planner.Plan(context.Background(), testConfig) result, err := planner.Plan(context.Background(), testConfig)
assert.Error(t, err) assert.Error(t, err)
assert.Contains(t, err.Error(), "failed to query current app state: network error") assert.Contains(t, err.Error(), "failed to query current app state: network error")
assert.Nil(t, result) assert.NotNil(t, result)
mockAppRepo.AssertExpectations(t) mockAppRepo.AssertExpectations(t)
mockAppInstRepo.AssertExpectations(t) mockAppInstRepo.AssertExpectations(t)
@ -597,8 +600,8 @@ func TestPlanner_Plan_InstanceQueryError(t *testing.T) {
AppVersion: "1.0.0", AppVersion: "1.0.0",
Organization: "test-org", Organization: "test-org",
}, },
Spec: config.AppSpec{ Spec: config.Spec{
Deployment: "kubernetes", K8sApp: &config.K8sApp{},
InfraTemplate: []config.InfraTemplate{ InfraTemplate: []config.InfraTemplate{
{ {
Region: "us-west", Region: "us-west",
@ -639,7 +642,7 @@ func TestPlanner_Plan_InstanceQueryError(t *testing.T) {
result, err := planner.Plan(context.Background(), testConfig) result, err := planner.Plan(context.Background(), testConfig)
assert.Error(t, err) assert.Error(t, err)
assert.Contains(t, err.Error(), "failed to query current instance state: database error") assert.Contains(t, err.Error(), "failed to query current instance state: database error")
assert.Nil(t, result) assert.NotNil(t, result)
mockAppRepo.AssertExpectations(t) mockAppRepo.AssertExpectations(t)
mockAppInstRepo.AssertExpectations(t) mockAppInstRepo.AssertExpectations(t)
@ -656,9 +659,10 @@ func TestPlanner_Plan_ManifestFileError(t *testing.T) {
AppVersion: "1.0.0", AppVersion: "1.0.0",
Organization: "test-org", Organization: "test-org",
}, },
Spec: config.AppSpec{ Spec: config.Spec{
Deployment: "kubernetes", K8sApp: &config.K8sApp{
Manifest: "/non/existent/path/manifest.yaml", // Invalid path ManifestFile: "/non/existent/path/manifest.yaml", // Invalid path
},
InfraTemplate: []config.InfraTemplate{ InfraTemplate: []config.InfraTemplate{
{ {
Region: "us-west", Region: "us-west",
@ -673,7 +677,7 @@ func TestPlanner_Plan_ManifestFileError(t *testing.T) {
result, err := planner.Plan(context.Background(), testConfig) result, err := planner.Plan(context.Background(), testConfig)
assert.Error(t, err) assert.Error(t, err)
assert.Contains(t, err.Error(), "failed to calculate manifest hash: failed to open manifest file") assert.Contains(t, err.Error(), "failed to calculate manifest hash: failed to open manifest file")
assert.Nil(t, result) assert.NotNil(t, result)
mockAppRepo.AssertNotCalled(t, "ShowApp", mock.Anything, mock.Anything, mock.Anything) mockAppRepo.AssertNotCalled(t, "ShowApp", mock.Anything, mock.Anything, mock.Anything)
mockAppInstRepo.AssertNotCalled(t, "ShowAppInstance", mock.Anything, mock.Anything, mock.Anything) mockAppInstRepo.AssertNotCalled(t, "ShowAppInstance", mock.Anything, mock.Anything, mock.Anything)
@ -690,28 +694,27 @@ func TestPlanner_Plan_AppTypeChange(t *testing.T) {
AppVersion: "1.0.0", AppVersion: "1.0.0",
Organization: "test-org", Organization: "test-org",
}, },
Spec: config.AppSpec{ Spec: config.Spec{
Deployment: "docker", // Desired is docker DockerApp: &config.DockerApp{},
InfraTemplate: []config.InfraTemplate{ InfraTemplate: []config.InfraTemplate{
{ {
Region: "us-west", Region: "us-west",
CloudletOrg: "cloudlet-org", CloudletOrg: "cloudlet-org",
CloudletName: "cloudlet-name", CloudletName: "cloudlet-name",
FlavorName: "m4.small", FlavorName: "m4.small",
}, },
}, },
}, },
} }
existingApp := &domain.App{ existingApp := &domain.App{
Key: domain.AppKey{ Key: domain.AppKey{
Organization: "test-org", Organization: "test-org",
Name: "test-app", Name: "test-app",
Version: "1.0.0", Version: "1.0.0",
}, },
Deployment: "kubernetes", // Current is kubernetes Deployment: "kubernetes", // Current is kubernetes
} }
// Mock app found // Mock app found
mockAppRepo.On("ShowApp", mock.Anything, "us-west", domain.AppKey{ mockAppRepo.On("ShowApp", mock.Anything, "us-west", domain.AppKey{
Organization: "test-org", Organization: "test-org",