66 lines
1.6 KiB
Go
66 lines
1.6 KiB
Go
package docker
|
|
|
|
import (
|
|
"context"
|
|
"os"
|
|
"path/filepath"
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
// TestIntegrationPodman — dijalankan bila socket Podman tersedia
|
|
// (rootless: $XDG_RUNTIME_DIR/podman/podman.sock, atau rootful).
|
|
// Mengaktifkan socket rootless:
|
|
//
|
|
// systemctl --user enable --now podman.socket
|
|
func TestIntegrationPodman(t *testing.T) {
|
|
host := podmanSocket()
|
|
if host == "" {
|
|
t.Skip("socket podman tidak ada — lewati")
|
|
}
|
|
|
|
cl, info, err := Detect(host)
|
|
if err != nil {
|
|
t.Fatalf("Detect(%s): %v", host, err)
|
|
}
|
|
defer cl.Close()
|
|
if info.Name != "podman" {
|
|
t.Fatalf("nama engine harus podman, dapat %q", info.Name)
|
|
}
|
|
|
|
ctx, cancel := context.WithTimeout(context.Background(), 15*time.Second)
|
|
defer cancel()
|
|
i, err := cl.Info(ctx)
|
|
if err != nil {
|
|
t.Fatalf("Info: %v", err)
|
|
}
|
|
t.Logf("podman %s (API %s) · %d/%d kontainer berjalan · %d image",
|
|
i.ServerVersion, i.APIVersion, i.Running, i.Containers, i.Images)
|
|
|
|
items, err := cl.ListContainers(ctx)
|
|
if err != nil {
|
|
t.Fatalf("ListContainers: %v", err)
|
|
}
|
|
t.Logf("ListContainers: %d kontainer", len(items))
|
|
imgs, err := cl.ListImages(ctx)
|
|
if err != nil {
|
|
t.Fatalf("ListImages: %v", err)
|
|
}
|
|
t.Logf("ListImages: %d image", len(imgs))
|
|
}
|
|
|
|
// podmanSocket — kandidat socket podman yang benar-benar ada (kosong = tidak ada).
|
|
func podmanSocket() string {
|
|
var cands []string
|
|
if xdg := os.Getenv("XDG_RUNTIME_DIR"); xdg != "" {
|
|
cands = append(cands, filepath.Join(xdg, "podman", "podman.sock"))
|
|
}
|
|
cands = append(cands, "/run/podman/podman.sock")
|
|
for _, c := range cands {
|
|
if _, err := os.Stat(c); err == nil {
|
|
return "unix://" + c
|
|
}
|
|
}
|
|
return ""
|
|
}
|