-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathversion_test.go
More file actions
84 lines (72 loc) · 2.06 KB
/
version_test.go
File metadata and controls
84 lines (72 loc) · 2.06 KB
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
package main
import (
"strings"
"testing"
)
func TestGetVersion(t *testing.T) {
// Test that GetVersion returns a value
version := GetVersion()
if version == "" {
t.Error("GetVersion() should not return empty string")
}
}
func TestGetFullVersion(t *testing.T) {
// Test that GetFullVersion returns a value
fullVersion := GetFullVersion()
if fullVersion == "" {
t.Error("GetFullVersion() should not return empty string")
}
// Full version should contain version info
if !strings.Contains(fullVersion, "v") && GetVersion() != "dev" {
t.Error("Full version should contain 'v' prefix for non-dev versions")
}
}
func TestGetOsInfo(t *testing.T) {
// Test that GetOsInfo returns a value
osInfo := GetOsInfo()
if osInfo == "" {
t.Error("GetOsInfo() should not return empty string")
}
// Should contain GOOS and GOARCH
if !strings.Contains(osInfo, " ") {
t.Error("OS info should contain space-separated OS and arch")
}
}
func TestVersionFormat(t *testing.T) {
version := GetVersion()
// If not dev, version should follow semver format
if version != "dev" {
// Check basic semver format (at least x.y.z)
parts := strings.Split(version, ".")
if len(parts) < 3 {
t.Errorf("Version %s should have at least 3 parts (semver)", version)
}
}
}
func TestGetBuildInfo(t *testing.T) {
buildInfo := GetBuildInfo()
if buildInfo == "" {
t.Error("GetBuildInfo() should not return empty string")
}
// Build info should contain "Version:"
if !strings.Contains(buildInfo, "Version:") {
t.Error("Build info should contain 'Version:'")
}
}
func TestIsVersionNewer(t *testing.T) {
tests := []struct {
current string
latest string
expect bool
}{
{current: "1.1.0", latest: "1.2.0", expect: true},
{current: "1.10.0", latest: "1.9.9", expect: false},
{current: "1.1.0", latest: "v1.1.1", expect: true},
{current: "1.1.0", latest: "1.1.0", expect: false},
}
for _, tt := range tests {
if got := isVersionNewer(tt.current, tt.latest); got != tt.expect {
t.Fatalf("isVersionNewer(%q, %q) = %v, want %v", tt.current, tt.latest, got, tt.expect)
}
}
}