fix(test): mock the manager in generate-entry single-mode tests

Signed-off-by: Luca Di Maio <luca.dimaio1@gmail.com>
This commit is contained in:
Luca Di Maio
2026-06-25 09:07:25 +02:00
parent 3a4fc6a89e
commit b9b46b685a
+16 -3
View File
@@ -23,8 +23,15 @@ func TestGenerateEntryCommand_Execute(t *testing.T) {
tempDir := t.TempDir() tempDir := t.TempDir()
defer os.RemoveAll(tempDir) defer os.RemoveAll(tempDir)
// create the list command // A mock manager that lists the target box, so single-mode resolveTargets
containerManager := providers.NewDocker(false, "sudo", false) // 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) listCmd := commands.NewListCommand(&config.Values{}, containerManager)
// //
@@ -90,7 +97,13 @@ func TestGenerateEntryCommand_Execute_Root(t *testing.T) {
tempDir := t.TempDir() tempDir := t.TempDir()
defer os.RemoveAll(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) listCmd := commands.NewListCommand(&config.Values{}, containerManager)
generateEntryCmd := commands.NewGenerateEntryCommand(&config.Values{}, listCmd) generateEntryCmd := commands.NewGenerateEntryCommand(&config.Values{}, listCmd)