forked from ava-labs/avalanchego
-
Notifications
You must be signed in to change notification settings - Fork 0
/
compatibility_test.go
115 lines (109 loc) · 1.94 KB
/
compatibility_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
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
// Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved.
// See the file LICENSE for licensing terms.
package version
import (
"fmt"
"testing"
"time"
"github.com/stretchr/testify/require"
)
func TestCompatibility(t *testing.T) {
v := &Application{
Name: Client,
Major: 1,
Minor: 4,
Patch: 3,
}
minCompatible := &Application{
Name: Client,
Major: 1,
Minor: 4,
Patch: 0,
}
minCompatibleTime := time.Unix(9000, 0)
prevMinCompatible := &Application{
Name: Client,
Major: 1,
Minor: 3,
Patch: 0,
}
compatibility := NewCompatibility(
v,
minCompatible,
minCompatibleTime,
prevMinCompatible,
).(*compatibility)
require.Equal(t, v, compatibility.Version())
tests := []struct {
peer *Application
time time.Time
expectedErr error
}{
{
peer: &Application{
Name: Client,
Major: 1,
Minor: 5,
Patch: 0,
},
time: minCompatibleTime,
},
{
peer: &Application{
Name: Client,
Major: 1,
Minor: 3,
Patch: 5,
},
time: time.Unix(8500, 0),
},
{
peer: &Application{
Name: Client,
Major: 0,
Minor: 1,
Patch: 0,
},
time: minCompatibleTime,
expectedErr: errDifferentMajor,
},
{
peer: &Application{
Name: Client,
Major: 1,
Minor: 3,
Patch: 5,
},
time: minCompatibleTime,
expectedErr: errIncompatible,
},
{
peer: &Application{
Name: Client,
Major: 1,
Minor: 2,
Patch: 5,
},
time: time.Unix(8500, 0),
expectedErr: errIncompatible,
},
{
peer: &Application{
Name: Client,
Major: 1,
Minor: 1,
Patch: 5,
},
time: time.Unix(7500, 0),
expectedErr: errIncompatible,
},
}
for _, test := range tests {
peer := test.peer
compatibility.clock.Set(test.time)
t.Run(fmt.Sprintf("%s-%s", peer, test.time), func(t *testing.T) {
err := compatibility.Compatible(peer)
require.ErrorIs(t, err, test.expectedErr)
})
}
}