-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix goreleaser config: replacements is deprecated
- Loading branch information
Showing
2 changed files
with
63 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package collector | ||
|
||
import ( | ||
"bytes" | ||
"os" | ||
"testing" | ||
"text/template" | ||
|
||
"gopkg.in/yaml.v2" | ||
) | ||
|
||
// This file contains test cases to check name_template in .goreleaser.yaml generates expected filename. | ||
|
||
type releaseConfig struct { | ||
Archives []struct { | ||
NameTemplate string `yaml:"name_template"` | ||
} `yaml:"archives"` | ||
} | ||
|
||
type buildArg struct { | ||
ProjectName string | ||
Os string | ||
Arch string | ||
Arm int | ||
} | ||
|
||
func TestReleaseName(t *testing.T) { | ||
text, err := os.ReadFile(".goreleaser.yaml") | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
var cfg releaseConfig | ||
if err := yaml.Unmarshal(text, &cfg); err != nil { | ||
t.Fatal(err) | ||
} | ||
tmpl, err := template.New("name").Parse(cfg.Archives[0].NameTemplate) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
tests := map[string]buildArg{ | ||
"pkg_linux_x86_64": {"pkg", "linux", "amd64", 0}, | ||
"pkg_linux_i386": {"pkg", "linux", "386", 0}, | ||
"pkg_windows_x86_64": {"pkg", "windows", "amd64", 0}, | ||
"pkg_darwin_arm64": {"pkg", "darwin", "arm64", 0}, | ||
"pkg_darwin_armv6": {"pkg", "darwin", "arm", 6}, | ||
} | ||
for name, arg := range tests { | ||
var buf bytes.Buffer | ||
if err := tmpl.Execute(&buf, arg); err != nil { | ||
t.Fatal(err) | ||
} | ||
if s := buf.String(); s != name { | ||
t.Errorf("Execute(%v) = %s; want %s", arg, s, name) | ||
} | ||
} | ||
} |