Browse Source

Remove all network dependencies from the test suite

Guillaume J. Charmes 12 years ago
parent
commit
e43ef364cb
3 changed files with 14 additions and 80 deletions
  1. 0 70
      api_test.go
  2. 1 1
      buildfile_test.go
  3. 13 9
      runtime_test.go

+ 0 - 70
api_test.go

@@ -5,7 +5,6 @@ import (
 	"bufio"
 	"bufio"
 	"bytes"
 	"bytes"
 	"encoding/json"
 	"encoding/json"
-	"github.com/dotcloud/docker/auth"
 	"github.com/dotcloud/docker/utils"
 	"github.com/dotcloud/docker/utils"
 	"io"
 	"io"
 	"net"
 	"net"
@@ -41,44 +40,6 @@ func TestGetBoolParam(t *testing.T) {
 	}
 	}
 }
 }
 
 
-func TestPostAuth(t *testing.T) {
-	runtime, err := newTestRuntime()
-	if err != nil {
-		t.Fatal(err)
-	}
-	defer nuke(runtime)
-
-	srv := &Server{
-		runtime: runtime,
-	}
-
-	r := httptest.NewRecorder()
-
-	authConfig := &auth.AuthConfig{
-		Username: "utest",
-		Password: "utest",
-		Email:    "utest@yopmail.com",
-	}
-
-	authConfigJSON, err := json.Marshal(authConfig)
-	if err != nil {
-		t.Fatal(err)
-	}
-
-	req, err := http.NewRequest("POST", "/auth", bytes.NewReader(authConfigJSON))
-	if err != nil {
-		t.Fatal(err)
-	}
-
-	if err := postAuth(srv, APIVERSION, r, req, nil); err != nil {
-		t.Fatal(err)
-	}
-
-	if r.Code != http.StatusOK && r.Code != 0 {
-		t.Fatalf("%d OK or 0 expected, received %d\n", http.StatusOK, r.Code)
-	}
-}
-
 func TestGetVersion(t *testing.T) {
 func TestGetVersion(t *testing.T) {
 	runtime, err := newTestRuntime()
 	runtime, err := newTestRuntime()
 	if err != nil {
 	if err != nil {
@@ -286,37 +247,6 @@ func TestGetImagesViz(t *testing.T) {
 	}
 	}
 }
 }
 
 
-func TestGetImagesSearch(t *testing.T) {
-	runtime, err := newTestRuntime()
-	if err != nil {
-		t.Fatal(err)
-	}
-	defer nuke(runtime)
-
-	srv := &Server{
-		runtime: runtime,
-	}
-
-	r := httptest.NewRecorder()
-
-	req, err := http.NewRequest("GET", "/images/search?term=redis", nil)
-	if err != nil {
-		t.Fatal(err)
-	}
-
-	if err := getImagesSearch(srv, APIVERSION, r, req, nil); err != nil {
-		t.Fatal(err)
-	}
-
-	results := []APISearch{}
-	if err := json.Unmarshal(r.Body.Bytes(), &results); err != nil {
-		t.Fatal(err)
-	}
-	if len(results) < 2 {
-		t.Errorf("Expected at least 2 lines, %d found", len(results))
-	}
-}
-
 func TestGetImagesHistory(t *testing.T) {
 func TestGetImagesHistory(t *testing.T) {
 	runtime, err := newTestRuntime()
 	runtime, err := newTestRuntime()
 	if err != nil {
 	if err != nil {

+ 1 - 1
buildfile_test.go

@@ -84,7 +84,7 @@ run    [ "$FOO" = "BAR" ]
 
 
 	{
 	{
 		`
 		`
-from docker-ut
+from %s
 ENTRYPOINT /bin/echo
 ENTRYPOINT /bin/echo
 CMD Hello world
 CMD Hello world
 `,
 `,

+ 13 - 9
runtime_test.go

@@ -17,11 +17,12 @@ import (
 )
 )
 
 
 const (
 const (
-	unitTestImageName = "docker-unit-tests"
-	unitTestImageID   = "e9aa60c60128cad1"
-	unitTestStoreBase = "/var/lib/docker/unit-tests"
-	testDaemonAddr    = "127.0.0.1:4270"
-	testDaemonProto   = "tcp"
+	unitTestImageName     = "docker-unit-tests"
+	unitTestImageID       = "e9aa60c60128cad1"
+	unitTestNetworkBridge = "testdockbr0"
+	unitTestStoreBase     = "/var/lib/docker/unit-tests"
+	testDaemonAddr        = "127.0.0.1:4270"
+	testDaemonProto       = "tcp"
 )
 )
 
 
 var globalRuntime *Runtime
 var globalRuntime *Runtime
@@ -76,7 +77,7 @@ func init() {
 		log.Fatal("docker tests need to be run as root")
 		log.Fatal("docker tests need to be run as root")
 	}
 	}
 
 
-	NetworkBridgeIface = "testdockbr0"
+	NetworkBridgeIface = unitTestNetworkBridge
 
 
 	// Make it our Store root
 	// Make it our Store root
 	runtime, err := NewRuntimeFromDirectory(unitTestStoreBase, false)
 	runtime, err := NewRuntimeFromDirectory(unitTestStoreBase, false)
@@ -92,9 +93,12 @@ func init() {
 		pullingPool: make(map[string]struct{}),
 		pullingPool: make(map[string]struct{}),
 		pushingPool: make(map[string]struct{}),
 		pushingPool: make(map[string]struct{}),
 	}
 	}
-	// Retrieve the Image
-	if err := srv.ImagePull(unitTestImageName, "", os.Stdout, utils.NewStreamFormatter(false), nil); err != nil {
-		panic(err)
+	// If the unit test is not found, try to download it.
+	if img, err := runtime.repositories.LookupImage(unitTestImageName); err != nil || img.ID != unitTestImageID {
+		// Retrieve the Image
+		if err := srv.ImagePull(unitTestImageName, "", os.Stdout, utils.NewStreamFormatter(false), nil); err != nil {
+			panic(err)
+		}
 	}
 	}
 	// Spawn a Daemon
 	// Spawn a Daemon
 	go func() {
 	go func() {