This repository has been archived by the owner on Jun 13, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 177
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5078a0f
commit e004ebd
Showing
2 changed files
with
45 additions
and
137 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,61 @@ | ||
package packager | ||
|
||
import ( | ||
"archive/tar" | ||
"bytes" | ||
"fmt" | ||
"io" | ||
"strings" | ||
"testing" | ||
|
||
"github.com/docker/app/internal/tar" | ||
"github.com/docker/app/types" | ||
"gotest.tools/assert" | ||
"gotest.tools/fs" | ||
) | ||
|
||
func TestPackInvocationImageContext(t *testing.T) { | ||
app, err := types.NewAppFromDefaultFiles("testdata/packages/packing.dockerapp") | ||
assert.NilError(t, err) | ||
buf := bytes.NewBuffer(nil) | ||
assert.NilError(t, PackInvocationImageContext(app, buf)) | ||
dir := fs.NewDir(t, t.Name()) | ||
defer dir.Remove() | ||
assert.NilError(t, untar.Untar(buf, dir.Path(), false)) | ||
expectedDir := fs.NewDir(t, t.Name(), | ||
fs.FromDir("testdata/packages"), | ||
fs.WithFile("Dockerfile", dockerFile), | ||
fs.WithFile(".dockerignore", dockerIgnore)) | ||
defer expectedDir.Remove() | ||
assert.Assert(t, fs.Equal(dir.Path(), fs.ManifestFromDir(t, expectedDir.Path()))) | ||
assert.NilError(t, hasExpectedFiles(buf, map[string]bool{ | ||
"Dockerfile": true, | ||
".dockerignore": true, | ||
"packing.dockerapp/metadata.yml": true, | ||
"packing.dockerapp/docker-compose.yml": true, | ||
"packing.dockerapp/parameters.yml": true, | ||
"packing.dockerapp/config.cfg": true, | ||
"packing.dockerapp/nesteddir/config2.cfg": true, | ||
"packing.dockerapp/nesteddir/nested2/nested3/config3.cfg": true, | ||
})) | ||
} | ||
|
||
func hasExpectedFiles(r io.Reader, expectedFiles map[string]bool) error { | ||
tr := tar.NewReader(r) | ||
var errors []string | ||
var count int | ||
for { | ||
hdr, err := tr.Next() | ||
if err == io.EOF { | ||
break // End of archive | ||
} | ||
if err != nil { | ||
return err | ||
} | ||
if hdr.Size == 0 { | ||
errors = append(errors, fmt.Sprintf("content of '%s' is empty", hdr.Name)) | ||
} | ||
count++ | ||
if !expectedFiles[hdr.Name] { | ||
errors = append(errors, fmt.Sprintf("couldn't find file '%s' in the tar archive", hdr.Name)) | ||
break | ||
} | ||
} | ||
if count != len(expectedFiles) { | ||
errors = append(errors, fmt.Sprintf("number of expected files is in archive is '%d', but '%d' were found", | ||
len(expectedFiles), count)) | ||
} | ||
if len(errors) != 0 { | ||
return fmt.Errorf("%s", strings.Join(errors, "\n")) | ||
} | ||
return nil | ||
} |
This file was deleted.
Oops, something went wrong.