Browse code

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

shin- authored on 2013/05/09 02:21:21
Showing 3 changed files
... ...
@@ -33,6 +33,13 @@ func NewAuthConfig(username, password, email, rootPath string) *AuthConfig {
33 33
 	}
34 34
 }
35 35
 
36
+func IndexServerAddress() string {
37
+	if os.Getenv("DOCKER_INDEX_URL") != "" {
38
+		return os.Getenv("DOCKER_INDEX_URL")
39
+	}
40
+	return INDEX_SERVER
41
+}
42
+
36 43
 // create a base64 encoded auth string to store in config
37 44
 func EncodeAuth(authConfig *AuthConfig) string {
38 45
 	authStr := authConfig.Username + ":" + authConfig.Password
... ...
@@ -15,8 +15,7 @@ import (
15 15
 	"strings"
16 16
 )
17 17
 
18
-//FIXME: Set the endpoint in a conf file or via commandline
19
-const INDEX_ENDPOINT = auth.INDEX_SERVER + "/v1"
18
+var INDEX_ENDPOINT = auth.IndexServerAddress() + "/v1"
20 19
 
21 20
 // Build an Image object from raw json data
22 21
 func NewImgJson(src []byte) (*Image, error) {
23 22
new file mode 100644
... ...
@@ -0,0 +1,64 @@
0
+package docker
1
+
2
+import (
3
+	"os"
4
+	"testing"
5
+)
6
+
7
+func TestPull(t* testing.T) {
8
+	runtime, err := newTestRuntime()
9
+	if err != nil {
10
+		t.Fatal(err)
11
+	}
12
+	defer nuke(runtime)
13
+
14
+	err = runtime.graph.PullRepository(os.Stdout, "busybox", "", runtime.repositories, nil)
15
+	if err != nil {
16
+		t.Fatal(err)
17
+	}
18
+	img, err := runtime.repositories.LookupImage("busybox")
19
+	if err != nil {
20
+		t.Fatal(err)
21
+	}
22
+
23
+	// Try to run something on this image to make sure the layer's been downloaded properly.
24
+	config, err := ParseRun([]string{img.Id, "echo", "Hello World"}, os.Stdout, runtime.capabilities)
25
+	if err != nil {
26
+		t.Fatal(err)
27
+	}
28
+
29
+	b := NewBuilder(runtime)
30
+	container, err := b.Create(config)
31
+	if err != nil {
32
+		t.Fatal(err)
33
+	}
34
+	if err := container.Start(); err != nil {
35
+		t.Fatal(err)
36
+	}
37
+
38
+	if status := container.Wait(); status != 0 {
39
+		t.Fatalf("Expected status code 0, found %d instead", status)
40
+	}
41
+}
42
+
43
+func TestPullTag(t* testing.T) {
44
+	runtime, err := newTestRuntime()
45
+	if err != nil {
46
+		t.Fatal(err)
47
+	}
48
+	defer nuke(runtime)
49
+
50
+	err = runtime.graph.PullRepository(os.Stdout, "ubuntu", "12.04", runtime.repositories, nil)
51
+	if err != nil {
52
+		t.Fatal(err)
53
+	}
54
+	_, err = runtime.repositories.LookupImage("ubuntu:12.04")
55
+	if err != nil {
56
+		t.Fatal(err)
57
+	}
58
+
59
+	img2, err := runtime.repositories.LookupImage("ubuntu:12.10")
60
+	if img2 != nil {
61
+		t.Fatalf("Expected nil image but found %v instead", img2.Id)
62
+	}
63
+}
0 64
\ No newline at end of file