-
-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathversion_test.go
78 lines (73 loc) · 1.59 KB
/
version_test.go
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
package version
import (
"testing"
)
func TestNewInfo(t *testing.T) {
info := NewInfo("TestApp")
if info.Application != "TestApp" {
t.Errorf("Expected application name 'TestApp', got '%s'", info.Application)
}
}
func TestInfoString(t *testing.T) {
info := &Info{
Application: "TestApp",
VersionString: "1.0.0",
Commit: "abc123",
Date: "2023-01-01",
}
expected := "TestApp Version: 1.0.0 Commit: abc123 Date: 2023-01-01"
if got := info.String(); got != expected {
t.Errorf("Expected '%s', got '%s'", expected, got)
}
}
func TestInfoShortString(t *testing.T) {
tests := []struct {
name string
info Info
expected string
}{
{
name: "full info",
info: Info{
Application: "TestApp",
VersionString: "1.0.0",
Commit: "abc123",
Date: "2023-01-01T12:00:00Z",
},
expected: "TestApp 1.0.0 (abc123 2023-01-01)",
},
{
name: "no commit",
info: Info{
Application: "TestApp",
VersionString: "1.0.0",
Date: "2023-01-01T12:00:00Z",
},
expected: "TestApp 1.0.0 (2023-01-01)",
},
{
name: "no date",
info: Info{
Application: "TestApp",
VersionString: "1.0.0",
Commit: "abc123",
},
expected: "TestApp 1.0.0 (abc123)",
},
{
name: "version only",
info: Info{
Application: "TestApp",
VersionString: "1.0.0",
},
expected: "TestApp 1.0.0",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := tt.info.ShortString(); got != tt.expected {
t.Errorf("Expected '%s', got '%s'", tt.expected, got)
}
})
}
}