lazydocker/pkg/commands/socket_detection_windows_test.go
DeiAsPie cb517d9e09
Implement proper detection with Podman support and enhance error handling across platforms
Signed-off-by: DeiAsPie <93835541+DeiAsPie@users.noreply.github.com>
2025-12-27 13:19:14 +05:30

62 lines
1.7 KiB
Go

//go:build windows
package commands
import (
"context"
"errors"
"testing"
"github.com/sirupsen/logrus"
"github.com/stretchr/testify/assert"
)
func TestDetectPlatformCandidates_Windows_DockerSuccess(t *testing.T) {
oldValidate := validateSocketFunc
defer func() { validateSocketFunc = oldValidate }()
validateSocketFunc = func(ctx context.Context, host string, useEnv bool) error {
if host == "npipe:////./pipe/docker_engine" {
return nil
}
return errors.New("mock failure")
}
log := logrus.NewEntry(logrus.New())
host, runtime, err := detectPlatformCandidates(log)
assert.NoError(t, err)
assert.Equal(t, "npipe:////./pipe/docker_engine", host)
assert.Equal(t, RuntimeDocker, runtime)
}
func TestDetectPlatformCandidates_Windows_PodmanSuccess(t *testing.T) {
oldValidate := validateSocketFunc
defer func() { validateSocketFunc = oldValidate }()
validateSocketFunc = func(ctx context.Context, host string, useEnv bool) error {
if host == "npipe:////./pipe/podman-machine-default" {
return nil
}
return errors.New("mock failure")
}
log := logrus.NewEntry(logrus.New())
host, runtime, err := detectPlatformCandidates(log)
assert.NoError(t, err)
assert.Equal(t, "npipe:////./pipe/podman-machine-default", host)
assert.Equal(t, RuntimePodman, runtime)
}
func TestDetectPlatformCandidates_Windows_Failure(t *testing.T) {
oldValidate := validateSocketFunc
defer func() { validateSocketFunc = oldValidate }()
validateSocketFunc = func(ctx context.Context, host string, useEnv bool) error {
return errors.New("mock failure")
}
log := logrus.NewEntry(logrus.New())
_, _, err := detectPlatformCandidates(log)
assert.Error(t, err)
assert.Equal(t, ErrNoDockerSocket, err)
}