Files
DockMV/internal/dkr/inventory_live_test.go
kawaandClaude Sonnet 5 34e18987a0 Rename product to dockmv (container, image, module, env vars)
Container/image/service name, Go module path, CLI binary name, and
DOCKER_MIGRATE_* env vars still used the old working name; the project
is branded DockMV everywhere else (README, logo, Gitea repo).

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-08-11 13:56:26 +02:00

50 lines
1.3 KiB
Go

package dkr
import (
"context"
"encoding/json"
"os"
"testing"
"time"
"github.com/arescom/dockmv/internal/spec"
)
// TestLiveInventory is a smoke test against whatever daemon the environment
// points at. It is skipped unless DOCKMV_LIVE_TEST is set, because it
// needs a real Docker host.
func TestLiveInventory(t *testing.T) {
if os.Getenv("DOCKMV_LIVE_TEST") == "" {
t.Skip("set DOCKMV_LIVE_TEST=1 to run against the local daemon")
}
c, err := New("")
if err != nil {
t.Fatal(err)
}
defer c.Close()
ctx, cancel := context.WithTimeout(context.Background(), 60*time.Second)
defer cancel()
inv, err := c.Inventory(ctx)
if err != nil {
t.Fatal(err)
}
t.Logf("host=%s docker=%s containers=%d volumes=%d networks=%d warnings=%v",
inv.Host, inv.DockerVersion, len(inv.Containers), len(inv.Volumes), len(inv.Networks), inv.Warnings)
for i := range inv.Containers {
ct := &inv.Containers[i]
args := ct.CreateArgs(spec.RenderOptions{})
t.Logf("%s [%s] -> docker %s", ct.Name, ct.State, spec.ShellQuoteAll(args))
for _, m := range ct.DataMounts() {
t.Logf(" mount %-8s %-40s restore-into %s", m.Kind, m.Destination, RestorePath(m.Destination))
}
for _, w := range ct.Warnings {
t.Logf(" warn: %s", w)
}
}
b, _ := json.MarshalIndent(inv, "", " ")
t.Logf("inventory bytes: %d", len(b))
}