Docker-DCO-1.1-Signed-off-by: Cristian Staretu <cristian.staretu@gmail.com> (github: unclejack)
| ... | ... |
@@ -89,6 +89,9 @@ RUN mkdir -p /go/src/github.com/cpuguy83 \ |
| 89 | 89 |
# Get the "busybox" image source so we can build locally instead of pulling |
| 90 | 90 |
RUN git clone -b buildroot-2014.02 https://github.com/jpetazzo/docker-busybox.git /docker-busybox |
| 91 | 91 |
|
| 92 |
+# Get the "cirros" image source so we can import it instead of fetching it during tests |
|
| 93 |
+RUN curl -sSL -o /cirros.tar.gz https://github.com/ewindisch/docker-cirros/raw/1cded459668e8b9dbf4ef976c94c05add9bbd8e9/cirros-0.3.0-x86_64-lxc.tar.gz |
|
| 94 |
+ |
|
| 92 | 95 |
# Setup s3cmd config |
| 93 | 96 |
RUN /bin/echo -e '[default]\naccess_key=$AWS_ACCESS_KEY\nsecret_key=$AWS_SECRET_KEY' > /.s3cfg |
| 94 | 97 |
|
| ... | ... |
@@ -1,13 +1,22 @@ |
| 1 | 1 |
package main |
| 2 | 2 |
|
| 3 | 3 |
import ( |
| 4 |
+ "fmt" |
|
| 4 | 5 |
"os/exec" |
| 5 | 6 |
"strings" |
| 6 | 7 |
"testing" |
| 7 | 8 |
) |
| 8 | 9 |
|
| 9 | 10 |
func TestImportDisplay(t *testing.T) {
|
| 10 |
- importCmd := exec.Command(dockerBinary, "import", "https://github.com/ewindisch/docker-cirros/raw/master/cirros-0.3.0-x86_64-lxc.tar.gz") |
|
| 11 |
+ server, err := fileServer(map[string]string{
|
|
| 12 |
+ "/cirros.tar.gz": "/cirros.tar.gz", |
|
| 13 |
+ }) |
|
| 14 |
+ if err != nil {
|
|
| 15 |
+ t.Fatal(err) |
|
| 16 |
+ } |
|
| 17 |
+ defer server.Close() |
|
| 18 |
+ fileUrl := fmt.Sprintf("%s/cirros.tar.gz", server.URL)
|
|
| 19 |
+ importCmd := exec.Command(dockerBinary, "import", fileUrl) |
|
| 11 | 20 |
out, _, err := runCommandWithOutput(importCmd) |
| 12 | 21 |
if err != nil {
|
| 13 | 22 |
t.Errorf("import failed with errors: %v, output: %q", err, out)
|
| ... | ... |
@@ -5,6 +5,8 @@ import ( |
| 5 | 5 |
"encoding/json" |
| 6 | 6 |
"fmt" |
| 7 | 7 |
"io" |
| 8 |
+ "net/http" |
|
| 9 |
+ "net/http/httptest" |
|
| 8 | 10 |
"os" |
| 9 | 11 |
"os/exec" |
| 10 | 12 |
"reflect" |
| ... | ... |
@@ -212,3 +214,27 @@ func ListTar(f io.Reader) ([]string, error) {
|
| 212 | 212 |
entries = append(entries, th.Name) |
| 213 | 213 |
} |
| 214 | 214 |
} |
| 215 |
+ |
|
| 216 |
+type FileServer struct {
|
|
| 217 |
+ *httptest.Server |
|
| 218 |
+} |
|
| 219 |
+ |
|
| 220 |
+func fileServer(files map[string]string) (*FileServer, error) {
|
|
| 221 |
+ var handler http.HandlerFunc = func(w http.ResponseWriter, r *http.Request) {
|
|
| 222 |
+ if filePath, found := files[r.URL.Path]; found {
|
|
| 223 |
+ http.ServeFile(w, r, filePath) |
|
| 224 |
+ } else {
|
|
| 225 |
+ http.Error(w, http.StatusText(404), 404) |
|
| 226 |
+ } |
|
| 227 |
+ } |
|
| 228 |
+ |
|
| 229 |
+ for _, file := range files {
|
|
| 230 |
+ if _, err := os.Stat(file); err != nil {
|
|
| 231 |
+ return nil, err |
|
| 232 |
+ } |
|
| 233 |
+ } |
|
| 234 |
+ server := httptest.NewServer(handler) |
|
| 235 |
+ return &FileServer{
|
|
| 236 |
+ Server: server, |
|
| 237 |
+ }, nil |
|
| 238 |
+} |