2018-02-22 01:04:22 +02:00
|
|
|
package main
|
2017-04-21 20:25:32 +02:00
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2024-05-26 20:02:57 +02:00
|
|
|
"github.com/goreleaser/goreleaser/v2/internal/golden"
|
2019-05-28 04:59:33 +02:00
|
|
|
"github.com/stretchr/testify/require"
|
2017-04-21 20:25:32 +02:00
|
|
|
)
|
|
|
|
|
2019-05-28 04:59:33 +02:00
|
|
|
func TestVersion(t *testing.T) {
|
2023-05-03 20:00:13 +02:00
|
|
|
const goVersion = "go1.20.3"
|
|
|
|
const compiler = "gc"
|
|
|
|
const platform = "linux/amd64"
|
|
|
|
|
2019-05-28 04:59:33 +02:00
|
|
|
for name, tt := range map[string]struct {
|
2023-06-27 13:35:06 +02:00
|
|
|
version, commit, date, builtBy, treeState string
|
2019-05-28 04:59:33 +02:00
|
|
|
}{
|
2023-04-30 19:19:55 +02:00
|
|
|
"all empty": {},
|
2019-05-28 04:59:33 +02:00
|
|
|
"complete": {
|
2023-06-27 13:35:06 +02:00
|
|
|
version: "1.2.3",
|
|
|
|
date: "12/12/12",
|
|
|
|
commit: "aaaa",
|
|
|
|
builtBy: "me",
|
|
|
|
treeState: "clean",
|
2019-05-28 04:59:33 +02:00
|
|
|
},
|
|
|
|
"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) {
|
2023-06-27 13:35:06 +02:00
|
|
|
v := buildVersion(tt.version, tt.commit, tt.date, tt.builtBy, tt.treeState)
|
2023-05-03 20:00:13 +02:00
|
|
|
v.GoVersion = goVersion
|
|
|
|
v.Compiler = compiler
|
|
|
|
v.Platform = platform
|
2023-04-30 19:19:55 +02:00
|
|
|
out, err := v.JSONString()
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
golden.RequireEqualJSON(t, []byte(out))
|
2019-05-28 04:59:33 +02:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|