1
0
mirror of https://github.com/goreleaser/goreleaser.git synced 2025-07-15 01:34:21 +02:00

feat: Add archive config 'wrap_in_directory'

The field is optional. When set to true, files in archive are wrapped
in a directory, which has the same name as the archive itself.
Tests have also been extended to cover this.

Closes #251
This commit is contained in:
Jorin Vogel
2017-10-02 18:43:03 +02:00
parent 9562d098b0
commit 0e2e8c8eb3
4 changed files with 97 additions and 10 deletions

View File

@ -1,6 +1,9 @@
package archive
import (
"archive/tar"
"compress/gzip"
"io"
"os"
"path/filepath"
"testing"
@ -52,6 +55,23 @@ func TestRunPipe(t *testing.T) {
assert.NoError(t, Pipe{}.Run(ctx))
})
}
// Check archive contents
f, err := os.Open(filepath.Join(dist, "mybin_darwin_amd64.tar.gz"))
assert.NoError(t, err)
defer func() { assert.NoError(t, f.Close()) }()
gr, err := gzip.NewReader(f)
assert.NoError(t, err)
defer func() { assert.NoError(t, gr.Close()) }()
r := tar.NewReader(gr)
for _, n := range []string{"README.md", "mybin"} {
h, err := r.Next()
if err == io.EOF {
break
}
assert.NoError(t, err)
assert.Equal(t, n, h.Name)
}
}
func TestRunPipeBinary(t *testing.T) {
@ -132,3 +152,46 @@ func TestRunPipeGlobFailsToAdd(t *testing.T) {
ctx.AddBinary("windows386", "mybin", "mybin", "dist/mybin")
assert.Error(t, Pipe{}.Run(ctx))
}
func TestRunPipeWrap(t *testing.T) {
folder, back := testlib.Mktmp(t)
defer back()
var dist = filepath.Join(folder, "dist")
assert.NoError(t, os.Mkdir(dist, 0755))
assert.NoError(t, os.Mkdir(filepath.Join(dist, "mybin_darwin_amd64"), 0755))
_, err := os.Create(filepath.Join(dist, "mybin_darwin_amd64", "mybin"))
assert.NoError(t, err)
_, err = os.Create(filepath.Join(folder, "README.md"))
assert.NoError(t, err)
var ctx = &context.Context{
Config: config.Project{
Dist: dist,
Archive: config.Archive{
WrapInDirectory: true,
Format: "tar.gz",
Files: []string{
"README.*",
},
},
},
}
ctx.AddBinary("darwinamd64", "mybin_darwin_amd64", "mybin", filepath.Join(dist, "mybin_darwin_amd64", "mybin"))
assert.NoError(t, Pipe{}.Run(ctx))
// Check archive contents
f, err := os.Open(filepath.Join(dist, "mybin_darwin_amd64.tar.gz"))
assert.NoError(t, err)
defer func() { assert.NoError(t, f.Close()) }()
gr, err := gzip.NewReader(f)
assert.NoError(t, err)
defer func() { assert.NoError(t, gr.Close()) }()
r := tar.NewReader(gr)
for _, n := range []string{"README.md", "mybin"} {
h, err := r.Next()
if err == io.EOF {
break
}
assert.NoError(t, err)
assert.Equal(t, filepath.Join("mybin_darwin_amd64", n), h.Name)
}
}