2017-04-15 20:26:05 +02:00
|
|
|
package archive
|
|
|
|
|
|
|
|
import (
|
|
|
|
"io/ioutil"
|
|
|
|
"os"
|
|
|
|
"path/filepath"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/goreleaser/goreleaser/config"
|
|
|
|
"github.com/goreleaser/goreleaser/context"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestDescription(t *testing.T) {
|
|
|
|
assert.NotEmpty(t, Pipe{}.Description())
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestRunPipe(t *testing.T) {
|
|
|
|
var assert = assert.New(t)
|
|
|
|
folder, err := ioutil.TempDir("", "archivetest")
|
|
|
|
assert.NoError(err)
|
|
|
|
current, err := os.Getwd()
|
|
|
|
assert.NoError(err)
|
|
|
|
assert.NoError(os.Chdir(folder))
|
|
|
|
defer func() {
|
|
|
|
assert.NoError(os.Chdir(current))
|
|
|
|
}()
|
|
|
|
var dist = filepath.Join(folder, "dist")
|
|
|
|
assert.NoError(os.Mkdir(dist, 0755))
|
2017-07-01 18:13:44 +02:00
|
|
|
assert.NoError(os.Mkdir(filepath.Join(dist, "mybin_darwin_amd64"), 0755))
|
|
|
|
assert.NoError(os.Mkdir(filepath.Join(dist, "mybin_windows_amd64"), 0755))
|
|
|
|
_, err = os.Create(filepath.Join(dist, "mybin_darwin_amd64", "mybin"))
|
2017-04-15 20:26:05 +02:00
|
|
|
assert.NoError(err)
|
2017-07-01 18:13:44 +02:00
|
|
|
_, err = os.Create(filepath.Join(dist, "mybin_windows_amd64", "mybin.exe"))
|
2017-05-11 05:05:51 +02:00
|
|
|
assert.NoError(err)
|
|
|
|
_, err = os.Create(filepath.Join(folder, "README.md"))
|
2017-04-15 20:26:05 +02:00
|
|
|
assert.NoError(err)
|
|
|
|
var ctx = &context.Context{
|
2017-07-01 18:13:44 +02:00
|
|
|
Folders: map[string]string{
|
|
|
|
"darwinamd64": "mybin_darwin_amd64",
|
|
|
|
"windowsamd64": "mybin_windows_amd64",
|
2017-04-15 20:26:05 +02:00
|
|
|
},
|
|
|
|
Config: config.Project{
|
|
|
|
Dist: dist,
|
|
|
|
Archive: config.Archive{
|
|
|
|
Files: []string{
|
2017-05-11 05:05:51 +02:00
|
|
|
"README.*",
|
2017-04-15 20:26:05 +02:00
|
|
|
},
|
2017-04-21 21:01:19 +02:00
|
|
|
FormatOverrides: []config.FormatOverride{
|
|
|
|
{
|
|
|
|
Goos: "windows",
|
|
|
|
Format: "zip",
|
|
|
|
},
|
|
|
|
},
|
2017-04-15 20:26:05 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
for _, format := range []string{"tar.gz", "zip"} {
|
|
|
|
t.Run("Archive format "+format, func(t *testing.T) {
|
|
|
|
ctx.Config.Archive.Format = format
|
|
|
|
assert.NoError(Pipe{}.Run(ctx))
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
2017-04-21 21:03:36 +02:00
|
|
|
|
2017-04-22 15:29:53 +02:00
|
|
|
func TestRunPipeDistRemoved(t *testing.T) {
|
|
|
|
var assert = assert.New(t)
|
|
|
|
var ctx = &context.Context{
|
2017-07-01 18:13:44 +02:00
|
|
|
Folders: map[string]string{
|
|
|
|
"darwinamd64": "whatever",
|
2017-04-22 15:29:53 +02:00
|
|
|
},
|
|
|
|
Config: config.Project{
|
|
|
|
Dist: "/path/nope",
|
|
|
|
Archive: config.Archive{
|
|
|
|
Format: "zip",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
assert.Error(Pipe{}.Run(ctx))
|
|
|
|
}
|
|
|
|
|
2017-05-11 05:05:51 +02:00
|
|
|
func TestRunPipeInvalidGlob(t *testing.T) {
|
|
|
|
var assert = assert.New(t)
|
|
|
|
var ctx = &context.Context{
|
2017-07-01 18:13:44 +02:00
|
|
|
Folders: map[string]string{
|
|
|
|
"windowsamd64": "whatever",
|
2017-05-11 05:05:51 +02:00
|
|
|
},
|
|
|
|
Config: config.Project{
|
|
|
|
Dist: "/tmp",
|
|
|
|
Archive: config.Archive{
|
|
|
|
Files: []string{
|
|
|
|
"[x-]",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
assert.Error(Pipe{}.Run(ctx))
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestRunPipeGlobFailsToAdd(t *testing.T) {
|
|
|
|
var assert = assert.New(t)
|
|
|
|
folder, err := ioutil.TempDir("", "archivetest")
|
|
|
|
assert.NoError(err)
|
|
|
|
current, err := os.Getwd()
|
|
|
|
assert.NoError(err)
|
|
|
|
assert.NoError(os.Chdir(folder))
|
|
|
|
defer func() {
|
|
|
|
assert.NoError(os.Chdir(current))
|
|
|
|
}()
|
|
|
|
assert.NoError(os.MkdirAll(filepath.Join(folder, "folder", "another"), 0755))
|
|
|
|
|
|
|
|
var ctx = &context.Context{
|
2017-07-01 18:13:44 +02:00
|
|
|
Folders: map[string]string{
|
2017-05-11 05:05:51 +02:00
|
|
|
"windows386": "mybin",
|
|
|
|
},
|
|
|
|
Config: config.Project{
|
|
|
|
Dist: folder,
|
|
|
|
Archive: config.Archive{
|
|
|
|
Files: []string{
|
|
|
|
"folder",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
assert.Error(Pipe{}.Run(ctx))
|
|
|
|
}
|