-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathversion_test.go
More file actions
122 lines (97 loc) · 2.92 KB
/
Copy pathversion_test.go
File metadata and controls
122 lines (97 loc) · 2.92 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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
package main
import (
"strings"
"testing"
)
func TestGetVersion(t *testing.T) {
version := GetVersion()
if version == "" {
t.Error("GetVersion() returned empty string")
}
if version != Version {
t.Errorf("GetVersion() = %q, want %q", version, Version)
}
}
func TestGetFullVersion(t *testing.T) {
fullVersion := GetFullVersion()
if fullVersion == "" {
t.Error("GetFullVersion() returned empty string")
}
expected := AppName + " " + Version
if fullVersion != expected {
t.Errorf("GetFullVersion() = %q, want %q", fullVersion, expected)
}
}
func TestVersionConstants(t *testing.T) {
// Test that version constants are defined
if Version == "" {
t.Error("Version constant is empty")
}
if AppName == "" {
t.Error("AppName constant is empty")
}
// Test that version follows semantic versioning pattern
if !strings.Contains(Version, "v") {
t.Error("Version should start with 'v'")
}
// Test that app name is reasonable
if AppName != "WrapGuard" {
t.Errorf("AppName = %q, want %q", AppName, "WrapGuard")
}
}
func TestVersionFormat(t *testing.T) {
// Test version format (should be something like v1.0.0-dev)
version := GetVersion()
if !strings.HasPrefix(version, "v") {
t.Errorf("Version should start with 'v', got %q", version)
}
// Check for development version indicator
if strings.Contains(version, "dev") {
if !strings.Contains(version, "-dev") {
t.Errorf("Development version should contain '-dev', got %q", version)
}
}
}
func TestFullVersionFormat(t *testing.T) {
fullVersion := GetFullVersion()
// Should contain both app name and version
if !strings.Contains(fullVersion, AppName) {
t.Errorf("Full version should contain app name %q, got %q", AppName, fullVersion)
}
if !strings.Contains(fullVersion, Version) {
t.Errorf("Full version should contain version %q, got %q", Version, fullVersion)
}
// Should be in format "AppName Version"
parts := strings.Split(fullVersion, " ")
if len(parts) != 2 {
t.Errorf("Full version should have format 'AppName Version', got %q", fullVersion)
}
if parts[0] != AppName {
t.Errorf("First part should be app name %q, got %q", AppName, parts[0])
}
if parts[1] != Version {
t.Errorf("Second part should be version %q, got %q", Version, parts[1])
}
}
// Test version consistency across the module
func TestVersionModuleConsistency(t *testing.T) {
// The version module should be internally consistent
if GetVersion() != Version {
t.Errorf("GetVersion() != Version constant: %q != %q", GetVersion(), Version)
}
expectedFull := AppName + " " + Version
if GetFullVersion() != expectedFull {
t.Errorf("GetFullVersion() != expected: %q != %q", GetFullVersion(), expectedFull)
}
}
// Benchmark tests for performance (though these are simple functions)
func BenchmarkGetVersion(b *testing.B) {
for i := 0; i < b.N; i++ {
_ = GetVersion()
}
}
func BenchmarkGetFullVersion(b *testing.B) {
for i := 0; i < b.N; i++ {
_ = GetFullVersion()
}
}