Skip to content

Commit ea14e25

Browse files
committed
add test to replicate #751
1 parent c8d5b86 commit ea14e25

File tree

2 files changed

+153
-0
lines changed

2 files changed

+153
-0
lines changed

tools/download_test.go

+36
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,52 @@
1616
package tools
1717

1818
import (
19+
"encoding/json"
1920
"fmt"
2021
"io/ioutil"
2122
"net/http"
2223
"os"
2324
"path"
2425
"testing"
2526

27+
"github.com/arduino/go-paths-helper"
2628
"github.com/stretchr/testify/assert"
29+
"github.com/stretchr/testify/require"
2730
)
2831

32+
func TestDownloadCorrectPlatform(t *testing.T) {
33+
testCases := []struct {
34+
hostOS string
35+
hostArch string
36+
correctOSArch string
37+
}{
38+
{"linux", "amd64", "x86_64-linux-gnu"},
39+
{"linux", "386", "i686-linux-gnu"},
40+
{"darwin", "amd64", "x86_64-apple-darwin"},
41+
{"windows", "386", "i686-mingw32"},
42+
{"windows", "amd64", "i686-mingw32"},
43+
{"linux", "arm", "arm-linux-gnueabihf"},
44+
}
45+
testIndex := paths.New("testdata", "test_tool_index.json")
46+
buf, err := testIndex.ReadFile()
47+
require.NoError(t, err)
48+
49+
var data index
50+
err = json.Unmarshal(buf, &data)
51+
require.NoError(t, err)
52+
for _, tc := range testCases {
53+
OS = tc.hostOS // override `runtime.OS` for testing purposes
54+
Arch = tc.hostArch // override `runtime.ARCH` for testing purposes
55+
// Find the tool by name
56+
correctTool, correctSystem := findTool("arduino-test", "arduino-fwuploader", "2.2.2", data)
57+
require.NotNil(t, correctTool)
58+
require.NotNil(t, correctSystem)
59+
require.Equal(t, correctTool.Name, "arduino-fwuploader")
60+
require.Equal(t, correctTool.Version, "2.2.2")
61+
require.Equal(t, correctSystem.Host, tc.correctOSArch)
62+
}
63+
}
64+
2965
func Test_findBaseDir(t *testing.T) {
3066
cases := []struct {
3167
dirList []string

tools/testdata/test_tool_index.json

+117
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
{
2+
"packages": [
3+
{
4+
"name": "arduino-test",
5+
"maintainer": "Arduino",
6+
"websiteURL": "http://www.arduino.cc/",
7+
"email": "[email protected]",
8+
"help": {
9+
"online": "http://www.arduino.cc/en/Reference/HomePage"
10+
},
11+
"platforms": [
12+
{
13+
"name": "Arduino megaAVR Boards - Pre-release",
14+
"architecture": "megaavr",
15+
"version": "1.8.102",
16+
"category": "Arduino",
17+
"url": "http://downloads.arduino.cc/cores/staging/core-megaavr-1.8.102.tar.bz2",
18+
"archiveFileName": "core-megaavr-1.8.102.tar.bz2",
19+
"checksum": "SHA-256:ad5e60b828678d9ccff957032524a4c4d68b218737e7df24b905769a04dc2a6a",
20+
"size": "858620",
21+
"help": {
22+
"online": "https://github.com/arduino/ArduinoCore-megaavr/issues"
23+
},
24+
"boards": [
25+
{
26+
"name": "Arduino Uno WiFi Rev2"
27+
},
28+
{
29+
"name": "Arduino Nano Every"
30+
}
31+
],
32+
"toolsDependencies": [
33+
{
34+
"packager": "arduino",
35+
"name": "avr-gcc",
36+
"version": "7.3.0-atmel3.6.1-arduino5"
37+
},
38+
{
39+
"packager": "arduino",
40+
"name": "avrdude",
41+
"version": "7.0-arduino.3"
42+
},
43+
{
44+
"packager": "arduino",
45+
"name": "arduinoOTA",
46+
"version": "1.3.0"
47+
}
48+
]
49+
}
50+
],
51+
"tools": [
52+
{
53+
"name": "arduino-fwuploader",
54+
"version": "2.2.2",
55+
"systems": [
56+
{
57+
"host": "i686-linux-gnu",
58+
"url": "http://downloads.arduino.cc/arduino-fwuploader/arduino-fwuploader_2.2.2_Linux_32bit.tar.gz",
59+
"archiveFileName": "arduino-fwuploader_2.2.2_Linux_32bit.tar.gz",
60+
"checksum": "SHA-256:503b9f8b24c6e396d09eb64f0e1f625c6f9aa5a90b01a50d7dec6477f4a866f0",
61+
"size": "7262873"
62+
},
63+
{
64+
"host": "x86_64-linux-gnu",
65+
"url": "http://downloads.arduino.cc/arduino-fwuploader/arduino-fwuploader_2.2.2_Linux_64bit.tar.gz",
66+
"archiveFileName": "arduino-fwuploader_2.2.2_Linux_64bit.tar.gz",
67+
"checksum": "SHA-256:8d77d0b33c8b0787fe3b80191709b69d638ef2a447d9853536cda35bfafd274b",
68+
"size": "7306763"
69+
},
70+
{
71+
"host": "i686-mingw32",
72+
"url": "http://downloads.arduino.cc/arduino-fwuploader/arduino-fwuploader_2.2.2_Windows_32bit.zip",
73+
"archiveFileName": "arduino-fwuploader_2.2.2_Windows_32bit.zip",
74+
"checksum": "SHA-256:74ad9a5d369204b51be288c98d74f949ceb7a0c227ee64eb65ae179ec884c84c",
75+
"size": "7450717"
76+
},
77+
{
78+
"host": "x86_64-mingw32",
79+
"url": "http://downloads.arduino.cc/arduino-fwuploader/arduino-fwuploader_2.2.2_Windows_64bit.zip",
80+
"archiveFileName": "arduino-fwuploader_2.2.2_Windows_64bit.zip",
81+
"checksum": "SHA-256:b25ac549cb0645166613c96cf899aebc541e482fe196aada6408bd7cff2c7d02",
82+
"size": "7390999"
83+
},
84+
{
85+
"host": "x86_64-apple-darwin",
86+
"url": "http://downloads.arduino.cc/arduino-fwuploader/arduino-fwuploader_2.2.2_macOS_64bit.tar.gz",
87+
"archiveFileName": "arduino-fwuploader_2.2.2_macOS_64bit.tar.gz",
88+
"checksum": "SHA-256:2cd6168ff470457b5124ba0faf118f315be2d1b9fb4fef43eb74370cd83620a2",
89+
"size": "7306576"
90+
},
91+
{
92+
"host": "arm64-apple-darwin",
93+
"url": "http://downloads.arduino.cc/arduino-fwuploader/arduino-fwuploader_2.2.2_macOS_ARM64.tar.gz",
94+
"archiveFileName": "arduino-fwuploader_2.2.2_macOS_ARM64.tar.gz",
95+
"checksum": "SHA-256:10ae5614af4d82096b6ba0e1e07aab667fa140d2bf1d5e3407dd8ad4c6748195",
96+
"size": "6878214"
97+
},
98+
{
99+
"host": "arm-linux-gnueabihf",
100+
"url": "http://downloads.arduino.cc/arduino-fwuploader/arduino-fwuploader_2.2.2_Linux_ARMv6.tar.gz",
101+
"archiveFileName": "arduino-fwuploader_2.2.2_Linux_ARMv6.tar.gz",
102+
"checksum": "SHA-256:5aadf6e50ffe620635faf941fdf82c0765c8cba4830951bb53267ad125fc5af8",
103+
"size": "6940393"
104+
},
105+
{
106+
"host": "aarch64-linux-gnu",
107+
"url": "http://downloads.arduino.cc/arduino-fwuploader/arduino-fwuploader_2.2.2_Linux_ARM64.tar.gz",
108+
"archiveFileName": "arduino-fwuploader_2.2.2_Linux_ARM64.tar.gz",
109+
"checksum": "SHA-256:6d11a4f4aa5a81de865f3d18ca395a2780fdbb1e1597a2b11b2b5329e09f30fd",
110+
"size": "6829396"
111+
}
112+
]
113+
}
114+
]
115+
}
116+
]
117+
}

0 commit comments

Comments
 (0)