|
16 | 16 | package tools
|
17 | 17 |
|
18 | 18 | import (
|
| 19 | + "encoding/json" |
19 | 20 | "fmt"
|
20 | 21 | "io/ioutil"
|
21 | 22 | "net/http"
|
22 | 23 | "os"
|
23 | 24 | "path"
|
24 | 25 | "testing"
|
25 | 26 |
|
| 27 | + "github.com/arduino/go-paths-helper" |
26 | 28 | "github.com/stretchr/testify/assert"
|
| 29 | + "github.com/stretchr/testify/require" |
27 | 30 | )
|
28 | 31 |
|
| 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 | + |
29 | 66 | func Test_findBaseDir(t *testing.T) {
|
30 | 67 | cases := []struct {
|
31 | 68 | dirList []string
|
|
0 commit comments