From b9b46b685a24dcaaa49cfbf41638b4c62039dd47 Mon Sep 17 00:00:00 2001 From: Luca Di Maio Date: Mon, 22 Jun 2026 16:03:46 +0200 Subject: [PATCH] fix(test): mock the manager in generate-entry single-mode tests Signed-off-by: Luca Di Maio --- pkg/commands/generate_entry_test.go | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/pkg/commands/generate_entry_test.go b/pkg/commands/generate_entry_test.go index f8294504..262bdf8f 100644 --- a/pkg/commands/generate_entry_test.go +++ b/pkg/commands/generate_entry_test.go @@ -23,8 +23,15 @@ func TestGenerateEntryCommand_Execute(t *testing.T) { tempDir := t.TempDir() defer os.RemoveAll(tempDir) - // create the list command - containerManager := providers.NewDocker(false, "sudo", false) + // A mock manager that lists the target box, so single-mode resolveTargets + // finds it: generate-entry refuses to create an entry for a missing box. + containerManager := &testutil.MockContainerManager{ + ListContainersResult: []containermanager.Container{{ + Name: "test-container", + Image: "registry.fedoraproject.org/fedora-toolbox:latest", + Labels: map[string]string{"manager": "distrobox"}, + }}, + } listCmd := commands.NewListCommand(&config.Values{}, containerManager) // @@ -90,7 +97,13 @@ func TestGenerateEntryCommand_Execute_Root(t *testing.T) { tempDir := t.TempDir() defer os.RemoveAll(tempDir) - containerManager := providers.NewDocker(false, "sudo", false) + containerManager := &testutil.MockContainerManager{ + ListContainersResult: []containermanager.Container{{ + Name: "test-container", + Image: "registry.fedoraproject.org/fedora-toolbox:latest", + Labels: map[string]string{"manager": "distrobox"}, + }}, + } listCmd := commands.NewListCommand(&config.Values{}, containerManager) generateEntryCmd := commands.NewGenerateEntryCommand(&config.Values{}, listCmd)