mirror of
				https://github.com/moby/moby.git
				synced 2022-11-09 12:21:53 -05:00 
			
		
		
		
	integ-cli: fix TestImportDisplay & add FileServer
Docker-DCO-1.1-Signed-off-by: Cristian Staretu <cristian.staretu@gmail.com> (github: unclejack)
This commit is contained in:
		
							parent
							
								
									8b18a2da54
								
							
						
					
					
						commit
						9e5592d6a1
					
				
					 3 changed files with 39 additions and 1 deletions
				
			
		| 
						 | 
				
			
			@ -89,6 +89,9 @@ RUN mkdir -p /go/src/github.com/cpuguy83 \
 | 
			
		|||
# Get the "busybox" image source so we can build locally instead of pulling
 | 
			
		||||
RUN	git clone -b buildroot-2014.02 https://github.com/jpetazzo/docker-busybox.git /docker-busybox
 | 
			
		||||
 | 
			
		||||
# Get the "cirros" image source so we can import it instead of fetching it during tests
 | 
			
		||||
RUN	curl -sSL -o /cirros.tar.gz https://github.com/ewindisch/docker-cirros/raw/1cded459668e8b9dbf4ef976c94c05add9bbd8e9/cirros-0.3.0-x86_64-lxc.tar.gz
 | 
			
		||||
 | 
			
		||||
# Setup s3cmd config
 | 
			
		||||
RUN	/bin/echo -e '[default]\naccess_key=$AWS_ACCESS_KEY\nsecret_key=$AWS_SECRET_KEY' > /.s3cfg
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,13 +1,22 @@
 | 
			
		|||
package main
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"fmt"
 | 
			
		||||
	"os/exec"
 | 
			
		||||
	"strings"
 | 
			
		||||
	"testing"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
func TestImportDisplay(t *testing.T) {
 | 
			
		||||
	importCmd := exec.Command(dockerBinary, "import", "https://github.com/ewindisch/docker-cirros/raw/master/cirros-0.3.0-x86_64-lxc.tar.gz")
 | 
			
		||||
	server, err := fileServer(map[string]string{
 | 
			
		||||
		"/cirros.tar.gz": "/cirros.tar.gz",
 | 
			
		||||
	})
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		t.Fatal(err)
 | 
			
		||||
	}
 | 
			
		||||
	defer server.Close()
 | 
			
		||||
	fileUrl := fmt.Sprintf("%s/cirros.tar.gz", server.URL)
 | 
			
		||||
	importCmd := exec.Command(dockerBinary, "import", fileUrl)
 | 
			
		||||
	out, _, err := runCommandWithOutput(importCmd)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		t.Errorf("import failed with errors: %v, output: %q", err, out)
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -5,6 +5,8 @@ import (
 | 
			
		|||
	"encoding/json"
 | 
			
		||||
	"fmt"
 | 
			
		||||
	"io"
 | 
			
		||||
	"net/http"
 | 
			
		||||
	"net/http/httptest"
 | 
			
		||||
	"os"
 | 
			
		||||
	"os/exec"
 | 
			
		||||
	"reflect"
 | 
			
		||||
| 
						 | 
				
			
			@ -212,3 +214,27 @@ func ListTar(f io.Reader) ([]string, error) {
 | 
			
		|||
		entries = append(entries, th.Name)
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
type FileServer struct {
 | 
			
		||||
	*httptest.Server
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func fileServer(files map[string]string) (*FileServer, error) {
 | 
			
		||||
	var handler http.HandlerFunc = func(w http.ResponseWriter, r *http.Request) {
 | 
			
		||||
		if filePath, found := files[r.URL.Path]; found {
 | 
			
		||||
			http.ServeFile(w, r, filePath)
 | 
			
		||||
		} else {
 | 
			
		||||
			http.Error(w, http.StatusText(404), 404)
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	for _, file := range files {
 | 
			
		||||
		if _, err := os.Stat(file); err != nil {
 | 
			
		||||
			return nil, err
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
	server := httptest.NewServer(handler)
 | 
			
		||||
	return &FileServer{
 | 
			
		||||
		Server: server,
 | 
			
		||||
	}, nil
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue