diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-16 16:20:50 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-16 16:20:50 +0000 |
commit | 318b0d0e7515e0a97e647906387ecf89455f3878 (patch) | |
tree | 905dcee34012fd33308dbfda2f7114343dd36e8b /check_test.go | |
parent | Initial commit. (diff) | |
download | golang-github-containers-storage-318b0d0e7515e0a97e647906387ecf89455f3878.tar.xz golang-github-containers-storage-318b0d0e7515e0a97e647906387ecf89455f3878.zip |
Adding upstream version 1.51.0+ds1.upstream/1.51.0+ds1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'check_test.go')
-rw-r--r-- | check_test.go | 101 |
1 files changed, 101 insertions, 0 deletions
diff --git a/check_test.go b/check_test.go new file mode 100644 index 0000000..2b37cf3 --- /dev/null +++ b/check_test.go @@ -0,0 +1,101 @@ +package storage + +import ( + "archive/tar" + "sort" + "testing" + + "github.com/containers/storage/pkg/archive" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" +) + +func TestCheckDirectory(t *testing.T) { + vectors := []struct { + description string + headers []tar.Header + expected []string + }{ + { + description: "basic", + headers: []tar.Header{ + {Name: "a", Typeflag: tar.TypeDir}, + }, + expected: []string{ + "a/", + }, + }, + { + description: "whiteout", + headers: []tar.Header{ + {Name: "a", Typeflag: tar.TypeDir}, + {Name: "a/b", Typeflag: tar.TypeDir}, + {Name: "a/b/c", Typeflag: tar.TypeReg}, + {Name: "a/b/d", Typeflag: tar.TypeReg}, + {Name: "a/b/" + archive.WhiteoutPrefix + "c", Typeflag: tar.TypeReg}, + }, + expected: []string{ + "a/", + "a/b/", + "a/b/d", + }, + }, + { + description: "opaque", + headers: []tar.Header{ + {Name: "a", Typeflag: tar.TypeDir}, + {Name: "a/b", Typeflag: tar.TypeDir}, + {Name: "a/b/c", Typeflag: tar.TypeReg}, + {Name: "a/b/d", Typeflag: tar.TypeReg}, + {Name: "a/b/" + archive.WhiteoutOpaqueDir, Typeflag: tar.TypeReg}, + }, + expected: []string{ + "a/", + "a/b/", + }, + }, + } + for i := range vectors { + t.Run(vectors[i].description, func(t *testing.T) { + cd := newCheckDirectoryDefaults() + for _, hdr := range vectors[i].headers { + cd.header(&hdr) + } + actual := cd.names() + sort.Strings(actual) + expected := append([]string{}, vectors[i].expected...) + sort.Strings(expected) + assert.Equal(t, expected, actual) + }) + } +} + +func TestCheckDetectWriteable(t *testing.T) { + var sawRWlayers, sawRWimages bool + stoar, err := GetStore(StoreOptions{ + RunRoot: t.TempDir(), + GraphRoot: t.TempDir(), + GraphDriverName: "vfs", + }) + require.NoError(t, err, "unexpected error initializing test store") + s, ok := stoar.(*store) + require.True(t, ok, "unexpected error making type assertion") + _, done, err := readAllLayerStores(s, func(store roLayerStore) (struct{}, bool, error) { + if roLayerStoreIsReallyReadWrite(store) { // implicitly checking that the type assertion in this function doesn't panic + sawRWlayers = true + } + return struct{}{}, false, nil + }) + assert.False(t, done, "unexpected error from readAllLayerStores") + assert.NoError(t, err, "unexpected error from readAllLayerStores") + assert.True(t, sawRWlayers, "unexpected error detecting which layer store is writeable") + _, done, err = readAllImageStores(s, func(store roImageStore) (struct{}, bool, error) { + if roImageStoreIsReallyReadWrite(store) { // implicitly checking that the type assertion in this function doesn't panic + sawRWimages = true + } + return struct{}{}, false, nil + }) + assert.False(t, done, "unexpected error from readAllImageStores") + assert.NoError(t, err, "unexpected error from readAllImageStores") + assert.True(t, sawRWimages, "unexpected error detecting which image store is writeable") +} |