diff --git a/rootfs/rootfstest/BUILD b/internal/tartest/BUILD similarity index 73% rename from rootfs/rootfstest/BUILD rename to internal/tartest/BUILD index 113a9d5..72b2532 100644 --- a/rootfs/rootfstest/BUILD +++ b/internal/tartest/BUILD @@ -2,15 +2,15 @@ load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test") go_library( name = "go_default_library", - srcs = ["rootfstest.go"], - importpath = "github.com/motiejus/code/undocker/rootfs/rootfstest", + srcs = ["tartest.go"], + importpath = "github.com/motiejus/code/undocker/internal/tartest", visibility = ["//visibility:public"], deps = ["@com_github_stretchr_testify//require:go_default_library"], ) go_test( name = "go_default_test", - srcs = ["rootfstest_test.go"], + srcs = ["tartest_test.go"], embed = [":go_default_library"], deps = ["@com_github_stretchr_testify//assert:go_default_library"], ) diff --git a/rootfs/rootfstest/rootfstest.go b/internal/tartest/tartest.go similarity index 85% rename from rootfs/rootfstest/rootfstest.go rename to internal/tartest/tartest.go index e9b7063..6b1bb72 100644 --- a/rootfs/rootfstest/rootfstest.go +++ b/internal/tartest/tartest.go @@ -1,9 +1,8 @@ -package rootfstest +package tartest import ( "archive/tar" "bytes" - "encoding/json" "io" "testing" @@ -32,16 +31,10 @@ type ( Contents *bytes.Buffer } - Manifest []string - Hardlink struct { Name string Uid int } - - dockerManifestJSON []struct { - Layers []string `json:"Layers"` - } ) func (tb Tarball) Buffer() *bytes.Buffer { @@ -85,17 +78,6 @@ func (f File) Tar(tw *tar.Writer) error { return nil } -func (m Manifest) Tar(tw *tar.Writer) error { - b, err := json.Marshal(dockerManifestJSON{{Layers: m}}) - if err != nil { - return err - } - return File{ - Name: "manifest.json", - Contents: bytes.NewBuffer(b), - }.Tar(tw) -} - func (h Hardlink) Tar(tw *tar.Writer) error { return tw.WriteHeader(&tar.Header{ Typeflag: tar.TypeLink, diff --git a/rootfs/rootfstest/rootfstest_test.go b/internal/tartest/tartest_test.go similarity index 97% rename from rootfs/rootfstest/rootfstest_test.go rename to internal/tartest/tartest_test.go index f6c7d1c..5596ef8 100644 --- a/rootfs/rootfstest/rootfstest_test.go +++ b/internal/tartest/tartest_test.go @@ -1,4 +1,4 @@ -package rootfstest +package tartest import ( "bytes" diff --git a/rootfs/BUILD b/rootfs/BUILD index f366c67..978f0b9 100644 --- a/rootfs/BUILD +++ b/rootfs/BUILD @@ -20,7 +20,7 @@ go_test( ], embed = [":go_default_library"], deps = [ - "//src/undocker/rootfs/rootfstest:go_default_library", + "//src/undocker/internal/tartest:go_default_library", "@com_github_stretchr_testify//assert:go_default_library", "@com_github_stretchr_testify//require:go_default_library", ], diff --git a/rootfs/rootfs_test.go b/rootfs/rootfs_test.go index 8353f3a..bc9acd1 100644 --- a/rootfs/rootfs_test.go +++ b/rootfs/rootfs_test.go @@ -1,25 +1,22 @@ package rootfs import ( + "archive/tar" "bytes" + "encoding/json" "testing" - "github.com/motiejus/code/undocker/rootfs/rootfstest" + "github.com/motiejus/code/undocker/internal/tartest" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) type ( - file = rootfstest.File - dir = rootfstest.Dir - hardlink = rootfstest.Hardlink - manifest = rootfstest.Manifest - extractable = rootfstest.Extractable - tarball = rootfstest.Tarball -) - -var ( - extract = rootfstest.Extract + file = tartest.File + dir = tartest.Dir + hardlink = tartest.Hardlink + extractable = tartest.Extractable + tarball = tartest.Tarball ) func TestRootFS(t *testing.T) { @@ -183,8 +180,24 @@ func TestRootFS(t *testing.T) { return } require.NoError(t, err) - got := extract(t, &out) + got := tartest.Extract(t, &out) assert.Equal(t, tt.want, got) }) } } + +// Helpers +type ( + manifest []string +) + +func (m manifest) Tar(tw *tar.Writer) error { + b, err := json.Marshal(dockerManifestJSON{{Layers: m}}) + if err != nil { + return err + } + return file{ + Name: "manifest.json", + Contents: bytes.NewBuffer(b), + }.Tar(tw) +} diff --git a/rootfs/tree.go b/rootfs/tree.go index 6c7a7a0..50079c9 100644 --- a/rootfs/tree.go +++ b/rootfs/tree.go @@ -15,7 +15,7 @@ type tree struct { end bool } -// New creates a new tree from a given path. +// newTree creates a new tree from a given path. func newTree(paths ...string) *tree { t := &tree{name: ".", children: []*tree{}} for _, path := range paths {