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

83 lines
1.9 KiB
Go
Raw Normal View History

2017-07-27 02:30:48 +02:00
package snapcraft
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())
}
2017-08-02 14:16:59 +02:00
func TestRunPipeMissingInfo(t *testing.T) {
for name, snap := range map[string]config.Snapcraft{
2017-08-02 14:17:19 +02:00
"missing summary": {
2017-08-02 14:16:59 +02:00
Description: "dummy desc",
2017-07-27 02:30:48 +02:00
},
2017-08-02 14:17:19 +02:00
"missing description": {
2017-08-02 14:16:59 +02:00
Summary: "dummy summary",
2017-07-27 02:30:48 +02:00
},
2017-08-02 14:16:59 +02:00
} {
t.Run(name, func(t *testing.T) {
var assert = assert.New(t)
var ctx = &context.Context{
Config: config.Project{
Snapcraft: snap,
},
}
assert.NoError(Pipe{}.Run(ctx))
})
2017-07-27 02:30:48 +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))
var binPath = filepath.Join(dist, "mybin", "mybin")
_, err = os.Create(binPath)
assert.NoError(err)
var ctx = &context.Context{
Version: "testversion",
Config: config.Project{
ProjectName: "mybin",
Dist: dist,
Snapcraft: config.Snapcraft{
Summary: "test summary",
Description: "test description",
},
},
}
for _, plat := range []string{"linuxamd64", "linux386", "darwinamd64"} {
ctx.AddBinary(plat, "mybin", "mybin", binPath)
}
assert.NoError(Pipe{}.Run(ctx))
}
func TestNoSnapcraftInPath(t *testing.T) {
var assert = assert.New(t)
var path = os.Getenv("PATH")
defer func() {
assert.NoError(os.Setenv("PATH", path))
}()
assert.NoError(os.Setenv("PATH", ""))
var ctx = &context.Context{
Config: config.Project{
Snapcraft: config.Snapcraft{
Summary: "dummy",
Description: "dummy",
},
},
}
assert.EqualError(Pipe{}.Run(ctx), ErrNoSnapcraft.Error())
}