Use assertions in image package unit tests.

Signed-off-by: Daniel Nephin <dnephin@docker.com>
This commit is contained in:
Daniel Nephin 2017-03-03 12:38:06 -05:00
parent 9ea5e02e92
commit 69d7362058
3 changed files with 192 additions and 451 deletions

View file

@ -11,79 +11,51 @@ import (
"path/filepath"
"testing"
"github.com/docker/docker/pkg/testutil/assert"
"github.com/opencontainers/go-digest"
)
func TestFSGetSet(t *testing.T) {
func defaultFSStoreBackend(t *testing.T) (StoreBackend, func()) {
tmpdir, err := ioutil.TempDir("", "images-fs-store")
if err != nil {
t.Fatal(err)
}
defer os.RemoveAll(tmpdir)
fs, err := NewFSStoreBackend(tmpdir)
if err != nil {
t.Fatal(err)
}
assert.NilError(t, err)
testGetSet(t, fs)
fsBackend, err := NewFSStoreBackend(tmpdir)
assert.NilError(t, err)
return fsBackend, func() { os.RemoveAll(tmpdir) }
}
func TestFSGetInvalidData(t *testing.T) {
tmpdir, err := ioutil.TempDir("", "images-fs-store")
if err != nil {
t.Fatal(err)
}
defer os.RemoveAll(tmpdir)
fs, err := NewFSStoreBackend(tmpdir)
if err != nil {
t.Fatal(err)
}
store, cleanup := defaultFSStoreBackend(t)
defer cleanup()
id, err := fs.Set([]byte("foobar"))
if err != nil {
t.Fatal(err)
}
id, err := store.Set([]byte("foobar"))
assert.NilError(t, err)
dgst := digest.Digest(id)
if err := ioutil.WriteFile(filepath.Join(tmpdir, contentDirName, string(dgst.Algorithm()), dgst.Hex()), []byte("foobar2"), 0600); err != nil {
t.Fatal(err)
}
err = ioutil.WriteFile(filepath.Join(store.(*fs).root, contentDirName, string(dgst.Algorithm()), dgst.Hex()), []byte("foobar2"), 0600)
assert.NilError(t, err)
_, err = fs.Get(id)
if err == nil {
t.Fatal("expected get to fail after data modification.")
}
_, err = store.Get(id)
assert.Error(t, err, "failed to verify")
}
func TestFSInvalidSet(t *testing.T) {
tmpdir, err := ioutil.TempDir("", "images-fs-store")
if err != nil {
t.Fatal(err)
}
defer os.RemoveAll(tmpdir)
fs, err := NewFSStoreBackend(tmpdir)
if err != nil {
t.Fatal(err)
}
store, cleanup := defaultFSStoreBackend(t)
defer cleanup()
id := digest.FromBytes([]byte("foobar"))
err = os.Mkdir(filepath.Join(tmpdir, contentDirName, string(id.Algorithm()), id.Hex()), 0700)
if err != nil {
t.Fatal(err)
}
err := os.Mkdir(filepath.Join(store.(*fs).root, contentDirName, string(id.Algorithm()), id.Hex()), 0700)
assert.NilError(t, err)
_, err = fs.Set([]byte("foobar"))
if err == nil {
t.Fatal("expected error from invalid filesystem data.")
}
_, err = store.Set([]byte("foobar"))
assert.Error(t, err, "is a directory")
}
func TestFSInvalidRoot(t *testing.T) {
tmpdir, err := ioutil.TempDir("", "images-fs-store")
if err != nil {
t.Fatal(err)
}
assert.NilError(t, err)
defer os.RemoveAll(tmpdir)
tcases := []struct {
@ -98,34 +70,29 @@ func TestFSInvalidRoot(t *testing.T) {
root := filepath.Join(tmpdir, tc.root)
filePath := filepath.Join(tmpdir, tc.invalidFile)
err := os.MkdirAll(filepath.Dir(filePath), 0700)
if err != nil {
t.Fatal(err)
}
assert.NilError(t, err)
f, err := os.Create(filePath)
if err != nil {
t.Fatal(err)
}
f.Close()
defer f.Close()
assert.NilError(t, err)
_, err = NewFSStoreBackend(root)
if err == nil {
t.Fatalf("expected error from root %q and invalid file %q", tc.root, tc.invalidFile)
}
assert.Error(t, err, "not a directory")
os.RemoveAll(root)
}
}
func testMetadataGetSet(t *testing.T, store StoreBackend) {
func TestFSMetadataGetSet(t *testing.T) {
store, cleanup := defaultFSStoreBackend(t)
defer cleanup()
id, err := store.Set([]byte("foo"))
if err != nil {
t.Fatal(err)
}
assert.NilError(t, err)
id2, err := store.Set([]byte("bar"))
if err != nil {
t.Fatal(err)
}
assert.NilError(t, err)
tcases := []struct {
id digest.Digest
@ -139,115 +106,51 @@ func testMetadataGetSet(t *testing.T, store StoreBackend) {
for _, tc := range tcases {
err = store.SetMetadata(tc.id, tc.key, tc.value)
if err != nil {
t.Fatal(err)
}
assert.NilError(t, err)
actual, err := store.GetMetadata(tc.id, tc.key)
if err != nil {
t.Fatal(err)
}
assert.NilError(t, err)
if bytes.Compare(actual, tc.value) != 0 {
t.Fatalf("Metadata expected %q, got %q", tc.value, actual)
}
}
_, err = store.GetMetadata(id2, "tkey2")
if err == nil {
t.Fatal("expected error for getting metadata for unknown key")
}
assert.Error(t, err, "no such file or directory")
id3 := digest.FromBytes([]byte("baz"))
err = store.SetMetadata(id3, "tkey", []byte("tval"))
if err == nil {
t.Fatal("expected error for setting metadata for unknown ID.")
}
assert.Error(t, err, "no such file or directory")
_, err = store.GetMetadata(id3, "tkey")
if err == nil {
t.Fatal("expected error for getting metadata for unknown ID.")
}
}
func TestFSMetadataGetSet(t *testing.T) {
tmpdir, err := ioutil.TempDir("", "images-fs-store")
if err != nil {
t.Fatal(err)
}
defer os.RemoveAll(tmpdir)
fs, err := NewFSStoreBackend(tmpdir)
if err != nil {
t.Fatal(err)
}
testMetadataGetSet(t, fs)
}
func TestFSDelete(t *testing.T) {
tmpdir, err := ioutil.TempDir("", "images-fs-store")
if err != nil {
t.Fatal(err)
}
defer os.RemoveAll(tmpdir)
fs, err := NewFSStoreBackend(tmpdir)
if err != nil {
t.Fatal(err)
}
testDelete(t, fs)
}
func TestFSWalker(t *testing.T) {
tmpdir, err := ioutil.TempDir("", "images-fs-store")
if err != nil {
t.Fatal(err)
}
defer os.RemoveAll(tmpdir)
fs, err := NewFSStoreBackend(tmpdir)
if err != nil {
t.Fatal(err)
}
testWalker(t, fs)
assert.Error(t, err, "no such file or directory")
}
func TestFSInvalidWalker(t *testing.T) {
tmpdir, err := ioutil.TempDir("", "images-fs-store")
if err != nil {
t.Fatal(err)
}
defer os.RemoveAll(tmpdir)
fs, err := NewFSStoreBackend(tmpdir)
if err != nil {
t.Fatal(err)
}
store, cleanup := defaultFSStoreBackend(t)
defer cleanup()
fooID, err := fs.Set([]byte("foo"))
if err != nil {
t.Fatal(err)
}
fooID, err := store.Set([]byte("foo"))
assert.NilError(t, err)
if err := ioutil.WriteFile(filepath.Join(tmpdir, contentDirName, "sha256/foobar"), []byte("foobar"), 0600); err != nil {
t.Fatal(err)
}
err = ioutil.WriteFile(filepath.Join(store.(*fs).root, contentDirName, "sha256/foobar"), []byte("foobar"), 0600)
assert.NilError(t, err)
n := 0
err = fs.Walk(func(id digest.Digest) error {
if id != fooID {
t.Fatalf("invalid walker ID %q, expected %q", id, fooID)
}
err = store.Walk(func(id digest.Digest) error {
assert.Equal(t, id, fooID)
n++
return nil
})
if err != nil {
t.Fatalf("invalid data should not have caused walker error, got %v", err)
}
if n != 1 {
t.Fatalf("expected 1 walk initialization, got %d", n)
}
assert.NilError(t, err)
assert.Equal(t, n, 1)
}
func testGetSet(t *testing.T, store StoreBackend) {
func TestFSGetSet(t *testing.T) {
store, cleanup := defaultFSStoreBackend(t)
defer cleanup()
type tcase struct {
input []byte
expected digest.Digest
@ -258,15 +161,13 @@ func testGetSet(t *testing.T, store StoreBackend) {
randomInput := make([]byte, 8*1024)
_, err := rand.Read(randomInput)
if err != nil {
t.Fatal(err)
}
assert.NilError(t, err)
// skipping use of digest pkg because it is used by the implementation
h := sha256.New()
_, err = h.Write(randomInput)
if err != nil {
t.Fatal(err)
}
assert.NilError(t, err)
tcases = append(tcases, tcase{
input: randomInput,
expected: digest.Digest("sha256:" + hex.EncodeToString(h.Sum(nil))),
@ -274,83 +175,74 @@ func testGetSet(t *testing.T, store StoreBackend) {
for _, tc := range tcases {
id, err := store.Set([]byte(tc.input))
if err != nil {
t.Fatal(err)
}
if id != tc.expected {
t.Fatalf("expected ID %q, got %q", tc.expected, id)
}
}
for _, emptyData := range [][]byte{nil, {}} {
_, err := store.Set(emptyData)
if err == nil {
t.Fatal("expected error for nil input.")
}
assert.NilError(t, err)
assert.Equal(t, id, tc.expected)
}
for _, tc := range tcases {
data, err := store.Get(tc.expected)
if err != nil {
t.Fatal(err)
}
assert.NilError(t, err)
if bytes.Compare(data, tc.input) != 0 {
t.Fatalf("expected data %q, got %q", tc.input, data)
}
}
}
func TestFSGetUnsetKey(t *testing.T) {
store, cleanup := defaultFSStoreBackend(t)
defer cleanup()
for _, key := range []digest.Digest{"foobar:abc", "sha256:abc", "sha256:c3ab8ff13720e8ad9047dd39466b3c8974e592c2fa383d4a3960714caef0c4f2a"} {
_, err := store.Get(key)
if err == nil {
t.Fatalf("expected error for ID %q.", key)
}
assert.Error(t, err, "no such file or directory")
}
}
func testDelete(t *testing.T, store StoreBackend) {
func TestFSGetEmptyData(t *testing.T) {
store, cleanup := defaultFSStoreBackend(t)
defer cleanup()
for _, emptyData := range [][]byte{nil, {}} {
_, err := store.Set(emptyData)
assert.Error(t, err, "invalid empty data")
}
}
func TestFSDelete(t *testing.T) {
store, cleanup := defaultFSStoreBackend(t)
defer cleanup()
id, err := store.Set([]byte("foo"))
if err != nil {
t.Fatal(err)
}
assert.NilError(t, err)
id2, err := store.Set([]byte("bar"))
if err != nil {
t.Fatal(err)
}
assert.NilError(t, err)
err = store.Delete(id)
if err != nil {
t.Fatal(err)
}
assert.NilError(t, err)
_, err = store.Get(id)
if err == nil {
t.Fatalf("expected getting deleted item %q to fail", id)
}
assert.Error(t, err, "no such file or directory")
_, err = store.Get(id2)
if err != nil {
t.Fatal(err)
}
assert.NilError(t, err)
err = store.Delete(id2)
if err != nil {
t.Fatal(err)
}
assert.NilError(t, err)
_, err = store.Get(id2)
if err == nil {
t.Fatalf("expected getting deleted item %q to fail", id2)
}
assert.Error(t, err, "no such file or directory")
}
func testWalker(t *testing.T, store StoreBackend) {
func TestFSWalker(t *testing.T) {
store, cleanup := defaultFSStoreBackend(t)
defer cleanup()
id, err := store.Set([]byte("foo"))
if err != nil {
t.Fatal(err)
}
assert.NilError(t, err)
id2, err := store.Set([]byte("bar"))
if err != nil {
t.Fatal(err)
}
assert.NilError(t, err)
tcases := make(map[digest.Digest]struct{})
tcases[id] = struct{}{}
@ -361,24 +253,22 @@ func testWalker(t *testing.T, store StoreBackend) {
n++
return nil
})
if err != nil {
t.Fatal(err)
}
assert.NilError(t, err)
assert.Equal(t, n, 2)
assert.Equal(t, len(tcases), 0)
}
if n != 2 {
t.Fatalf("expected 2 walk initializations, got %d", n)
}
if len(tcases) != 0 {
t.Fatalf("expected empty unwalked set, got %+v", tcases)
}
func TestFSWalkerStopOnError(t *testing.T) {
store, cleanup := defaultFSStoreBackend(t)
defer cleanup()
// stop on error
tcases = make(map[digest.Digest]struct{})
id, err := store.Set([]byte("foo"))
assert.NilError(t, err)
tcases := make(map[digest.Digest]struct{})
tcases[id] = struct{}{}
err = store.Walk(func(id digest.Digest) error {
return errors.New("")
return errors.New("what")
})
if err == nil {
t.Fatalf("expected error from walker.")
}
assert.Error(t, err, "what")
}

View file

@ -5,6 +5,8 @@ import (
"sort"
"strings"
"testing"
"github.com/docker/docker/pkg/testutil/assert"
)
const sampleImageJSON = `{
@ -17,22 +19,15 @@ const sampleImageJSON = `{
}
}`
func TestJSON(t *testing.T) {
func TestNewFromJSON(t *testing.T) {
img, err := NewFromJSON([]byte(sampleImageJSON))
if err != nil {
t.Fatal(err)
}
rawJSON := img.RawJSON()
if string(rawJSON) != sampleImageJSON {
t.Fatalf("raw JSON of config didn't match: expected %+v, got %v", sampleImageJSON, rawJSON)
}
assert.NilError(t, err)
assert.Equal(t, string(img.RawJSON()), sampleImageJSON)
}
func TestInvalidJSON(t *testing.T) {
func TestNewFromJSONWithInvalidJSON(t *testing.T) {
_, err := NewFromJSON([]byte("{}"))
if err == nil {
t.Fatal("expected JSON parse error")
}
assert.Error(t, err, "invalid image JSON, no RootFS key")
}
func TestMarshalKeyOrder(t *testing.T) {
@ -43,9 +38,7 @@ func TestMarshalKeyOrder(t *testing.T) {
Architecture: "c",
},
})
if err != nil {
t.Fatal(err)
}
assert.NilError(t, err)
expectedOrder := []string{"architecture", "author", "comment"}
var indexes []int

View file

@ -1,292 +1,150 @@
package image
import (
"io/ioutil"
"os"
"testing"
"github.com/docker/docker/layer"
"github.com/docker/docker/pkg/testutil/assert"
"github.com/opencontainers/go-digest"
)
func TestRestore(t *testing.T) {
tmpdir, err := ioutil.TempDir("", "images-fs-store")
if err != nil {
t.Fatal(err)
}
defer os.RemoveAll(tmpdir)
fs, err := NewFSStoreBackend(tmpdir)
if err != nil {
t.Fatal(err)
}
fs, cleanup := defaultFSStoreBackend(t)
defer cleanup()
id1, err := fs.Set([]byte(`{"comment": "abc", "rootfs": {"type": "layers"}}`))
if err != nil {
t.Fatal(err)
}
assert.NilError(t, err)
_, err = fs.Set([]byte(`invalid`))
if err != nil {
t.Fatal(err)
}
assert.NilError(t, err)
id2, err := fs.Set([]byte(`{"comment": "def", "rootfs": {"type": "layers", "diff_ids": ["2c26b46b68ffc68ff99b453c1d30413413422d706483bfa0f98a5e886266e7ae"]}}`))
if err != nil {
t.Fatal(err)
}
assert.NilError(t, err)
err = fs.SetMetadata(id2, "parent", []byte(id1))
if err != nil {
t.Fatal(err)
}
assert.NilError(t, err)
is, err := NewImageStore(fs, &mockLayerGetReleaser{})
if err != nil {
t.Fatal(err)
}
assert.NilError(t, err)
imgs := is.Map()
if actual, expected := len(imgs), 2; actual != expected {
t.Fatalf("invalid images length, expected 2, got %q", len(imgs))
}
assert.Equal(t, len(is.Map()), 2)
img1, err := is.Get(ID(id1))
if err != nil {
t.Fatal(err)
}
if actual, expected := img1.computedID, ID(id1); actual != expected {
t.Fatalf("invalid image ID: expected %q, got %q", expected, actual)
}
if actual, expected := img1.computedID.String(), string(id1); actual != expected {
t.Fatalf("invalid image ID string: expected %q, got %q", expected, actual)
}
assert.NilError(t, err)
assert.Equal(t, img1.computedID, ID(id1))
assert.Equal(t, img1.computedID.String(), string(id1))
img2, err := is.Get(ID(id2))
if err != nil {
t.Fatal(err)
}
if actual, expected := img1.Comment, "abc"; actual != expected {
t.Fatalf("invalid comment for image1: expected %q, got %q", expected, actual)
}
if actual, expected := img2.Comment, "def"; actual != expected {
t.Fatalf("invalid comment for image2: expected %q, got %q", expected, actual)
}
assert.NilError(t, err)
assert.Equal(t, img1.Comment, "abc")
assert.Equal(t, img2.Comment, "def")
p, err := is.GetParent(ID(id1))
if err == nil {
t.Fatal("expected error for getting parent")
}
assert.Error(t, err, "no such file")
p, err = is.GetParent(ID(id2))
if err != nil {
t.Fatal(err)
}
if actual, expected := p, ID(id1); actual != expected {
t.Fatalf("invalid parent: expected %q, got %q", expected, actual)
}
assert.NilError(t, err)
assert.Equal(t, p, ID(id1))
children := is.Children(ID(id1))
if len(children) != 1 {
t.Fatalf("invalid children length: %q", len(children))
}
if actual, expected := children[0], ID(id2); actual != expected {
t.Fatalf("invalid child for id1: expected %q, got %q", expected, actual)
}
heads := is.Heads()
if actual, expected := len(heads), 1; actual != expected {
t.Fatalf("invalid images length: expected %q, got %q", expected, actual)
}
assert.Equal(t, len(children), 1)
assert.Equal(t, children[0], ID(id2))
assert.Equal(t, len(is.Heads()), 1)
sid1, err := is.Search(string(id1)[:10])
if err != nil {
t.Fatal(err)
}
if actual, expected := sid1, ID(id1); actual != expected {
t.Fatalf("searched ID mismatch: expected %q, got %q", expected, actual)
}
assert.NilError(t, err)
assert.Equal(t, sid1, ID(id1))
sid1, err = is.Search(digest.Digest(id1).Hex()[:6])
if err != nil {
t.Fatal(err)
}
if actual, expected := sid1, ID(id1); actual != expected {
t.Fatalf("searched ID mismatch: expected %q, got %q", expected, actual)
}
assert.NilError(t, err)
assert.Equal(t, sid1, ID(id1))
invalidPattern := digest.Digest(id1).Hex()[1:6]
_, err = is.Search(invalidPattern)
if err == nil {
t.Fatalf("expected search for %q to fail", invalidPattern)
}
assert.Error(t, err, "No such image")
}
func TestAddDelete(t *testing.T) {
tmpdir, err := ioutil.TempDir("", "images-fs-store")
if err != nil {
t.Fatal(err)
}
defer os.RemoveAll(tmpdir)
fs, err := NewFSStoreBackend(tmpdir)
if err != nil {
t.Fatal(err)
}
is, err := NewImageStore(fs, &mockLayerGetReleaser{})
if err != nil {
t.Fatal(err)
}
is, cleanup := defaultImageStore(t)
defer cleanup()
id1, err := is.Create([]byte(`{"comment": "abc", "rootfs": {"type": "layers", "diff_ids": ["2c26b46b68ffc68ff99b453c1d30413413422d706483bfa0f98a5e886266e7ae"]}}`))
if err != nil {
t.Fatal(err)
}
if actual, expected := id1, ID("sha256:8d25a9c45df515f9d0fe8e4a6b1c64dd3b965a84790ddbcc7954bb9bc89eb993"); actual != expected {
t.Fatalf("create ID mismatch: expected %q, got %q", expected, actual)
}
assert.NilError(t, err)
assert.Equal(t, id1, ID("sha256:8d25a9c45df515f9d0fe8e4a6b1c64dd3b965a84790ddbcc7954bb9bc89eb993"))
img, err := is.Get(id1)
if err != nil {
t.Fatal(err)
}
if actual, expected := img.Comment, "abc"; actual != expected {
t.Fatalf("invalid comment in image: expected %q, got %q", expected, actual)
}
assert.NilError(t, err)
assert.Equal(t, img.Comment, "abc")
id2, err := is.Create([]byte(`{"comment": "def", "rootfs": {"type": "layers", "diff_ids": ["2c26b46b68ffc68ff99b453c1d30413413422d706483bfa0f98a5e886266e7ae"]}}`))
if err != nil {
t.Fatal(err)
}
assert.NilError(t, err)
err = is.SetParent(id2, id1)
if err != nil {
t.Fatal(err)
}
assert.NilError(t, err)
pid1, err := is.GetParent(id2)
if err != nil {
t.Fatal(err)
}
if actual, expected := pid1, id1; actual != expected {
t.Fatalf("invalid parent for image: expected %q, got %q", expected, actual)
}
assert.NilError(t, err)
assert.Equal(t, pid1, id1)
_, err = is.Delete(id1)
if err != nil {
t.Fatal(err)
}
_, err = is.Get(id1)
if err == nil {
t.Fatalf("expected get for deleted image %q to fail", id1)
}
_, err = is.Get(id2)
if err != nil {
t.Fatal(err)
}
pid1, err = is.GetParent(id2)
if err == nil {
t.Fatalf("expected parent check for image %q to fail, got %q", id2, pid1)
}
assert.NilError(t, err)
_, err = is.Get(id1)
assert.Error(t, err, "no such file or directory")
_, err = is.Get(id2)
assert.NilError(t, err)
_, err = is.GetParent(id2)
assert.Error(t, err, "no such file or directory")
}
func TestSearchAfterDelete(t *testing.T) {
tmpdir, err := ioutil.TempDir("", "images-fs-store")
if err != nil {
t.Fatal(err)
}
defer os.RemoveAll(tmpdir)
fs, err := NewFSStoreBackend(tmpdir)
if err != nil {
t.Fatal(err)
}
is, err := NewImageStore(fs, &mockLayerGetReleaser{})
if err != nil {
t.Fatal(err)
}
is, cleanup := defaultImageStore(t)
defer cleanup()
id, err := is.Create([]byte(`{"comment": "abc", "rootfs": {"type": "layers"}}`))
if err != nil {
t.Fatal(err)
}
assert.NilError(t, err)
id1, err := is.Search(string(id)[:15])
if err != nil {
t.Fatal(err)
}
assert.NilError(t, err)
assert.Equal(t, id1, id)
if actual, expected := id1, id; expected != actual {
t.Fatalf("wrong id returned from search: expected %q, got %q", expected, actual)
}
_, err = is.Delete(id)
assert.NilError(t, err)
if _, err := is.Delete(id); err != nil {
t.Fatal(err)
}
if _, err := is.Search(string(id)[:15]); err == nil {
t.Fatal("expected search after deletion to fail")
}
_, err = is.Search(string(id)[:15])
assert.Error(t, err, "No such image")
}
func TestParentReset(t *testing.T) {
tmpdir, err := ioutil.TempDir("", "images-fs-store")
if err != nil {
t.Fatal(err)
}
defer os.RemoveAll(tmpdir)
fs, err := NewFSStoreBackend(tmpdir)
if err != nil {
t.Fatal(err)
}
is, err := NewImageStore(fs, &mockLayerGetReleaser{})
if err != nil {
t.Fatal(err)
}
is, cleanup := defaultImageStore(t)
defer cleanup()
id, err := is.Create([]byte(`{"comment": "abc1", "rootfs": {"type": "layers"}}`))
if err != nil {
t.Fatal(err)
}
assert.NilError(t, err)
id2, err := is.Create([]byte(`{"comment": "abc2", "rootfs": {"type": "layers"}}`))
if err != nil {
t.Fatal(err)
}
assert.NilError(t, err)
id3, err := is.Create([]byte(`{"comment": "abc3", "rootfs": {"type": "layers"}}`))
if err != nil {
t.Fatal(err)
}
assert.NilError(t, err)
if err := is.SetParent(id, id2); err != nil {
t.Fatal(err)
}
assert.NilError(t, is.SetParent(id, id2))
assert.Equal(t, len(is.Children(id2)), 1)
ids := is.Children(id2)
if actual, expected := len(ids), 1; expected != actual {
t.Fatalf("wrong number of children: %d, got %d", expected, actual)
}
assert.NilError(t, is.SetParent(id, id3))
assert.Equal(t, len(is.Children(id2)), 0)
assert.Equal(t, len(is.Children(id3)), 1)
}
if err := is.SetParent(id, id3); err != nil {
t.Fatal(err)
}
func defaultImageStore(t *testing.T) (Store, func()) {
fsBackend, cleanup := defaultFSStoreBackend(t)
ids = is.Children(id2)
if actual, expected := len(ids), 0; expected != actual {
t.Fatalf("wrong number of children after parent reset: %d, got %d", expected, actual)
}
ids = is.Children(id3)
if actual, expected := len(ids), 1; expected != actual {
t.Fatalf("wrong number of children after parent reset: %d, got %d", expected, actual)
}
store, err := NewImageStore(fsBackend, &mockLayerGetReleaser{})
assert.NilError(t, err)
return store, cleanup
}
type mockLayerGetReleaser struct{}