Skip to content

Add more test coverage for manifest/ #59

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions manifest/example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion manifest/fetch.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
39 changes: 38 additions & 1 deletion manifest/fetch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand All @@ -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)
}