From 13b8605ba5f8554aedf658aacee5bc436887cbfa Mon Sep 17 00:00:00 2001 From: Nick White Date: Tue, 27 Jul 2021 11:31:50 +0100 Subject: internal/pipeline: Add notreadable test to CheckImages --- internal/pipeline/put_test.go | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'internal') diff --git a/internal/pipeline/put_test.go b/internal/pipeline/put_test.go index 68dd173..9cc8b02 100644 --- a/internal/pipeline/put_test.go +++ b/internal/pipeline/put_test.go @@ -6,6 +6,7 @@ package pipeline import ( "errors" + "os" "testing" ) @@ -16,11 +17,18 @@ func Test_CheckImages(t *testing.T) { }{ {"testdata/good", nil}, {"testdata/bad", errors.New("Decoding image testdata/bad/bad.png failed: png: invalid format: invalid checksum")}, - {"testdata/nonexistent", nil}, + {"testdata/notreadable", errors.New("Opening image testdata/notreadable/1.png failed: open testdata/notreadable/1.png: permission denied")}, } for _, c := range cases { t.Run(c.dir, func(t *testing.T) { + if c.dir == "testdata/notreadable" { + err := os.Chmod("testdata/notreadable/1.png", 0000) + if err != nil { + t.Fatalf("Error preparing test by setting file to be unreadable: %v", err) + } + } + err := CheckImages(c.dir) if err == nil && c.err != nil { t.Fatalf("Expected error '%v', got no error", c.err) @@ -31,6 +39,13 @@ func Test_CheckImages(t *testing.T) { if err != nil && c.err != nil && err.Error() != c.err.Error() { t.Fatalf("Got an unexpected error, expected '%v', got '%v'", c.err, err) } + + if c.dir == "testdata/notreadable" { + err := os.Chmod("testdata/notreadable/1.png", 0644) + if err != nil { + t.Fatalf("Error resetting test by setting file to be readable: %v", err) + } + } }) } } -- cgit v1.2.1-24-ge1ad