-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathversion_test.go
More file actions
115 lines (103 loc) · 2.62 KB
/
version_test.go
File metadata and controls
115 lines (103 loc) · 2.62 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
package farp
import "testing"
func TestGetVersion(t *testing.T) {
version := GetVersion()
if version.Version != ProtocolVersion {
t.Errorf("GetVersion().Version = %v, want %v", version.Version, ProtocolVersion)
}
if version.Major != ProtocolMajor {
t.Errorf("GetVersion().Major = %v, want %v", version.Major, ProtocolMajor)
}
if version.Minor != ProtocolMinor {
t.Errorf("GetVersion().Minor = %v, want %v", version.Minor, ProtocolMinor)
}
if version.Patch != ProtocolPatch {
t.Errorf("GetVersion().Patch = %v, want %v", version.Patch, ProtocolPatch)
}
}
func TestIsCompatible(t *testing.T) {
tests := []struct {
name string
manifestVersion string
want bool
}{
{
name: "exact match",
manifestVersion: "1.0.0",
want: true,
},
{
name: "same major, lower minor",
manifestVersion: "1.0.0",
want: true,
},
{
name: "same major, same minor",
manifestVersion: "1.2.0",
want: true,
},
{
name: "same major, higher minor",
manifestVersion: "1.3.0",
want: false,
},
{
name: "different major (higher)",
manifestVersion: "2.0.0",
want: false,
},
{
name: "different major (lower)",
manifestVersion: "0.9.0",
want: false,
},
{
name: "invalid version format",
manifestVersion: "invalid",
want: false,
},
{
name: "empty version",
manifestVersion: "",
want: false,
},
{
name: "partial version",
manifestVersion: "1.0",
want: false,
},
{
name: "version with extra parts",
manifestVersion: "1.0.0.0",
want: true, // Sscanf will ignore extra parts
},
{
name: "version with patch difference",
manifestVersion: "1.0.5",
want: true,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := IsCompatible(tt.manifestVersion); got != tt.want {
t.Errorf("IsCompatible(%v) = %v, want %v", tt.manifestVersion, got, tt.want)
}
})
}
}
func TestProtocolConstants(t *testing.T) {
// Verify protocol version constants are set correctly
if ProtocolMajor != 1 {
t.Errorf("ProtocolMajor = %v, want 1", ProtocolMajor)
}
if ProtocolMinor != 2 {
t.Errorf("ProtocolMinor = %v, want 2", ProtocolMinor)
}
if ProtocolPatch != 0 {
t.Errorf("ProtocolPatch = %v, want 0", ProtocolPatch)
}
expectedVersion := "1.2.0"
if ProtocolVersion != expectedVersion {
t.Errorf("ProtocolVersion = %v, want %v", ProtocolVersion, expectedVersion)
}
}