mirror of
https://github.com/goreleaser/goreleaser.git
synced 2025-03-17 20:47:50 +02:00
fix: use bin name instead of bin path to set snap app config (#1002)
* fix: use bin name instead of bin path to set snap app config * feat: add testcase for snap with binary in dir
This commit is contained in:
parent
310bf450a8
commit
2de196a745
@ -159,7 +159,7 @@ func create(ctx *context.Context, arch string, binaries []artifact.Artifact) err
|
||||
appMetadata := AppMetadata{
|
||||
Command: name,
|
||||
}
|
||||
if configAppMetadata, ok := ctx.Config.Snapcraft.Apps[binary.Name]; ok {
|
||||
if configAppMetadata, ok := ctx.Config.Snapcraft.Apps[name]; ok {
|
||||
appMetadata.Plugs = configAppMetadata.Plugs
|
||||
appMetadata.Daemon = configAppMetadata.Daemon
|
||||
appMetadata.Command = strings.Join([]string{
|
||||
|
@ -58,7 +58,7 @@ func TestRunPipe(t *testing.T) {
|
||||
})
|
||||
ctx.Git.CurrentTag = "v1.2.3"
|
||||
ctx.Version = "v1.2.3"
|
||||
addBinaries(t, ctx, "mybin", dist)
|
||||
addBinaries(t, ctx, "mybin", dist, "mybin")
|
||||
assert.NoError(t, Pipe{}.Run(ctx))
|
||||
assert.Len(t, ctx.Artifacts.Filter(artifact.ByType(artifact.PublishableSnapcraft)).List(), 2)
|
||||
}
|
||||
@ -80,7 +80,7 @@ func TestRunPipeInvalidNameTemplate(t *testing.T) {
|
||||
})
|
||||
ctx.Git.CurrentTag = "v1.2.3"
|
||||
ctx.Version = "v1.2.3"
|
||||
addBinaries(t, ctx, "mybin", dist)
|
||||
addBinaries(t, ctx, "mybin", dist, "mybin")
|
||||
assert.EqualError(t, Pipe{}.Run(ctx), `template: tmpl:1: unexpected "}" in operand`)
|
||||
}
|
||||
|
||||
@ -102,7 +102,37 @@ func TestRunPipeWithName(t *testing.T) {
|
||||
})
|
||||
ctx.Git.CurrentTag = "v1.2.3"
|
||||
ctx.Version = "v1.2.3"
|
||||
addBinaries(t, ctx, "testprojectname", dist)
|
||||
addBinaries(t, ctx, "testprojectname", dist, "mybin")
|
||||
assert.NoError(t, Pipe{}.Run(ctx))
|
||||
yamlFile, err := ioutil.ReadFile(filepath.Join(dist, "foo_amd64", "prime", "meta", "snap.yaml"))
|
||||
assert.NoError(t, err)
|
||||
var metadata Metadata
|
||||
err = yaml.Unmarshal(yamlFile, &metadata)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, "testsnapname", metadata.Name)
|
||||
assert.Equal(t, "mybin", metadata.Apps["mybin"].Command)
|
||||
assert.Equal(t, "mybin", metadata.Apps["testsnapname"].Command)
|
||||
}
|
||||
|
||||
func TestRunPipeWithBinaryInDir(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, err)
|
||||
var ctx = context.New(config.Project{
|
||||
ProjectName: "testprojectname",
|
||||
Dist: dist,
|
||||
Snapcraft: config.Snapcraft{
|
||||
NameTemplate: "foo_{{.Arch}}",
|
||||
Name: "testsnapname",
|
||||
Summary: "test summary",
|
||||
Description: "test description",
|
||||
},
|
||||
})
|
||||
ctx.Git.CurrentTag = "v1.2.3"
|
||||
ctx.Version = "v1.2.3"
|
||||
addBinaries(t, ctx, "testprojectname", dist, "bin/mybin")
|
||||
assert.NoError(t, Pipe{}.Run(ctx))
|
||||
yamlFile, err := ioutil.ReadFile(filepath.Join(dist, "foo_amd64", "prime", "meta", "snap.yaml"))
|
||||
assert.NoError(t, err)
|
||||
@ -143,7 +173,7 @@ func TestRunPipeMetadata(t *testing.T) {
|
||||
})
|
||||
ctx.Git.CurrentTag = "v1.2.3"
|
||||
ctx.Version = "v1.2.3"
|
||||
addBinaries(t, ctx, "mybin", dist)
|
||||
addBinaries(t, ctx, "mybin", dist, "mybin")
|
||||
assert.NoError(t, Pipe{}.Run(ctx))
|
||||
yamlFile, err := ioutil.ReadFile(filepath.Join(dist, "foo_amd64", "prime", "meta", "snap.yaml"))
|
||||
assert.NoError(t, err)
|
||||
@ -203,7 +233,7 @@ func TestDefaultSet(t *testing.T) {
|
||||
assert.Equal(t, "foo", ctx.Config.Snapcraft.NameTemplate)
|
||||
}
|
||||
|
||||
func addBinaries(t *testing.T, ctx *context.Context, name, dist string) {
|
||||
func addBinaries(t *testing.T, ctx *context.Context, name, dist, dest string) {
|
||||
for _, goos := range []string{"linux", "darwin"} {
|
||||
for _, goarch := range []string{"amd64", "386", "arm6"} {
|
||||
var folder = goos + goarch
|
||||
@ -212,7 +242,7 @@ func addBinaries(t *testing.T, ctx *context.Context, name, dist string) {
|
||||
_, err := os.Create(binPath)
|
||||
assert.NoError(t, err)
|
||||
ctx.Artifacts.Add(artifact.Artifact{
|
||||
Name: "mybin",
|
||||
Name: dest,
|
||||
Path: binPath,
|
||||
Goarch: goarch,
|
||||
Goos: goos,
|
||||
|
Loading…
x
Reference in New Issue
Block a user