Add more test coverage for manifest/
This commit is contained in:
parent
20b5a50a4e
commit
419da33551
|
|
@ -59,6 +59,8 @@ GitCommit: d7e2a8d90a9b8f5dfd5bcd428e0c33b68c40cc19
|
|||
Directory: 1.5
|
||||
File: Dockerfile.alpine
|
||||
s390x-File: Dockerfile.alpine.s390x.bad-boy
|
||||
Builder: buildkit
|
||||
GitFetch: refs/heads/having-a-good-time
|
||||
|
||||
SharedTags: raspbian
|
||||
GitCommit: deadbeefdeadbeefdeadbeefdeadbeefdeadbeef
|
||||
|
|
@ -105,9 +107,11 @@ s390x-File: Dockerfile
|
|||
// s390x-GitCommit: b6c460e7cd79b595267870a98013ec3078b490df
|
||||
//
|
||||
// Tags: 1.5-alpine
|
||||
// GitFetch: refs/heads/having-a-good-time
|
||||
// GitCommit: d7e2a8d90a9b8f5dfd5bcd428e0c33b68c40cc19
|
||||
// Directory: 1.5
|
||||
// File: Dockerfile.alpine
|
||||
// Builder: buildkit
|
||||
// s390x-File: Dockerfile.alpine.s390x.bad-boy
|
||||
//
|
||||
// Tags: raspbian-s390x
|
||||
|
|
|
|||
|
|
@ -68,7 +68,7 @@ func Fetch(library, repo string) (string, string, *Manifest2822, error) {
|
|||
|
||||
// try file paths
|
||||
filePaths := []string{}
|
||||
if filepath.IsAbs(repo) || strings.IndexRune(repo, filepath.Separator) >= 0 || strings.IndexRune(repo, '/') >= 0 {
|
||||
if filepath.IsAbs(repo) || strings.ContainsRune(repo, filepath.Separator) || strings.ContainsRune(repo, '/') {
|
||||
filePaths = append(filePaths, repo)
|
||||
}
|
||||
if !filepath.IsAbs(repo) {
|
||||
|
|
|
|||
|
|
@ -2,13 +2,14 @@ package manifest_test
|
|||
|
||||
import (
|
||||
"errors"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/docker-library/bashbrew/manifest"
|
||||
)
|
||||
|
||||
func TestFetchErrors(t *testing.T) {
|
||||
repoName, tagName, _, err := manifest.Fetch("testdata", "bash:69.420")
|
||||
repoName, tagName, _, err := manifest.Fetch("/dev/null", "testdata/bash:69.420")
|
||||
if err == nil {
|
||||
t.Fatalf("expected tag-not-found error, got repoName=%q, tagName=%q instead", repoName, tagName)
|
||||
}
|
||||
|
|
@ -27,4 +28,40 @@ func TestFetchErrors(t *testing.T) {
|
|||
t.Fatalf("expected manifest-not-found error, got %q instead", err)
|
||||
}
|
||||
t.Logf("correct, expected error: %s", err)
|
||||
|
||||
repoName, tagName, _, err = manifest.Fetch("/dev/null", "/proc/kmsg")
|
||||
if err == nil {
|
||||
t.Fatalf("expected filesystem error, got repoName=%q, tagName=%q instead", repoName, tagName)
|
||||
}
|
||||
if !strings.Contains(err.Error(), "permission denied") && !strings.Contains(err.Error(), "not permitted") {
|
||||
t.Fatalf("expected filesystem error, got %q instead", err)
|
||||
}
|
||||
t.Logf("correct, expected error: %s", err)
|
||||
|
||||
repoName, tagName, _, err = manifest.Fetch("/dev/null", "./testdata")
|
||||
if err == nil {
|
||||
t.Fatalf("expected directory error, got repoName=%q, tagName=%q instead", repoName, tagName)
|
||||
}
|
||||
if !strings.Contains(err.Error(), "is a directory") {
|
||||
t.Fatalf("expected directory error, got %q instead", err)
|
||||
}
|
||||
t.Logf("correct, expected error: %s", err)
|
||||
|
||||
repoName, tagName, _, err = manifest.Fetch("/dev/null", "https://nonexistent.subdomain.example.com/nonexistent-project:1.2.3")
|
||||
if err == nil {
|
||||
t.Fatalf("expected no such host error, got repoName=%q, tagName=%q instead", repoName, tagName)
|
||||
}
|
||||
if !strings.Contains(err.Error(), "no such host") {
|
||||
t.Fatalf("expected no such host error, got %q instead", err)
|
||||
}
|
||||
t.Logf("correct, expected error: %s", err)
|
||||
|
||||
repoName, tagName, _, err = manifest.Fetch("/dev/null", "https://example.com:1.2.3")
|
||||
if err == nil {
|
||||
t.Fatalf("expected parse error, got repoName=%q, tagName=%q instead", repoName, tagName)
|
||||
}
|
||||
if !strings.HasPrefix(err.Error(), "Bad line:") {
|
||||
t.Fatalf("expected parse error, got %q instead", err)
|
||||
}
|
||||
t.Logf("correct, expected error: %s", err)
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue