Skip to content

Commit

Permalink
test: assert layers correct when path changes type
Browse files Browse the repository at this point in the history
Signed-off-by: Will Murphy <[email protected]>
  • Loading branch information
willmurphyscode committed Nov 23, 2024
1 parent 00886bf commit aef21b8
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 0 deletions.
62 changes: 62 additions & 0 deletions test/integration/path_type_change_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package integration

import (
"testing"

"github.com/anchore/stereoscope/pkg/file"
"github.com/anchore/stereoscope/pkg/filetree/filenode"
"github.com/anchore/stereoscope/pkg/imagetest"
)

func TestPathTypeChangeImage(t *testing.T) {
image := imagetest.GetFixtureImage(t, "docker-archive", "image-path-type-change")

layerAssertions := []map[string]file.Type{
make(map[string]file.Type),
{
"/chimera/a.txt": file.TypeRegular,
"/chimera/b.txt": file.TypeRegular,
"/chimera": file.TypeDirectory,
},
{
"/chimera": file.TypeDirectory,
},
make(map[string]file.Type),
{
"/chimera": file.TypeRegular,
},
make(map[string]file.Type),
{
"/chimera": file.TypeSymLink,
},
make(map[string]file.Type),
{
"/chimera": file.TypeDirectory,
},
}

for idx, layer := range image.Layers {
assertions := layerAssertions[idx]
err := layer.SquashedTree.Walk(func(path file.Path, f filenode.FileNode) error {
expect, ok := assertions[string(path)]
if !ok {
return nil
}
if f.FileType != expect {
t.Errorf("at %v got %v want %v", path, f.FileType, expect)
}
delete(assertions, string(path))
return nil
}, nil)
if err != nil {
t.Error(err)
}
}
for i, a := range layerAssertions {
if len(a) > 0 {
for k, v := range a {
t.Errorf("for layer %v, never saw %v of type %v", i, k, v)
}
}
}
}
20 changes: 20 additions & 0 deletions test/integration/test-fixtures/image-path-type-change/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
FROM busybox:1.37.0@sha256:db142d433cdde11f10ae479dbf92f3b13d693fd1c91053da9979728cceb1dc68

# makes /chimera/a.txt /chimera/b.txt
COPY . /

# make a layer where the dir is empty
RUN rm /chimera/a.txt /chimera/b.txt

RUN rmdir /chimera

RUN touch /chimera

RUN rm /chimera

RUN ln -s /etc/hostname /chimera

RUN unlink /chimera

RUN mkdir /chimera

Empty file.
Empty file.

0 comments on commit aef21b8

Please sign in to comment.