Skip to content

Commit 7a1c2ef

Browse files
committed
Make integration-test independent from evolving libraries version
1 parent 6e43d4d commit 7a1c2ef

File tree

1 file changed

+89
-68
lines changed

1 file changed

+89
-68
lines changed

internal/integrationtest/daemon/profile_lib_commands_test.go

Lines changed: 89 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424
"github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1"
2525
"github.com/arduino/go-paths-helper"
2626
"github.com/stretchr/testify/require"
27+
"go.bug.st/testifyjson/requirejson"
2728
)
2829

2930
func indexLibArray(l ...*commands.ProfileLibraryReference) []*commands.ProfileLibraryReference {
@@ -42,6 +43,13 @@ func indexLib(name, version string, isdep ...bool) *commands.ProfileLibraryRefer
4243
}
4344
}
4445

46+
func latestVersion(t *testing.T, cli *integrationtest.ArduinoCLI, name string) string {
47+
out, _, err := cli.Run("lib", "search", name, "--json")
48+
require.NoError(t, err)
49+
v := requirejson.Parse(t, out).Query(`.libraries[] | select(.name=="` + name + `") | .latest.version`).String()
50+
return strings.Trim(v, `"`)
51+
}
52+
4553
func TestProfileLibAddListAndRemov(t *testing.T) {
4654
env, cli := integrationtest.CreateEnvForDaemon(t)
4755
t.Cleanup(func() { env.CleanUp() })
@@ -101,13 +109,18 @@ profiles:
101109
default_profile: test
102110
`)
103111

112+
// Gather latest versions of dependencies to check later
113+
vAdafruitL3GD20U := latestVersion(t, cli, "Adafruit L3GD20 U")
114+
vAdafruitLSM303DLHC := latestVersion(t, cli, "Adafruit LSM303DLHC")
115+
vAdafruitUnifiedSensor := latestVersion(t, cli, "Adafruit Unified Sensor")
116+
vAdafruitBusIO := latestVersion(t, cli, "Adafruit BusIO")
117+
104118
// Add a library to the profile
105119
{
106120
addresp, err := grpcInst.ProfileLibAdd(t.Context(), sk.String(), "test", indexLib("ArduinoJson", "6.18.5"), true, false)
107121
require.NoError(t, err)
108122
require.Equal(t, indexLibArray(indexLib("ArduinoJson", "6.18.5")), addresp.GetAddedLibraries())
109-
}
110-
expect(`
123+
expect(`
111124
profiles:
112125
test:
113126
fqbn: arduino:avr:uno
@@ -123,6 +136,7 @@ profiles:
123136
124137
default_profile: test
125138
`)
139+
}
126140

127141
// Add a library with deps to the profile
128142
{
@@ -137,9 +151,9 @@ profiles:
137151
libraries:
138152
- ArduinoJson (6.18.5)
139153
- Adafruit 9DOF (1.1.4)
140-
- dependency: Adafruit L3GD20 U (2.0.3)
141-
- dependency: Adafruit LSM303DLHC (1.0.4)
142-
- dependency: Adafruit Unified Sensor (1.1.15)
154+
- dependency: Adafruit L3GD20 U (` + vAdafruitL3GD20U + `)
155+
- dependency: Adafruit LSM303DLHC (` + vAdafruitLSM303DLHC + `)
156+
- dependency: Adafruit Unified Sensor (` + vAdafruitUnifiedSensor + `)
143157
144158
test2:
145159
fqbn: arduino:avr:mini
@@ -150,9 +164,9 @@ default_profile: test
150164
`)
151165
require.Equal(t, indexLibArray(
152166
indexLib("Adafruit 9DOF", "1.1.4"),
153-
indexLib("Adafruit L3GD20 U", "2.0.3", true),
154-
indexLib("Adafruit LSM303DLHC", "1.0.4", true),
155-
indexLib("Adafruit Unified Sensor", "1.1.15", true),
167+
indexLib("Adafruit L3GD20 U", vAdafruitL3GD20U, true),
168+
indexLib("Adafruit LSM303DLHC", vAdafruitLSM303DLHC, true),
169+
indexLib("Adafruit Unified Sensor", vAdafruitUnifiedSensor, true),
156170
), addresp.GetAddedLibraries())
157171
}
158172

@@ -162,16 +176,15 @@ default_profile: test
162176
require.NoError(t, err)
163177
require.Equal(t, indexLibArray(
164178
indexLib("Adafruit ADG72x", "1.0.0"),
165-
indexLib("Adafruit BusIO", "1.17.4", true),
179+
indexLib("Adafruit BusIO", vAdafruitBusIO, true),
166180
), addresp.GetAddedLibraries())
167181
}
168182
{
169183
// Add a library with deps to the profile
170184
addresp, err := grpcInst.ProfileLibAdd(t.Context(), sk.String(), "test", indexLib("Adafruit ADS1X15", "2.6.0"), true, false)
171185
require.NoError(t, err)
172186
require.Equal(t, indexLibArray(indexLib("Adafruit ADS1X15", "2.6.0")), addresp.GetAddedLibraries())
173-
}
174-
expect(`
187+
expect(`
175188
profiles:
176189
test:
177190
fqbn: arduino:avr:uno
@@ -180,11 +193,11 @@ profiles:
180193
libraries:
181194
- ArduinoJson (6.18.5)
182195
- Adafruit 9DOF (1.1.4)
183-
- dependency: Adafruit L3GD20 U (2.0.3)
184-
- dependency: Adafruit LSM303DLHC (1.0.4)
185-
- dependency: Adafruit Unified Sensor (1.1.15)
196+
- dependency: Adafruit L3GD20 U (` + vAdafruitL3GD20U + `)
197+
- dependency: Adafruit LSM303DLHC (` + vAdafruitLSM303DLHC + `)
198+
- dependency: Adafruit Unified Sensor (` + vAdafruitUnifiedSensor + `)
186199
- Adafruit ADG72x (1.0.0)
187-
- dependency: Adafruit BusIO (1.17.4)
200+
- dependency: Adafruit BusIO (` + vAdafruitBusIO + `)
188201
- Adafruit ADS1X15 (2.6.0)
189202
190203
test2:
@@ -194,14 +207,14 @@ profiles:
194207
195208
default_profile: test
196209
`)
210+
}
197211

198212
// Remove a library with deps from the profile
199213
{
200214
remresp, err := grpcInst.ProfileLibRemove(t.Context(), sk.String(), "test", indexLib("Adafruit ADG72x", "1.0.0"), true)
201215
require.NoError(t, err)
202216
require.Equal(t, indexLibArray(indexLib("Adafruit ADG72x", "1.0.0")), remresp.RemovedLibraries)
203-
}
204-
expect(`
217+
expect(`
205218
profiles:
206219
test:
207220
fqbn: arduino:avr:uno
@@ -210,10 +223,10 @@ profiles:
210223
libraries:
211224
- ArduinoJson (6.18.5)
212225
- Adafruit 9DOF (1.1.4)
213-
- dependency: Adafruit L3GD20 U (2.0.3)
214-
- dependency: Adafruit LSM303DLHC (1.0.4)
215-
- dependency: Adafruit Unified Sensor (1.1.15)
216-
- dependency: Adafruit BusIO (1.17.4)
226+
- dependency: Adafruit L3GD20 U (` + vAdafruitL3GD20U + `)
227+
- dependency: Adafruit LSM303DLHC (` + vAdafruitLSM303DLHC + `)
228+
- dependency: Adafruit Unified Sensor (` + vAdafruitUnifiedSensor + `)
229+
- dependency: Adafruit BusIO (` + vAdafruitBusIO + `)
217230
- Adafruit ADS1X15 (2.6.0)
218231
219232
test2:
@@ -223,17 +236,17 @@ profiles:
223236
224237
default_profile: test
225238
`)
239+
}
226240

227241
// Remove another library with deps from the profile that will also remove some shared dependencies
228242
{
229243
remresp, err := grpcInst.ProfileLibRemove(t.Context(), sk.String(), "test", indexLib("Adafruit ADS1X15", "2.6.0"), true)
230244
require.NoError(t, err)
231245
require.Equal(t, indexLibArray(
232246
indexLib("Adafruit ADS1X15", "2.6.0"),
233-
indexLib("Adafruit BusIO", "1.17.4", true),
247+
indexLib("Adafruit BusIO", vAdafruitBusIO, true),
234248
), remresp.RemovedLibraries)
235-
}
236-
expect(`
249+
expect(`
237250
profiles:
238251
test:
239252
fqbn: arduino:avr:uno
@@ -242,9 +255,9 @@ profiles:
242255
libraries:
243256
- ArduinoJson (6.18.5)
244257
- Adafruit 9DOF (1.1.4)
245-
- dependency: Adafruit L3GD20 U (2.0.3)
246-
- dependency: Adafruit LSM303DLHC (1.0.4)
247-
- dependency: Adafruit Unified Sensor (1.1.15)
258+
- dependency: Adafruit L3GD20 U (` + vAdafruitL3GD20U + `)
259+
- dependency: Adafruit LSM303DLHC (` + vAdafruitLSM303DLHC + `)
260+
- dependency: Adafruit Unified Sensor (` + vAdafruitUnifiedSensor + `)
248261
249262
test2:
250263
fqbn: arduino:avr:mini
@@ -253,12 +266,13 @@ profiles:
253266
254267
default_profile: test
255268
`)
269+
}
256270

257271
// Now explicitly add a dependency making it no longer a (removable) dependency
258272
{
259-
addresp, err := grpcInst.ProfileLibAdd(t.Context(), sk.String(), "test", indexLib("Adafruit Unified Sensor", "1.1.15"), true, false)
273+
addresp, err := grpcInst.ProfileLibAdd(t.Context(), sk.String(), "test", indexLib("Adafruit Unified Sensor", vAdafruitUnifiedSensor), true, false)
260274
require.NoError(t, err)
261-
require.Equal(t, indexLibArray(indexLib("Adafruit Unified Sensor", "1.1.15")), addresp.GetSkippedLibraries())
275+
require.Equal(t, indexLibArray(indexLib("Adafruit Unified Sensor", vAdafruitUnifiedSensor)), addresp.GetSkippedLibraries())
262276
expect(`
263277
profiles:
264278
test:
@@ -268,9 +282,9 @@ profiles:
268282
libraries:
269283
- ArduinoJson (6.18.5)
270284
- Adafruit 9DOF (1.1.4)
271-
- dependency: Adafruit L3GD20 U (2.0.3)
272-
- dependency: Adafruit LSM303DLHC (1.0.4)
273-
- Adafruit Unified Sensor (1.1.15)
285+
- dependency: Adafruit L3GD20 U (` + vAdafruitL3GD20U + `)
286+
- dependency: Adafruit LSM303DLHC (` + vAdafruitLSM303DLHC + `)
287+
- Adafruit Unified Sensor (` + vAdafruitUnifiedSensor + `)
274288
275289
test2:
276290
fqbn: arduino:avr:mini
@@ -287,8 +301,8 @@ default_profile: test
287301
require.NoError(t, err)
288302
require.Equal(t, indexLibArray(
289303
indexLib("Adafruit 9DOF", "1.1.4"),
290-
indexLib("Adafruit L3GD20 U", "2.0.3", true),
291-
indexLib("Adafruit LSM303DLHC", "1.0.4", true),
304+
indexLib("Adafruit L3GD20 U", vAdafruitL3GD20U, true),
305+
indexLib("Adafruit LSM303DLHC", vAdafruitLSM303DLHC, true),
292306
), remresp.RemovedLibraries)
293307
expect(`
294308
profiles:
@@ -298,7 +312,7 @@ profiles:
298312
- platform: arduino:avr (1.8.6)
299313
libraries:
300314
- ArduinoJson (6.18.5)
301-
- Adafruit Unified Sensor (1.1.15)
315+
- Adafruit Unified Sensor (` + vAdafruitUnifiedSensor + `)
302316
303317
test2:
304318
fqbn: arduino:avr:mini
@@ -324,6 +338,13 @@ func TestProfileLibRemoveWithDeps(t *testing.T) {
324338
t.Cleanup(func() { tmp.RemoveAll() })
325339
sk := tmp.Join("sketch")
326340

341+
// Gather latest versions of dependencies to check later
342+
vArduinoRPClite := latestVersion(t, cli, "Arduino_RPClite")
343+
vArxContainer := latestVersion(t, cli, "ArxContainer")
344+
vArxTypeTraits := latestVersion(t, cli, "ArxTypeTraits")
345+
vDebugLog := latestVersion(t, cli, "DebugLog")
346+
vMsgPack := latestVersion(t, cli, "MsgPack")
347+
327348
// Create a new sketch
328349
_, _, err = cli.Run("sketch", "new", sk.String())
329350
require.NoError(t, err)
@@ -357,12 +378,12 @@ default_profile: test
357378
addresp, err := grpcInst.ProfileLibAdd(t.Context(), sk.String(), "test", indexLib("Arduino_RouterBridge", "0.2.2"), true, false)
358379
require.NoError(t, err)
359380
require.Equal(t, indexLibArray(
360-
indexLib("Arduino_RPClite", "0.2.0", true),
381+
indexLib("Arduino_RPClite", vArduinoRPClite, true),
361382
indexLib("Arduino_RouterBridge", "0.2.2"),
362-
indexLib("ArxContainer", "0.7.0", true),
363-
indexLib("ArxTypeTraits", "0.3.2", true),
364-
indexLib("DebugLog", "0.8.4", true),
365-
indexLib("MsgPack", "0.4.2", true),
383+
indexLib("ArxContainer", vArxContainer, true),
384+
indexLib("ArxTypeTraits", vArxTypeTraits, true),
385+
indexLib("DebugLog", vDebugLog, true),
386+
indexLib("MsgPack", vMsgPack, true),
366387
), addresp.GetAddedLibraries())
367388
expect(`
368389
profiles:
@@ -371,12 +392,12 @@ profiles:
371392
platforms:
372393
- platform: arduino:avr (1.8.6)
373394
libraries:
374-
- dependency: Arduino_RPClite (0.2.0)
395+
- dependency: Arduino_RPClite (` + vArduinoRPClite + `)
375396
- Arduino_RouterBridge (0.2.2)
376-
- dependency: ArxContainer (0.7.0)
377-
- dependency: ArxTypeTraits (0.3.2)
378-
- dependency: DebugLog (0.8.4)
379-
- dependency: MsgPack (0.4.2)
397+
- dependency: ArxContainer (` + vArxContainer + `)
398+
- dependency: ArxTypeTraits (` + vArxTypeTraits + `)
399+
- dependency: DebugLog (` + vDebugLog + `)
400+
- dependency: MsgPack (` + vMsgPack + `)
380401
381402
default_profile: test
382403
`)
@@ -388,11 +409,11 @@ default_profile: test
388409
require.NoError(t, err)
389410
require.Equal(t, indexLibArray(
390411
indexLib("Arduino_RouterBridge", "0.2.2"),
391-
indexLib("Arduino_RPClite", "0.2.0", true),
392-
indexLib("ArxContainer", "0.7.0", true),
393-
indexLib("ArxTypeTraits", "0.3.2", true),
394-
indexLib("DebugLog", "0.8.4", true),
395-
indexLib("MsgPack", "0.4.2", true),
412+
indexLib("Arduino_RPClite", vArduinoRPClite, true),
413+
indexLib("ArxContainer", vArxContainer, true),
414+
indexLib("ArxTypeTraits", vArxTypeTraits, true),
415+
indexLib("DebugLog", vDebugLog, true),
416+
indexLib("MsgPack", vMsgPack, true),
396417
), remresp.GetRemovedLibraries())
397418
expect(`
398419
profiles:
@@ -410,12 +431,12 @@ default_profile: test
410431
addresp, err := grpcInst.ProfileLibAdd(t.Context(), sk.String(), "test", indexLib("Arduino_RouterBridge", "0.2.2"), true, false)
411432
require.NoError(t, err)
412433
require.Equal(t, indexLibArray(
413-
indexLib("Arduino_RPClite", "0.2.0", true),
434+
indexLib("Arduino_RPClite", vArduinoRPClite, true),
414435
indexLib("Arduino_RouterBridge", "0.2.2"),
415-
indexLib("ArxContainer", "0.7.0", true),
416-
indexLib("ArxTypeTraits", "0.3.2", true),
417-
indexLib("DebugLog", "0.8.4", true),
418-
indexLib("MsgPack", "0.4.2", true),
436+
indexLib("ArxContainer", vArxContainer, true),
437+
indexLib("ArxTypeTraits", vArxTypeTraits, true),
438+
indexLib("DebugLog", vDebugLog, true),
439+
indexLib("MsgPack", vMsgPack, true),
419440
), addresp.GetAddedLibraries())
420441
expect(`
421442
profiles:
@@ -424,12 +445,12 @@ profiles:
424445
platforms:
425446
- platform: arduino:avr (1.8.6)
426447
libraries:
427-
- dependency: Arduino_RPClite (0.2.0)
448+
- dependency: Arduino_RPClite (` + vArduinoRPClite + `)
428449
- Arduino_RouterBridge (0.2.2)
429-
- dependency: ArxContainer (0.7.0)
430-
- dependency: ArxTypeTraits (0.3.2)
431-
- dependency: DebugLog (0.8.4)
432-
- dependency: MsgPack (0.4.2)
450+
- dependency: ArxContainer (` + vArxContainer + `)
451+
- dependency: ArxTypeTraits (` + vArxTypeTraits + `)
452+
- dependency: DebugLog (` + vDebugLog + `)
453+
- dependency: MsgPack (` + vMsgPack + `)
433454
434455
default_profile: test
435456
`)
@@ -450,10 +471,10 @@ profiles:
450471
- platform: arduino:avr (1.8.6)
451472
libraries:
452473
- Arduino_RouterBridge (0.2.2)
453-
- dependency: ArxContainer (0.7.0)
454-
- dependency: ArxTypeTraits (0.3.2)
455-
- dependency: DebugLog (0.8.4)
456-
- dependency: MsgPack (0.4.2)
474+
- dependency: ArxContainer (` + vArxContainer + `)
475+
- dependency: ArxTypeTraits (` + vArxTypeTraits + `)
476+
- dependency: DebugLog (` + vDebugLog + `)
477+
- dependency: MsgPack (` + vMsgPack + `)
457478
458479
default_profile: test
459480
`)
@@ -465,10 +486,10 @@ default_profile: test
465486
require.NoError(t, err)
466487
require.Equal(t, indexLibArray(
467488
indexLib("Arduino_RouterBridge", "0.2.2"),
468-
indexLib("ArxContainer", "0.7.0", true),
469-
indexLib("ArxTypeTraits", "0.3.2", true),
470-
indexLib("DebugLog", "0.8.4", true),
471-
indexLib("MsgPack", "0.4.2", true),
489+
indexLib("ArxContainer", vArxContainer, true),
490+
indexLib("ArxTypeTraits", vArxTypeTraits, true),
491+
indexLib("DebugLog", vDebugLog, true),
492+
indexLib("MsgPack", vMsgPack, true),
472493
), remresp.GetRemovedLibraries())
473494
expect(`
474495
profiles:

0 commit comments

Comments
 (0)