1
0
mirror of https://github.com/goreleaser/goreleaser.git synced 2025-01-10 03:47:03 +02:00
goreleaser/pipeline/fpm/fpm_test.go

138 lines
3.3 KiB
Go
Raw Normal View History

2017-04-15 20:41:41 +02:00
package fpm
import (
"io/ioutil"
"os"
"path/filepath"
"runtime"
2017-04-15 20:41:41 +02:00
"testing"
"github.com/goreleaser/goreleaser/config"
"github.com/goreleaser/goreleaser/context"
2017-08-20 21:50:34 +02:00
"github.com/goreleaser/goreleaser/internal/testlib"
2017-04-15 20:41:41 +02:00
"github.com/stretchr/testify/assert"
)
func TestDescription(t *testing.T) {
assert.NotEmpty(t, Pipe{}.String())
2017-04-15 20:41:41 +02:00
}
func TestRunPipeNoFormats(t *testing.T) {
var ctx = &context.Context{
Version: "1.0.0",
Config: config.Project{},
Parallelism: runtime.NumCPU(),
2017-04-15 20:41:41 +02:00
}
2017-08-20 21:50:34 +02:00
testlib.AssertSkipped(t, Pipe{}.Run(ctx))
2017-04-15 20:41:41 +02:00
}
func TestRunPipe(t *testing.T) {
folder, err := ioutil.TempDir("", "archivetest")
assert.NoError(t, err)
2017-04-15 20:41:41 +02:00
var dist = filepath.Join(folder, "dist")
assert.NoError(t, os.Mkdir(dist, 0755))
assert.NoError(t, 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)
assert.NoError(t, err)
2017-04-15 20:41:41 +02:00
var ctx = &context.Context{
Version: "1.0.0",
Parallelism: runtime.NumCPU(),
Debug: true,
2017-04-15 20:41:41 +02:00
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{
2017-08-19 00:45:44 +02:00
Formats: []string{"deb", "rpm"},
2017-04-15 20:41:41 +02:00
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)
}
assert.NoError(t, Pipe{}.Run(ctx))
2017-04-15 20:41:41 +02:00
}
func TestNoFPMInPath(t *testing.T) {
var path = os.Getenv("PATH")
defer func() {
assert.NoError(t, os.Setenv("PATH", path))
2017-04-15 20:41:41 +02:00
}()
assert.NoError(t, os.Setenv("PATH", ""))
2017-04-15 20:41:41 +02:00
var ctx = &context.Context{
Version: "1.0.0",
Parallelism: runtime.NumCPU(),
2017-04-15 20:41:41 +02:00
Config: config.Project{
FPM: config.FPM{
2017-08-19 00:45:44 +02:00
Formats: []string{"deb", "rpm"},
2017-04-15 20:41:41 +02:00
},
},
}
assert.EqualError(t, Pipe{}.Run(ctx), ErrNoFPM.Error())
2017-04-15 20:41:41 +02:00
}
func TestCreateFileDoesntExist(t *testing.T) {
folder, err := ioutil.TempDir("", "archivetest")
assert.NoError(t, err)
var dist = filepath.Join(folder, "dist")
assert.NoError(t, os.Mkdir(dist, 0755))
assert.NoError(t, os.Mkdir(filepath.Join(dist, "mybin"), 0755))
var ctx = &context.Context{
Version: "1.0.0",
Parallelism: runtime.NumCPU(),
Config: config.Project{
Dist: dist,
FPM: config.FPM{
2017-08-19 00:45:44 +02:00
Formats: []string{"deb", "rpm"},
Files: map[string]string{
"testdata/testfile.txt": "/var/lib/test/testfile.txt",
},
},
},
}
2017-07-14 03:40:44 +02:00
ctx.AddBinary("linuxamd64", "mybin", "mybin", filepath.Join(dist, "mybin", "mybin"))
assert.Error(t, Pipe{}.Run(ctx))
}
func TestRunPipeWithExtraFiles(t *testing.T) {
var ctx = &context.Context{
Version: "1.0.0",
Parallelism: runtime.NumCPU(),
Config: config.Project{
FPM: config.FPM{
2017-08-19 00:45:44 +02:00
Formats: []string{"deb", "rpm"},
},
},
}
assert.NoError(t, Pipe{}.Run(ctx))
}
func TestDefault(t *testing.T) {
var ctx = &context.Context{
Config: config.Project{
FPM: config.FPM{},
},
}
assert.NoError(t, Pipe{}.Default(ctx))
assert.Equal(t, "/usr/local/bin", ctx.Config.FPM.Bindir)
}
func TestDefaultSet(t *testing.T) {
var ctx = &context.Context{
Config: config.Project{
FPM: config.FPM{
Bindir: "/bin",
},
},
}
assert.NoError(t, Pipe{}.Default(ctx))
assert.Equal(t, "/bin", ctx.Config.FPM.Bindir)
}