2017-04-15 20:41:41 +02:00
|
|
|
package fpm
|
|
|
|
|
|
|
|
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 TestRunPipeNoFormats(t *testing.T) {
|
|
|
|
var assert = assert.New(t)
|
|
|
|
var ctx = &context.Context{
|
|
|
|
Config: config.Project{},
|
|
|
|
}
|
|
|
|
assert.NoError(Pipe{}.Run(ctx))
|
|
|
|
}
|
|
|
|
|
2017-06-08 11:41:09 +02:00
|
|
|
func TestRunPipeFormatBinary(t *testing.T) {
|
2017-06-05 18:28:29 +02:00
|
|
|
var assert = assert.New(t)
|
|
|
|
var ctx = &context.Context{
|
|
|
|
Config: config.Project{
|
2017-07-03 06:25:53 +02:00
|
|
|
FPM: config.FPM{
|
|
|
|
Formats: []string{"deb"},
|
|
|
|
},
|
2017-06-05 18:28:29 +02:00
|
|
|
Archive: config.Archive{
|
2017-06-08 11:41:09 +02:00
|
|
|
Format: "binary",
|
2017-06-05 18:28:29 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
assert.NoError(Pipe{}.Run(ctx))
|
|
|
|
}
|
|
|
|
|
2017-04-15 20:41:41 +02:00
|
|
|
func TestRunPipe(t *testing.T) {
|
|
|
|
var assert = assert.New(t)
|
|
|
|
folder, err := ioutil.TempDir("", "archivetest")
|
|
|
|
assert.NoError(err)
|
|
|
|
var dist = filepath.Join(folder, "dist")
|
|
|
|
assert.NoError(os.Mkdir(dist, 0755))
|
|
|
|
assert.NoError(os.Mkdir(filepath.Join(dist, "mybin"), 0755))
|
2017-07-14 03:40:44 +02:00
|
|
|
var binPath = filepath.Join(dist, "mybin", "mybin")
|
|
|
|
_, err = os.Create(binPath)
|
2017-04-15 20:41:41 +02:00
|
|
|
assert.NoError(err)
|
|
|
|
var ctx = &context.Context{
|
|
|
|
Config: config.Project{
|
2017-07-02 03:42:10 +02:00
|
|
|
ProjectName: "mybin",
|
|
|
|
Dist: dist,
|
2017-04-15 20:41:41 +02:00
|
|
|
FPM: config.FPM{
|
|
|
|
Formats: []string{"deb"},
|
|
|
|
Dependencies: []string{"make"},
|
|
|
|
Conflicts: []string{"git"},
|
2017-04-21 22:02:28 +02:00
|
|
|
Description: "Some description",
|
|
|
|
License: "MIT",
|
|
|
|
Maintainer: "me@me",
|
|
|
|
Vendor: "asdf",
|
|
|
|
Homepage: "https://goreleaser.github.io",
|
2017-04-15 20:41:41 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
2017-07-14 03:40:44 +02:00
|
|
|
for _, plat := range []string{"linuxamd64", "linux386", "darwinamd64"} {
|
|
|
|
ctx.AddBinary(plat, "mybin", "mybin", binPath)
|
|
|
|
}
|
2017-04-15 20:41:41 +02:00
|
|
|
assert.NoError(Pipe{}.Run(ctx))
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestNoFPMInPath(t *testing.T) {
|
|
|
|
var assert = assert.New(t)
|
|
|
|
var path = os.Getenv("PATH")
|
|
|
|
defer func() {
|
|
|
|
assert.NoError(os.Setenv("PATH", path))
|
|
|
|
}()
|
2017-04-21 20:45:56 +02:00
|
|
|
assert.NoError(os.Setenv("PATH", ""))
|
2017-04-15 20:41:41 +02:00
|
|
|
var ctx = &context.Context{
|
|
|
|
Config: config.Project{
|
|
|
|
FPM: config.FPM{
|
|
|
|
Formats: []string{"deb"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
assert.EqualError(Pipe{}.Run(ctx), ErrNoFPM.Error())
|
|
|
|
}
|
2017-04-22 15:41:58 +02:00
|
|
|
|
|
|
|
func TestCreateFileDoesntExist(t *testing.T) {
|
|
|
|
var assert = assert.New(t)
|
|
|
|
folder, err := ioutil.TempDir("", "archivetest")
|
|
|
|
assert.NoError(err)
|
|
|
|
var dist = filepath.Join(folder, "dist")
|
|
|
|
assert.NoError(os.Mkdir(dist, 0755))
|
|
|
|
assert.NoError(os.Mkdir(filepath.Join(dist, "mybin"), 0755))
|
|
|
|
var ctx = &context.Context{
|
|
|
|
Config: config.Project{
|
|
|
|
Dist: dist,
|
|
|
|
FPM: config.FPM{
|
|
|
|
Formats: []string{"deb"},
|
2017-08-09 03:54:23 +02:00
|
|
|
Files: map[string]string{
|
|
|
|
"testdata/testfile.txt": "/var/lib/test/testfile.txt",
|
|
|
|
},
|
2017-04-22 15:41:58 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
2017-07-14 03:40:44 +02:00
|
|
|
ctx.AddBinary("linuxamd64", "mybin", "mybin", filepath.Join(dist, "mybin", "mybin"))
|
2017-04-22 15:41:58 +02:00
|
|
|
assert.Error(Pipe{}.Run(ctx))
|
|
|
|
}
|
2017-08-09 03:54:23 +02:00
|
|
|
|
|
|
|
func TestRunPipeWithExtraFiles(t *testing.T) {
|
|
|
|
var assert = assert.New(t)
|
|
|
|
var ctx = &context.Context{
|
|
|
|
Config: config.Project{
|
|
|
|
FPM: config.FPM{
|
|
|
|
Formats: []string{"deb"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
assert.NoError(Pipe{}.Run(ctx))
|
|
|
|
}
|