mirror of
https://github.com/89luca89/distrobox.git
synced 2026-08-19 01:14:49 -05:00
test(providers): add podman command selection test
Signed-off-by: Fabrizio Sestito <fabrizio.sestito@suse.com>
This commit is contained in:
committed by
Alessio Biancalana
parent
730ca303a1
commit
270384f994
@@ -1,6 +1,8 @@
|
|||||||
package providers
|
package providers
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
@@ -709,6 +711,54 @@ func TestParsePodmanContainerListEmptyNames(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestPodman_runUsesCorrectBinary(t *testing.T) {
|
||||||
|
tests := []struct {
|
||||||
|
name string
|
||||||
|
constructor func() *Podman
|
||||||
|
expectedPrefix string
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
name: "NewPodman uses podman binary",
|
||||||
|
constructor: func() *Podman { return NewPodman(false, "sudo", false) },
|
||||||
|
expectedPrefix: "podman ",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "NewPodmanLauncher uses podman-launcher binary",
|
||||||
|
constructor: func() *Podman { return NewPodmanLauncher(false, "sudo", false) },
|
||||||
|
expectedPrefix: "podman-launcher ",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, tt := range tests {
|
||||||
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
|
p := tt.constructor()
|
||||||
|
|
||||||
|
// Capture stdout during DryRun
|
||||||
|
origStdout := os.Stdout
|
||||||
|
r, w, err := os.Pipe()
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("failed to create pipe: %v", err)
|
||||||
|
}
|
||||||
|
os.Stdout = w //nolint:reassign // redirect stdout to capture dry-run output in test
|
||||||
|
|
||||||
|
_, _ = p.run(t.Context(), []string{"info"}, runOptions{DryRun: true})
|
||||||
|
|
||||||
|
w.Close()
|
||||||
|
os.Stdout = origStdout //nolint:reassign // restore original stdout
|
||||||
|
|
||||||
|
var buf bytes.Buffer
|
||||||
|
if _, err := buf.ReadFrom(r); err != nil {
|
||||||
|
t.Fatalf("failed to read captured output: %v", err)
|
||||||
|
}
|
||||||
|
got := buf.String()
|
||||||
|
|
||||||
|
if !strings.HasPrefix(got, tt.expectedPrefix) {
|
||||||
|
t.Errorf("expected output to start with %q, got %q", tt.expectedPrefix, got)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestCommandExists(t *testing.T) {
|
func TestCommandExists(t *testing.T) {
|
||||||
// Test with a command that should exist on all systems
|
// Test with a command that should exist on all systems
|
||||||
if !commandExists("sh") {
|
if !commandExists("sh") {
|
||||||
|
|||||||
Reference in New Issue
Block a user