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
5 changes: 5 additions & 0 deletions pkg/project/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,11 @@ func (p *Project) Initialize(overwrite bool, blueprintURL ...string) error {
if err := p.Workstation.Prepare(); err != nil {
return fmt.Errorf("failed to prepare workstation: %w", err)
}
if p.Workstation.ContainerRuntime != nil {
if err := p.Workstation.ContainerRuntime.WriteConfig(); err != nil {
return fmt.Errorf("failed to write container runtime config: %w", err)
}
}
}

if err := p.Runtime.ConfigHandler.GenerateContextID(); err != nil {
Expand Down
92 changes: 92 additions & 0 deletions pkg/project/project_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"github.com/windsorcli/cli/pkg/workstation"
"github.com/windsorcli/cli/pkg/workstation/network"
"github.com/windsorcli/cli/pkg/workstation/services"
"github.com/windsorcli/cli/pkg/workstation/virt"
)

// =============================================================================
Expand Down Expand Up @@ -741,6 +742,97 @@ func TestProject_Initialize(t *testing.T) {
}
})

t.Run("CallsContainerRuntimeWriteConfig", func(t *testing.T) {
mocks := setupProjectMocks(t)
mockConfig := mocks.ConfigHandler.(*config.MockConfigHandler)
mockConfig.IsDevModeFunc = func(contextName string) bool {
return true
}
mockConfig.GetBoolFunc = func(key string, defaultValue ...bool) bool {
if key == "docker.enabled" {
return true
}
return false
}

proj, err := NewProject("test-context", &Project{Runtime: mocks.Runtime})
if err != nil {
t.Fatalf("Failed to create project: %v", err)
}

if err := proj.Configure(nil); err != nil {
t.Fatalf("Failed to configure project: %v", err)
}

if proj.Workstation == nil {
t.Fatal("Expected workstation to be created")
}

writeConfigCalled := false
mockContainerRuntime := virt.NewMockVirt()
mockContainerRuntime.WriteConfigFunc = func() error {
writeConfigCalled = true
return nil
}
proj.Workstation.ContainerRuntime = mockContainerRuntime
proj.Workstation.NetworkManager = nil

err = proj.Initialize(false)

if err != nil {
t.Errorf("Expected no error, got: %v", err)
}

if !writeConfigCalled {
t.Error("Expected ContainerRuntime.WriteConfig to be called")
}
})

t.Run("ErrorOnContainerRuntimeWriteConfigFailure", func(t *testing.T) {
mocks := setupProjectMocks(t)
mockConfig := mocks.ConfigHandler.(*config.MockConfigHandler)
mockConfig.IsDevModeFunc = func(contextName string) bool {
return true
}
mockConfig.GetBoolFunc = func(key string, defaultValue ...bool) bool {
if key == "docker.enabled" {
return true
}
return false
}

proj, err := NewProject("test-context", &Project{Runtime: mocks.Runtime})
if err != nil {
t.Fatalf("Failed to create project: %v", err)
}

if err := proj.Configure(nil); err != nil {
t.Fatalf("Failed to configure project: %v", err)
}

if proj.Workstation == nil {
t.Fatal("Expected workstation to be created")
}

mockContainerRuntime := virt.NewMockVirt()
mockContainerRuntime.WriteConfigFunc = func() error {
return fmt.Errorf("write config failed")
}
proj.Workstation.ContainerRuntime = mockContainerRuntime
proj.Workstation.NetworkManager = nil

err = proj.Initialize(false)

if err == nil {
t.Error("Expected error for ContainerRuntime.WriteConfig failure")
return
}

if !strings.Contains(err.Error(), "failed to write container runtime config") {
t.Errorf("Expected specific error message, got: %v", err)
}
})

t.Run("SuccessWithOverwriteTrue", func(t *testing.T) {
mocks := setupProjectMocks(t)
proj, err := NewProject("test-context", &Project{Runtime: mocks.Runtime})
Expand Down
6 changes: 0 additions & 6 deletions pkg/workstation/virt/docker_virt.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,6 @@ func (v *DockerVirt) Up() error {
return fmt.Errorf("failed to determine compose command: %w", err)
}

if v.configHandler.GetString("vm.driver") == "colima" {
if err := v.WriteConfig(); err != nil {
return fmt.Errorf("error regenerating docker compose config: %w", err)
}
}

projectRoot := v.runtime.ProjectRoot
composeFilePath := filepath.Join(projectRoot, ".windsor", "docker-compose.yaml")

Expand Down
Loading