Find docker index URL in ENV before using default value. Unit tests for docker pull

This commit is contained in:
shin- 2013-05-08 10:21:21 -07:00 committed by Guillaume J. Charmes
parent d586662ce5
commit fc1d1d871b
3 changed files with 72 additions and 2 deletions

View File

@ -33,6 +33,13 @@ func NewAuthConfig(username, password, email, rootPath string) *AuthConfig {
}
}
func IndexServerAddress() string {
if os.Getenv("DOCKER_INDEX_URL") != "" {
return os.Getenv("DOCKER_INDEX_URL")
}
return INDEX_SERVER
}
// create a base64 encoded auth string to store in config
func EncodeAuth(authConfig *AuthConfig) string {
authStr := authConfig.Username + ":" + authConfig.Password

View File

@ -15,8 +15,7 @@ import (
"strings"
)
//FIXME: Set the endpoint in a conf file or via commandline
const INDEX_ENDPOINT = auth.INDEX_SERVER + "/v1"
var INDEX_ENDPOINT = auth.IndexServerAddress() + "/v1"
// Build an Image object from raw json data
func NewImgJson(src []byte) (*Image, error) {

64
registry_test.go Normal file
View File

@ -0,0 +1,64 @@
package docker
import (
"os"
"testing"
)
func TestPull(t* testing.T) {
runtime, err := newTestRuntime()
if err != nil {
t.Fatal(err)
}
defer nuke(runtime)
err = runtime.graph.PullRepository(os.Stdout, "busybox", "", runtime.repositories, nil)
if err != nil {
t.Fatal(err)
}
img, err := runtime.repositories.LookupImage("busybox")
if err != nil {
t.Fatal(err)
}
// Try to run something on this image to make sure the layer's been downloaded properly.
config, err := ParseRun([]string{img.Id, "echo", "Hello World"}, os.Stdout, runtime.capabilities)
if err != nil {
t.Fatal(err)
}
b := NewBuilder(runtime)
container, err := b.Create(config)
if err != nil {
t.Fatal(err)
}
if err := container.Start(); err != nil {
t.Fatal(err)
}
if status := container.Wait(); status != 0 {
t.Fatalf("Expected status code 0, found %d instead", status)
}
}
func TestPullTag(t* testing.T) {
runtime, err := newTestRuntime()
if err != nil {
t.Fatal(err)
}
defer nuke(runtime)
err = runtime.graph.PullRepository(os.Stdout, "ubuntu", "12.04", runtime.repositories, nil)
if err != nil {
t.Fatal(err)
}
_, err = runtime.repositories.LookupImage("ubuntu:12.04")
if err != nil {
t.Fatal(err)
}
img2, err := runtime.repositories.LookupImage("ubuntu:12.10")
if img2 != nil {
t.Fatalf("Expected nil image but found %v instead", img2.Id)
}
}