-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: assert layers correct when path changes type
Signed-off-by: Will Murphy <[email protected]>
- Loading branch information
1 parent
00886bf
commit aef21b8
Showing
4 changed files
with
82 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
20
test/integration/test-fixtures/image-path-type-change/Dockerfile
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.