move rootfstest to tartest
it's not "rootfs" or "docker" any more.
This commit is contained in:
parent
81db130c94
commit
ccd34cf34b
@ -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"],
|
||||
)
|
@ -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,
|
@ -1,4 +1,4 @@
|
||||
package rootfstest
|
||||
package tartest
|
||||
|
||||
import (
|
||||
"bytes"
|
@ -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",
|
||||
],
|
||||
|
@ -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)
|
||||
}
|
||||
|
@ -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 {
|
||||
|
Loading…
Reference in New Issue
Block a user