@@ -2,13 +2,14 @@ package manifest_test
22
33import (
44 "errors"
5+ "strings"
56 "testing"
67
78 "github.com/docker-library/bashbrew/manifest"
89)
910
1011func TestFetchErrors (t * testing.T ) {
11- repoName , tagName , _ , err := manifest .Fetch ("testdata " , "bash:69.420" )
12+ repoName , tagName , _ , err := manifest .Fetch ("/dev/null " , "testdata/ bash:69.420" )
1213 if err == nil {
1314 t .Fatalf ("expected tag-not-found error, got repoName=%q, tagName=%q instead" , repoName , tagName )
1415 }
@@ -27,4 +28,40 @@ func TestFetchErrors(t *testing.T) {
2728 t .Fatalf ("expected manifest-not-found error, got %q instead" , err )
2829 }
2930 t .Logf ("correct, expected error: %s" , err )
31+
32+ repoName , tagName , _ , err = manifest .Fetch ("/dev/null" , "/proc/kmsg" )
33+ if err == nil {
34+ t .Fatalf ("expected filesystem error, got repoName=%q, tagName=%q instead" , repoName , tagName )
35+ }
36+ if ! strings .Contains (err .Error (), "permission denied" ) && ! strings .Contains (err .Error (), "not permitted" ) {
37+ t .Fatalf ("expected filesystem error, got %q instead" , err )
38+ }
39+ t .Logf ("correct, expected error: %s" , err )
40+
41+ repoName , tagName , _ , err = manifest .Fetch ("/dev/null" , "./testdata" )
42+ if err == nil {
43+ t .Fatalf ("expected directory error, got repoName=%q, tagName=%q instead" , repoName , tagName )
44+ }
45+ if ! strings .Contains (err .Error (), "is a directory" ) {
46+ t .Fatalf ("expected directory error, got %q instead" , err )
47+ }
48+ t .Logf ("correct, expected error: %s" , err )
49+
50+ repoName , tagName , _ , err = manifest .Fetch ("/dev/null" , "https://nonexistent.subdomain.example.com/nonexistent-project:1.2.3" )
51+ if err == nil {
52+ t .Fatalf ("expected no such host error, got repoName=%q, tagName=%q instead" , repoName , tagName )
53+ }
54+ if ! strings .Contains (err .Error (), "no such host" ) {
55+ t .Fatalf ("expected no such host error, got %q instead" , err )
56+ }
57+ t .Logf ("correct, expected error: %s" , err )
58+
59+ repoName , tagName , _ , err = manifest .Fetch ("/dev/null" , "https://example.com:1.2.3" )
60+ if err == nil {
61+ t .Fatalf ("expected parse error, got repoName=%q, tagName=%q instead" , repoName , tagName )
62+ }
63+ if ! strings .HasPrefix (err .Error (), "Bad line:" ) {
64+ t .Fatalf ("expected parse error, got %q instead" , err )
65+ }
66+ t .Logf ("correct, expected error: %s" , err )
3067}
0 commit comments