Initial push
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
package dkr
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"os"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/arescom/docker-migrate/internal/spec"
|
||||
)
|
||||
|
||||
// TestLiveInventory is a smoke test against whatever daemon the environment
|
||||
// points at. It is skipped unless DOCKER_MIGRATE_LIVE_TEST is set, because it
|
||||
// needs a real Docker host.
|
||||
func TestLiveInventory(t *testing.T) {
|
||||
if os.Getenv("DOCKER_MIGRATE_LIVE_TEST") == "" {
|
||||
t.Skip("set DOCKER_MIGRATE_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))
|
||||
}
|
||||
Reference in New Issue
Block a user