add more tests

Signed-off-by: Jess Frazelle <acidburn@microsoft.com>
This commit is contained in:
Jess Frazelle 2018-03-06 10:14:23 -05:00
parent e55cbf0fa3
commit 72cd07cf34
No known key found for this signature in database
GPG key ID: 18F3685C0022BFF3
7 changed files with 47 additions and 19 deletions

View file

@ -1,6 +1,9 @@
package main
import "testing"
import (
"strings"
"testing"
)
func TestDelete(t *testing.T) {
// Make sure we have busybox in list.
@ -8,12 +11,11 @@ func TestDelete(t *testing.T) {
if err != nil {
t.Fatalf("output: %s, error: %v", string(out), err)
}
expected := `Repositories for localhost:5000
REPO TAGS
busybox latest
expected := `REPO TAGS
busybox glibc, musl, latest
alpine latest
`
if out != expected {
if !strings.HasSuffix(out, expected) {
t.Fatalf("expected: %s\ngot: %s", expected, out)
}
@ -27,11 +29,11 @@ alpine latest
if err != nil {
t.Fatalf("output: %s, error: %v", string(out), err)
}
expected = `Repositories for localhost:5000
REPO TAGS
expected = `REPO TAGS
busybox glibc, musl
alpine latest
`
if out != expected {
if !strings.HasSuffix(out, expected) {
t.Fatalf("expected: %s\ngot: %s", expected, out)
}
}

View file

@ -1,17 +1,20 @@
package main
import "testing"
import (
"strings"
"testing"
)
func TestList(t *testing.T) {
out, err := run("ls")
if err != nil {
t.Fatalf("output: %s, error: %v", string(out), err)
}
expected := `Repositories for localhost:5000
REPO TAGS
expected := `REPO TAGS
busybox glibc, musl
alpine latest
`
if out != expected {
if !strings.HasSuffix(out, expected) {
t.Fatalf("expected: %s\ngot: %s", expected, out)
}
}

View file

@ -90,7 +90,7 @@ func TestMain(m *testing.M) {
func run(args ...string) (string, error) {
prog := "./testreg" + exeSuffix
// always add trust insecure, and the registry
newargs := append([]string{"-k", "-r", "localhost:5000"}, args...)
newargs := append([]string{"-d", "-k", "-r", "localhost:5000"}, args...)
cmd := exec.Command(prog, newargs...)
out, err := cmd.CombinedOutput()
return string(out), err

19
tags_test.go Normal file
View file

@ -0,0 +1,19 @@
package main
import (
"strings"
"testing"
)
func TestTags(t *testing.T) {
out, err := run("tags", "busybox")
if err != nil {
t.Fatalf("output: %s, error: %v", string(out), err)
}
expected := `glibc
musl
`
if !strings.HasSuffix(out, expected) {
t.Fatalf("expected: %s\ngot: %s", expected, out)
}
}

View file

@ -7,6 +7,8 @@ log:
storage:
filesystem:
rootdirectory: /var/lib/registry
delete:
enabled: true
http:
addr: 0.0.0.0:5000
headers:

View file

@ -7,6 +7,8 @@ log:
storage:
filesystem:
rootdirectory: /var/lib/registry
delete:
enabled: true
http:
addr: 0.0.0.0:5000
headers:

View file

@ -72,12 +72,12 @@ func StartRegistry(dcli *client.Client, config, username, password string) (stri
return r.ID, addr, err
}
if err := prefillRegistry("alpine:latest", dcli, "localhost"+port, username, password); err != nil {
return r.ID, addr, err
}
if err := prefillRegistry("busybox:latest", dcli, "localhost"+port, username, password); err != nil {
return r.ID, addr, err
// Prefill the images.
images := []string{"alpine:latest", "busybox:latest", "busybox:musl", "busybox:glibc"}
for _, image := range images {
if err := prefillRegistry(image, dcli, "localhost"+port, username, password); err != nil {
return r.ID, addr, err
}
}
return r.ID, addr, nil