Skip to content

Commit e5d5c53

Browse files
committed
WIP: adding test for 'core' command
1 parent 6edf0dd commit e5d5c53

File tree

1 file changed

+53
-1
lines changed

1 file changed

+53
-1
lines changed

commands/commands_test.go

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import (
3434
"fmt"
3535
"io/ioutil"
3636
"os"
37+
"strings"
3738
"testing"
3839

3940
"github.com/arduino/go-paths-helper"
@@ -281,6 +282,38 @@ func updateCoreIndex(t *testing.T) {
281282
require.Equal(t, 0, exitCode, "exit code")
282283
}
283284

285+
func detectLatestAVRCore(t *testing.T) string {
286+
jsonFile := paths.New(os.Getenv("ARDUINO_DATA_DIR")).Join("package_index.json")
287+
type index struct {
288+
Packages []struct {
289+
Name string
290+
Platforms []struct {
291+
Architecture string
292+
Version string
293+
}
294+
}
295+
}
296+
var jsonIndex index
297+
jsonData, err := jsonFile.ReadFile()
298+
require.NoError(t, err, "reading package_index.json")
299+
err = json.Unmarshal(jsonData, &jsonIndex)
300+
require.NoError(t, err, "parsing package_index.json")
301+
latest := ""
302+
for _, p := range jsonIndex.Packages {
303+
if p.Name == "arduino" {
304+
for _, pl := range p.Platforms {
305+
if pl.Architecture == "avr" && pl.Version > latest {
306+
latest = pl.Version
307+
}
308+
}
309+
break
310+
}
311+
}
312+
require.NotEmpty(t, latest, "latest avr core version")
313+
fmt.Println("Latest AVR core version:", latest)
314+
return latest
315+
}
316+
284317
func TestCoreDownload(t *testing.T) {
285318
defer makeTempDataDir(t)()
286319
defer makeTempSketchbookDir(t)()
@@ -291,14 +324,22 @@ func TestCoreDownload(t *testing.T) {
291324
defer os.RemoveAll(tmp)
292325

293326
updateCoreIndex(t)
294-
327+
AVR := "arduino:avr@" + detectLatestAVRCore(t)
328+
return
329+
// Download a specific core version
295330
exitCode, d := executeWithArgs(t, "core", "download", "arduino:[email protected]")
296331
require.Zero(t, exitCode, "exit code")
297332
require.Contains(t, string(d), "arduino:[email protected] downloaded")
298333
require.Contains(t, string(d), "arduino:[email protected] downloaded")
299334
require.Contains(t, string(d), "arduino:[email protected] downloaded")
300335
require.Contains(t, string(d), "arduino:[email protected] downloaded")
301336

337+
// Download latest
338+
exitCode, d = executeWithArgs(t, "core", "download", "arduino:avr")
339+
require.Zero(t, exitCode, "exit code")
340+
require.Contains(t, string(d), AVR+" downloaded")
341+
342+
// Wrong downloads
302343
exitCode, d = executeWithArgs(t, "core", "download", "arduino:[email protected]")
303344
require.NotZero(t, exitCode, "exit code")
304345
require.Contains(t, string(d), "required version 1.2.3-notexisting not found for platform arduino:samd")
@@ -310,4 +351,15 @@ func TestCoreDownload(t *testing.T) {
310351
exitCode, d = executeWithArgs(t, "core", "download", "wrongparameter")
311352
require.NotZero(t, exitCode, "exit code")
312353
require.Contains(t, string(d), "invalid item")
354+
355+
// Empty cores list
356+
exitCode, d = executeWithArgs(t, "core", "download", "wrongparameter")
357+
require.NotZero(t, exitCode, "exit code")
358+
require.Empty(t, strings.TrimSpace(string(d)))
359+
360+
// Install avr
361+
exitCode, d = executeWithArgs(t, "core", "install", "arduino:avr")
362+
require.Zero(t, exitCode, "exit code")
363+
require.Contains(t, string(d), "arduino:[email protected] downloaded")
364+
313365
}

0 commit comments

Comments
 (0)