@@ -15,70 +15,231 @@ import (
1515 bversion "github.com/elastic/elastic-agent/version"
1616)
1717
18- var (
19- versionList = []string {
20- "7.17.13" ,
21- "7.17.14" ,
22- "7.17.15" ,
23- "7.17.16" ,
24- "7.17.17" ,
25- "7.17.18" ,
26- "8.9.2" ,
27- "8.10.0" ,
28- "8.10.1" ,
29- "8.10.2" ,
30- "8.10.3" ,
31- "8.10.4" ,
32- "8.11.0" ,
33- "8.11.1" ,
34- "8.11.2" ,
35- "8.11.3" ,
36- "8.11.4" ,
37- "8.12.0" ,
38- "8.12.1" ,
39- "8.12.2" ,
40- "8.13.0" ,
41- }
42- snapshotList = []string {
43- "7.17.19-SNAPSHOT" ,
44- "8.12.2-SNAPSHOT" ,
45- "8.13.0-SNAPSHOT" ,
46- "8.14.0-SNAPSHOT" ,
47- }
48- )
49-
5018func TestFetchUpgradableVersionsAfterFeatureFreeze (t * testing.T ) {
5119 ctx , cancel := context .WithCancel (context .Background ())
5220 defer cancel ()
5321
54- expectedUpgradableVersions := []string {
55- "8.13.0-SNAPSHOT" ,
56- "8.12.2" ,
57- "8.12.2-SNAPSHOT" ,
58- "8.12.1" ,
59- "8.12.0" ,
60- "8.11.4" ,
61- "7.17.18" ,
62- }
22+ for _ , tc := range []struct {
23+ name string
24+ expectedUpgradableVersions []string
25+ versionReqs VersionRequirements
26+ fetchVersions []string
27+ snapshotFetchVersions []string
28+ }{
29+ {
30+ name : "generic case" ,
31+ expectedUpgradableVersions : []string {
32+ "8.12.2" ,
33+ "8.12.2-SNAPSHOT" ,
34+ "8.12.1" ,
35+ "8.12.0" ,
36+ "8.11.4" ,
37+ "7.17.19-SNAPSHOT" ,
38+ "7.17.18" ,
39+ },
40+ versionReqs : VersionRequirements {
41+ UpgradeToVersion : "8.13.0" , // to test that 8.14 is not returned
42+ CurrentMajors : 3 , // should return 8.12.2, 8.12.1, 8.12.0
43+ PreviousMajors : 3 , // should return 7.17.18
44+ PreviousMinors : 2 , // should return 8.12.2, 8.11.4
45+ SnapshotBranches : []string {"8.13" , "8.12" }, // should return 8.13.0-SNAPSHOT, 8.12.2-SNAPSHOT
46+ },
47+ fetchVersions : []string {
48+ "7.17.13" ,
49+ "7.17.14" ,
50+ "7.17.15" ,
51+ "7.17.16" ,
52+ "7.17.17" ,
53+ "7.17.18" ,
54+ "8.9.2" ,
55+ "8.10.0" ,
56+ "8.10.1" ,
57+ "8.10.2" ,
58+ "8.10.3" ,
59+ "8.10.4" ,
60+ "8.11.0" ,
61+ "8.11.1" ,
62+ "8.11.2" ,
63+ "8.11.3" ,
64+ "8.11.4" ,
65+ "8.12.0" ,
66+ "8.12.1" ,
67+ "8.12.2" ,
68+ "8.13.0" ,
69+ },
70+ snapshotFetchVersions : []string {
71+ "7.17.19-SNAPSHOT" ,
72+ "8.12.2-SNAPSHOT" ,
73+ "8.13.0-SNAPSHOT" ,
74+ "8.14.0-SNAPSHOT" ,
75+ },
76+ },
6377
64- reqs := VersionRequirements {
65- UpgradeToVersion : "8.13.0" , // to test that 8.14 is not returned
66- CurrentMajors : 3 , // should return 8.12.2, 8.12.1, 8.12.0
67- PreviousMajors : 3 , // should return 7.17.18
68- PreviousMinors : 2 , // should return 8.12.2, 8.11.4
69- SnapshotBranches : []string {"8.13" , "8.12" }, // should return 8.13.0-SNAPSHOT, 8.12.2-SNAPSHOT
70- }
78+ {
79+ name : "9.1.x case" ,
80+ expectedUpgradableVersions : []string {
81+ "9.0.2-SNAPSHOT" ,
82+ "9.0.1" ,
83+ "8.19.0-SNAPSHOT" ,
84+ "8.18.2" ,
85+ "7.17.29-SNAPSHOT" ,
86+ },
87+ versionReqs : VersionRequirements {
88+ UpgradeToVersion : "9.1.0" ,
89+ CurrentMajors : 1 ,
90+ PreviousMajors : 1 ,
91+ PreviousMinors : 2 ,
92+ SnapshotBranches : []string {"9.0" , "8.19" , "7.17" },
93+ },
94+ fetchVersions : []string {
95+ "7.17.27" ,
96+ "7.17.28" ,
97+ "8.17.5" ,
98+ "8.17.6" ,
99+ "8.18.1" ,
100+ "8.18.2" ,
101+ "9.0.1" ,
102+ },
103+ snapshotFetchVersions : []string {
104+ "7.17.29-SNAPSHOT" ,
105+ "8.19.0-SNAPSHOT" ,
106+ "9.0.2-SNAPSHOT" ,
107+ },
108+ },
109+ {
110+ name : "9.0.x case" ,
111+ expectedUpgradableVersions : []string {
112+ "8.19.0-SNAPSHOT" ,
113+ "8.18.2" ,
114+ "8.17.6" ,
115+ "7.17.29-SNAPSHOT" ,
116+ },
117+ versionReqs : VersionRequirements {
118+ UpgradeToVersion : "9.0.2" , // to test that 8.14 is not returned
119+ CurrentMajors : 1 , // should return 8.12.2, 8.12.1, 8.12.0
120+ PreviousMajors : 1 , // should return 7.17.18
121+ PreviousMinors : 2 , // should return 8.12.2, 8.11.4
122+ SnapshotBranches : []string {"9.0" , "8.19" , "7.17" }, // should return 8.13.0-SNAPSHOT, 8.12.2-SNAPSHOT
123+ },
124+ fetchVersions : []string {
125+ "7.17.28" ,
126+ "7.17.29" ,
127+ "8.17.5" ,
128+ "8.17.6" ,
129+ "8.18.1" ,
130+ "8.18.2" ,
131+ "9.0.1" ,
132+ },
133+ snapshotFetchVersions : []string {
134+ "7.17.29-SNAPSHOT" ,
135+ "8.19.0-SNAPSHOT" ,
136+ "9.0.3-SNAPSHOT" ,
137+ },
138+ },
139+ {
140+ name : "8.19.x case" ,
141+ expectedUpgradableVersions : []string {
142+ "8.18.2" ,
143+ "8.17.6" ,
144+ "7.17.29-SNAPSHOT" ,
145+ "7.17.28" ,
146+ },
147+ versionReqs : VersionRequirements {
148+ UpgradeToVersion : "8.19.0" ,
149+ CurrentMajors : 1 ,
150+ PreviousMajors : 1 ,
151+ PreviousMinors : 2 ,
152+ SnapshotBranches : []string {"9.0" , "8.19" , "7.17" },
153+ },
154+ fetchVersions : []string {
155+ "7.17.28" ,
156+ "8.17.5" ,
157+ "8.17.6" ,
158+ "8.18.1" ,
159+ "8.18.2" ,
160+ "9.0.1" ,
161+ },
162+ snapshotFetchVersions : []string {
163+ "7.17.29-SNAPSHOT" ,
164+ "8.19.0-SNAPSHOT" , // this should be excluded
165+ "9.0.3-SNAPSHOT" ,
166+ },
167+ },
168+ {
169+ name : "8.18.x case" ,
170+ expectedUpgradableVersions : []string {
171+ "8.17.6" ,
172+ "8.16.6" ,
173+ "7.17.29-SNAPSHOT" ,
174+ "7.17.28" ,
175+ },
176+ versionReqs : VersionRequirements {
177+ UpgradeToVersion : "8.18.2" ,
178+ CurrentMajors : 1 ,
179+ PreviousMajors : 1 ,
180+ PreviousMinors : 2 ,
181+ SnapshotBranches : []string {"9.0" , "8.19" , "7.17" },
182+ },
183+ fetchVersions : []string {
184+ "7.17.28" ,
185+ "8.16.5" ,
186+ "8.16.6" ,
187+ "8.17.5" ,
188+ "8.17.6" ,
189+ "8.18.1" ,
190+ "8.18.2" ,
191+ "9.0.1" ,
192+ },
193+ snapshotFetchVersions : []string {
194+ "7.17.29-SNAPSHOT" ,
195+ "8.19.0-SNAPSHOT" ,
196+ "9.0.3-SNAPSHOT" ,
197+ },
198+ },
199+ {
200+ name : "8.17.x case" ,
201+ expectedUpgradableVersions : []string {
202+ "8.16.6" ,
203+ "7.17.29-SNAPSHOT" ,
204+ "7.17.28" ,
205+ },
206+ versionReqs : VersionRequirements {
207+ UpgradeToVersion : "8.17.6" ,
208+ CurrentMajors : 1 ,
209+ PreviousMajors : 1 ,
210+ PreviousMinors : 2 ,
211+ SnapshotBranches : []string {"9.0" , "8.19" , "7.17" },
212+ },
213+ fetchVersions : []string {
214+ "7.17.28" ,
215+ "8.16.5" ,
216+ "8.16.6" ,
217+ "8.17.5" ,
218+ "8.17.6" ,
219+ "8.18.1" ,
220+ "8.18.2" ,
221+ "9.0.1" ,
222+ },
223+ snapshotFetchVersions : []string {
224+ "7.17.29-SNAPSHOT" ,
225+ "8.19.0-SNAPSHOT" ,
226+ "9.0.3-SNAPSHOT" ,
227+ },
228+ },
229+ } {
230+ t .Run (tc .name , func (t * testing.T ) {
231+ vf := fetcherMock {
232+ list : buildVersionList (t , tc .fetchVersions ),
233+ }
234+ sf := fetcherMock {
235+ list : buildVersionList (t , tc .snapshotFetchVersions ),
236+ }
71237
72- vf := fetcherMock {
73- list : buildVersionList (t , versionList ),
74- }
75- sf := fetcherMock {
76- list : buildVersionList (t , snapshotList ),
238+ upgradableVersions , err := FetchUpgradableVersions (ctx , vf , sf , tc .versionReqs )
239+ require .NoError (t , err )
240+ require .Equal (t , tc .expectedUpgradableVersions , upgradableVersions )
241+ })
77242 }
78-
79- versions , err := FetchUpgradableVersions (ctx , vf , sf , reqs )
80- require .NoError (t , err )
81- assert .Equal (t , expectedUpgradableVersions , versions )
82243}
83244
84245func TestGetUpgradableVersions (t * testing.T ) {
0 commit comments