test(pkg): add tests for version

This commit is contained in:
Emmanuel BENOîT 2024-07-20 00:25:31 +02:00
parent 1a29325c34
commit 9f282c40f9
Signed by: Emmanuel BENOîT
SSH key fingerprint: SHA256:l7PFUUF5TCDsvYeQC9OnTNz08dFY7Fvf4Hv3neIqYpg

View file

@ -0,0 +1,31 @@
package version // import nocternity.net/gomonop/pkg/version
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestVersion(t *testing.T) {
type Test struct {
version, commit, status, target, expected string
}
tests := []Test{
{"", "COMMIT", "clean", "TARGET", "development version (COMMIT) TARGET"},
{"VERSION", "COMMIT", "clean", "TARGET", "VERSION (COMMIT) TARGET"},
{"", "COMMIT", "dirty", "TARGET", "development version (COMMIT*) TARGET"},
{"VERSION", "COMMIT", "dirty", "TARGET", "VERSION (COMMIT*) TARGET"},
}
for _, test := range tests {
version = test.version
commit = test.commit
status = test.status
target = test.target
result := Version()
assert.Equal(t, test.expected, result, "Expected '%s', got '%s'", test.expected, result)
}
}