manifest: test ArchFile()
This commit is contained in:
parent
e6408ba864
commit
3532dbec44
|
|
@ -2,13 +2,13 @@ package manifest_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bufio"
|
"bufio"
|
||||||
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
|
||||||
|
|
||||||
"github.com/docker-library/go-dockerlibrary/manifest"
|
"github.com/docker-library/go-dockerlibrary/manifest"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestExample(t *testing.T) {
|
func Example() {
|
||||||
man, err := manifest.Parse(bufio.NewReader(strings.NewReader(`# RFC 2822
|
man, err := manifest.Parse(bufio.NewReader(strings.NewReader(`# RFC 2822
|
||||||
|
|
||||||
# I LOVE CAKE
|
# I LOVE CAKE
|
||||||
|
|
@ -60,30 +60,20 @@ Tags: raspbian-s390x
|
||||||
Architectures: s390x, i386
|
Architectures: s390x, i386
|
||||||
|
|
||||||
|
|
||||||
Tags: 1.5-withfile
|
|
||||||
SharedTags: 1.5-debian
|
|
||||||
GitCommit: d7e2a8d90a9b8f5dfd5bcd428e0c33b68c40cc19
|
|
||||||
File: Dockerfile-15
|
|
||||||
|
|
||||||
Tags: 1.5-withdirandfile
|
|
||||||
SharedTags: 1.5-debian
|
|
||||||
GitCommit: d7e2a8d90a9b8f5dfd5bcd428e0c33b68c40cc19
|
|
||||||
Directory: 1.5
|
|
||||||
File: Dockerfile-debian
|
|
||||||
`)))
|
`)))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
t.Logf("-------------\n2822:\n%s\n", man)
|
fmt.Printf("-------------\n2822:\n%s\n", man)
|
||||||
|
|
||||||
t.Logf("\nShared Tag Groups:\n")
|
fmt.Printf("\nShared Tag Groups:\n")
|
||||||
for _, group := range man.GetSharedTagGroups() {
|
for _, group := range man.GetSharedTagGroups() {
|
||||||
t.Logf("\n - %s\n", strings.Join(group.SharedTags, ", "))
|
fmt.Printf("\n - %s\n", strings.Join(group.SharedTags, ", "))
|
||||||
for _, entry := range group.Entries {
|
for _, entry := range group.Entries {
|
||||||
t.Logf(" - %s\n", entry.TagsString())
|
fmt.Printf(" - %s\n", entry.TagsString())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
t.Logf("\n")
|
fmt.Printf("\n")
|
||||||
|
|
||||||
man, err = manifest.Parse(bufio.NewReader(strings.NewReader(`
|
man, err = manifest.Parse(bufio.NewReader(strings.NewReader(`
|
||||||
# maintainer: InfoSiftr <github@infosiftr.com> (@infosiftr)
|
# maintainer: InfoSiftr <github@infosiftr.com> (@infosiftr)
|
||||||
|
|
@ -100,7 +90,7 @@ i: g@h j
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
t.Logf("-------------\nline-based:\n%v\n", man)
|
fmt.Printf("-------------\nline-based:\n%v\n", man)
|
||||||
|
|
||||||
// Output:
|
// Output:
|
||||||
// -------------
|
// -------------
|
||||||
|
|
@ -161,15 +151,15 @@ i: g@h j
|
||||||
// Directory: j
|
// Directory: j
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestExampleFetch_local(t *testing.T) {
|
func ExampleFetch_local() {
|
||||||
repoName, tagName, man, err := manifest.Fetch("testdata", "bash:4.4")
|
repoName, tagName, man, err := manifest.Fetch("testdata", "bash:4.4")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
t.Logf("%s:%s\n\n", repoName, tagName)
|
fmt.Printf("%s:%s\n\n", repoName, tagName)
|
||||||
|
|
||||||
t.Log(man.GetTag(tagName).ClearDefaults(manifest.DefaultManifestEntry).String())
|
fmt.Println(man.GetTag(tagName).ClearDefaults(manifest.DefaultManifestEntry).String())
|
||||||
|
|
||||||
// Output:
|
// Output:
|
||||||
// bash:4.4
|
// bash:4.4
|
||||||
|
|
@ -181,15 +171,15 @@ func TestExampleFetch_local(t *testing.T) {
|
||||||
// Directory: 4.4
|
// Directory: 4.4
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestExampleFetch_remote(t *testing.T) {
|
func ExampleFetch_remote() {
|
||||||
repoName, tagName, man, err := manifest.Fetch("/home/jsmith/docker/official-images/library", "https://github.com/docker-library/official-images/raw/1a3c4cd6d5cd53bd538a6f56a69f94c5b35325a7/library/bash:4.4")
|
repoName, tagName, man, err := manifest.Fetch("/home/jsmith/docker/official-images/library", "https://github.com/docker-library/official-images/raw/1a3c4cd6d5cd53bd538a6f56a69f94c5b35325a7/library/bash:4.4")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
t.Logf("%s:%s\n\n", repoName, tagName)
|
fmt.Printf("%s:%s\n\n", repoName, tagName)
|
||||||
|
|
||||||
t.Log(man.GetTag(tagName).ClearDefaults(manifest.DefaultManifestEntry).String())
|
fmt.Println(man.GetTag(tagName).ClearDefaults(manifest.DefaultManifestEntry).String())
|
||||||
|
|
||||||
// Output:
|
// Output:
|
||||||
// bash:4.4
|
// bash:4.4
|
||||||
|
|
|
||||||
|
|
@ -18,3 +18,36 @@ func TestParseError(t *testing.T) {
|
||||||
t.Errorf("Unexpected error: %v", err)
|
t.Errorf("Unexpected error: %v", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestArchFile(t *testing.T) {
|
||||||
|
tests := []struct {
|
||||||
|
file string
|
||||||
|
defaultArchFile string
|
||||||
|
}{{
|
||||||
|
file: "",
|
||||||
|
defaultArchFile: "Dockerfile",
|
||||||
|
}, {
|
||||||
|
file: "Dockerfile",
|
||||||
|
defaultArchFile: "Dockerfile",
|
||||||
|
}, {
|
||||||
|
file: "Dockerfile-foo",
|
||||||
|
defaultArchFile: "Dockerfile-foo",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, test := range tests {
|
||||||
|
manString := `Maintainers: Giuseppe Valente <gvalente@arista.com> (@7AC)
|
||||||
|
GitCommit: abcdef
|
||||||
|
`
|
||||||
|
if test.file != "" {
|
||||||
|
manString += "File: " + test.file
|
||||||
|
}
|
||||||
|
man, err := manifest.Parse2822(strings.NewReader(manString))
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("Unexpected error: %v", err)
|
||||||
|
}
|
||||||
|
if man.Global.ArchFile(manifest.DefaultArchitecture) != test.defaultArchFile {
|
||||||
|
t.Fatalf("Unexpected arch file: %s", man.Global.ArchFile(manifest.DefaultArchitecture))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue