summaryrefslogtreecommitdiff
path: root/pkg/version/version_test.go
blob: a3d9db78f1b61878fdac679e05394443c6f4ef9c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package version

import (
	"runtime"
	"testing"

	"github.com/stretchr/testify/assert"
	"github.com/stretchr/testify/require"
)

func Test_BinaryName(t *testing.T) {
	require.Equal(t, binaryName, BinaryName())
}

func Test_Version(t *testing.T) {
	assert.Regexp(t, `^v[0-9]+\.[0-9]+\.[0-9]+(\-[a-z]+)*(\+[a-z0-9]+)*$`, Version())
}

func Test_Useragent(t *testing.T) {
	assert.Regexp(t, `^[a-z\-]+:\sv[0-9]+\.[0-9]+\.[0-9]+(-[a-z]+)*(\+[a-z0-9]+)*$`, Useragent())
}

func TestGitCommit(t *testing.T) {
	expected := "unknown"
	actual := GitCommit()
	assert.Equal(t, expected, actual, "GitCommit should return the correct git commit hash")
}

func TestBuildDate(t *testing.T) {
	expected := "1970-01-01T00:00:00Z"
	actual := BuildDate()
	assert.Equal(t, expected, actual, "BuildDate should return the correct build date")
}

func TestGoVersion(t *testing.T) {
	expected := runtime.Version()
	actual := GoVersion()
	assert.Equal(t, expected, actual, "GoVersion should return the correct Go version")
}

func TestGoPlatform(t *testing.T) {
	expected := runtime.GOOS + "/" + runtime.GOARCH
	actual := GoPlatform()
	assert.Equal(t, expected, actual, "GoPlatform should return the correct Go platform")
}

func TestGoCompiler(t *testing.T) {
	expected := runtime.Compiler
	actual := GoCompiler()
	assert.Equal(t, expected, actual, "GoCompiler should return the correct Go compiler")
}