1
0
mirror of https://github.com/goreleaser/goreleaser.git synced 2025-01-24 04:16:27 +02:00
goreleaser/main_test.go
Oleksandr Redko 00a376cc64
refactor: remove unneeded in Go 1.22 loop var copy (#4856)
The PR cleans up unnecessary loop variable copying and enables the
[`copyloopvar`](https://golangci-lint.run/usage/linters/#copyloopvar)
linter for detecting this redundant variable copying.

#### Additional notes

After the project upgraded to Go version 1.22 in #4779, copying
variables inside a `for` loop became unnecessary. See this [blog
post](https://go.dev/blog/loopvar-preview) for a detailed explanation.

The `copyloopvar` linter is only available from `golangci-lint` v1.57
onwards, so we also need to update this tool.
2024-05-12 13:21:13 -03:00

51 lines
1.0 KiB
Go

package main
import (
"testing"
"github.com/goreleaser/goreleaser/internal/golden"
"github.com/stretchr/testify/require"
)
func TestVersion(t *testing.T) {
const goVersion = "go1.20.3"
const compiler = "gc"
const platform = "linux/amd64"
for name, tt := range map[string]struct {
version, commit, date, builtBy, treeState string
}{
"all empty": {},
"complete": {
version: "1.2.3",
date: "12/12/12",
commit: "aaaa",
builtBy: "me",
treeState: "clean",
},
"only version": {
version: "1.2.3",
},
"version and date": {
version: "1.2.3",
date: "12/12/12",
},
"version, date, built by": {
version: "1.2.3",
date: "12/12/12",
builtBy: "me",
},
} {
t.Run(name, func(t *testing.T) {
v := buildVersion(tt.version, tt.commit, tt.date, tt.builtBy, tt.treeState)
v.GoVersion = goVersion
v.Compiler = compiler
v.Platform = platform
out, err := v.JSONString()
require.NoError(t, err)
golden.RequireEqualJSON(t, []byte(out))
})
}
}