Skip to content

Commit dda7e1a

Browse files
committed
add test to replicate #751
1 parent e4cc76d commit dda7e1a

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

tools/download_test.go

+37
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,53 @@
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+
{"darwin", "arm64", "arm64-apple-darwin"},
42+
{"windows", "386", "i686-mingw32"},
43+
{"windows", "amd64", "i686-mingw32"},
44+
{"linux", "arm", "arm-linux-gnueabihf"},
45+
}
46+
testIndex := paths.New("testdata", "test_tool_index.json")
47+
buf, err := testIndex.ReadFile()
48+
require.NoError(t, err)
49+
50+
var data index
51+
err = json.Unmarshal(buf, &data)
52+
require.NoError(t, err)
53+
for _, tc := range testCases {
54+
OS = tc.hostOS // override `runtime.OS` for testing purposes
55+
Arch = tc.hostArch // override `runtime.ARCH` for testing purposes
56+
// Find the tool by name
57+
correctTool, correctSystem := findTool("arduino-test", "arduino-fwuploader", "2.2.2", data)
58+
require.NotNil(t, correctTool)
59+
require.NotNil(t, correctSystem)
60+
require.Equal(t, correctTool.Name, "arduino-fwuploader")
61+
require.Equal(t, correctTool.Version, "2.2.2")
62+
require.Equal(t, correctSystem.Host, tc.correctOSArch)
63+
}
64+
}
65+
2966
func Test_findBaseDir(t *testing.T) {
3067
cases := []struct {
3168
dirList []string

0 commit comments

Comments
 (0)