|
| 1 | +// This file is part of arduino-cli. |
| 2 | +// |
| 3 | +// Copyright 2020 ARDUINO SA (http://www.arduino.cc/) |
| 4 | +// |
| 5 | +// This software is released under the GNU General Public License version 3, |
| 6 | +// which covers the main part of arduino-cli. |
| 7 | +// The terms of this license can be found at: |
| 8 | +// https://www.gnu.org/licenses/gpl-3.0.en.html |
| 9 | +// |
| 10 | +// You can be released from the requirements of the above licenses by purchasing |
| 11 | +// a commercial license. Buying such a license is mandatory if you want to |
| 12 | +// modify or otherwise use the software for commercial activities involving the |
| 13 | +// Arduino software without disclosing the source code of your own applications. |
| 14 | +// To purchase a commercial license, send an email to [email protected]. |
| 15 | + |
| 16 | +package board |
| 17 | + |
| 18 | +import ( |
| 19 | + "context" |
| 20 | + "os" |
| 21 | + "testing" |
| 22 | + |
| 23 | + "github.com/arduino/arduino-cli/cli/instance" |
| 24 | + "github.com/arduino/arduino-cli/cli/output" |
| 25 | + "github.com/arduino/arduino-cli/commands/core" |
| 26 | + "github.com/arduino/arduino-cli/configuration" |
| 27 | + rpc "github.com/arduino/arduino-cli/rpc/commands" |
| 28 | + "github.com/arduino/go-paths-helper" |
| 29 | + "github.com/stretchr/testify/require" |
| 30 | +) |
| 31 | + |
| 32 | +func TestListAll(t *testing.T) { |
| 33 | + dataDir := paths.TempDir().Join("test", "data_dir") |
| 34 | + downloadDir := paths.TempDir().Join("test", "staging") |
| 35 | + os.Setenv("ARDUINO_DATA_DIR", dataDir.String()) |
| 36 | + os.Setenv("ARDUINO_DOWNLOADS_DIR", downloadDir.String()) |
| 37 | + dataDir.MkdirAll() |
| 38 | + downloadDir.MkdirAll() |
| 39 | + defer paths.TempDir().Join("test").RemoveAll() |
| 40 | + err := paths.New("testdata").Join("package_index.json").CopyTo(dataDir.Join("package_index.json")) |
| 41 | + require.Nil(t, err) |
| 42 | + |
| 43 | + configuration.Init(paths.TempDir().Join("test", "arduino-cli.yaml").String()) |
| 44 | + |
| 45 | + inst, err := instance.CreateInstance() |
| 46 | + require.Nil(t, err) |
| 47 | + |
| 48 | + _, err = core.PlatformInstall(context.Background(), |
| 49 | + &rpc.PlatformInstallReq{ |
| 50 | + Instance: inst, |
| 51 | + PlatformPackage: "arduino", |
| 52 | + Architecture: "avr", |
| 53 | + Version: "1.8.3", |
| 54 | + SkipPostInstall: true, |
| 55 | + }, output.NewDownloadProgressBarCB(), output.NewTaskProgressCB()) |
| 56 | + require.Nil(t, err) |
| 57 | + |
| 58 | + res, err := ListAll(context.Background(), &rpc.BoardListAllReq{ |
| 59 | + Instance: inst, |
| 60 | + SearchArgs: []string{}, |
| 61 | + IncludeHiddenBoards: true, |
| 62 | + }) |
| 63 | + require.Nil(t, err) |
| 64 | + require.NotNil(t, res) |
| 65 | + require.Equal(t, 26, len(res.Boards)) |
| 66 | + require.Contains(t, res.Boards, &rpc.BoardListItem{ |
| 67 | + Name: "Arduino Yún", |
| 68 | + FQBN: "arduino:avr:yun", |
| 69 | + IsHidden: false, |
| 70 | + }) |
| 71 | + require.Contains(t, res.Boards, &rpc.BoardListItem{ |
| 72 | + Name: "Arduino Uno", |
| 73 | + FQBN: "arduino:avr:uno", |
| 74 | + IsHidden: false, |
| 75 | + }) |
| 76 | + require.Contains(t, res.Boards, &rpc.BoardListItem{ |
| 77 | + Name: "Arduino Duemilanove or Diecimila", |
| 78 | + FQBN: "arduino:avr:diecimila", |
| 79 | + IsHidden: false, |
| 80 | + }) |
| 81 | + require.Contains(t, res.Boards, &rpc.BoardListItem{ |
| 82 | + Name: "Arduino Nano", |
| 83 | + FQBN: "arduino:avr:nano", |
| 84 | + IsHidden: false, |
| 85 | + }) |
| 86 | + require.Contains(t, res.Boards, &rpc.BoardListItem{ |
| 87 | + Name: "Arduino Mega or Mega 2560", |
| 88 | + FQBN: "arduino:avr:mega", |
| 89 | + IsHidden: false, |
| 90 | + }) |
| 91 | + require.Contains(t, res.Boards, &rpc.BoardListItem{ |
| 92 | + Name: "Arduino Mega ADK", |
| 93 | + FQBN: "arduino:avr:megaADK", |
| 94 | + IsHidden: false, |
| 95 | + }) |
| 96 | + require.Contains(t, res.Boards, &rpc.BoardListItem{ |
| 97 | + Name: "Arduino Leonardo", |
| 98 | + FQBN: "arduino:avr:leonardo", |
| 99 | + IsHidden: false, |
| 100 | + }) |
| 101 | + require.Contains(t, res.Boards, &rpc.BoardListItem{ |
| 102 | + Name: "Arduino Leonardo ETH", |
| 103 | + FQBN: "arduino:avr:leonardoeth", |
| 104 | + IsHidden: false, |
| 105 | + }) |
| 106 | + require.Contains(t, res.Boards, &rpc.BoardListItem{ |
| 107 | + Name: "Arduino Micro", |
| 108 | + FQBN: "arduino:avr:micro", |
| 109 | + IsHidden: false, |
| 110 | + }) |
| 111 | + require.Contains(t, res.Boards, &rpc.BoardListItem{ |
| 112 | + Name: "Arduino Esplora", |
| 113 | + FQBN: "arduino:avr:esplora", |
| 114 | + IsHidden: false, |
| 115 | + }) |
| 116 | + require.Contains(t, res.Boards, &rpc.BoardListItem{ |
| 117 | + Name: "Arduino Mini", |
| 118 | + FQBN: "arduino:avr:mini", |
| 119 | + IsHidden: false, |
| 120 | + }) |
| 121 | + require.Contains(t, res.Boards, &rpc.BoardListItem{ |
| 122 | + Name: "Arduino Ethernet", |
| 123 | + FQBN: "arduino:avr:ethernet", |
| 124 | + IsHidden: false, |
| 125 | + }) |
| 126 | + require.Contains(t, res.Boards, &rpc.BoardListItem{ |
| 127 | + Name: "Arduino Fio", |
| 128 | + FQBN: "arduino:avr:fio", |
| 129 | + IsHidden: false, |
| 130 | + }) |
| 131 | + require.Contains(t, res.Boards, &rpc.BoardListItem{ |
| 132 | + Name: "Arduino BT", |
| 133 | + FQBN: "arduino:avr:bt", |
| 134 | + IsHidden: false, |
| 135 | + }) |
| 136 | + require.Contains(t, res.Boards, &rpc.BoardListItem{ |
| 137 | + Name: "LilyPad Arduino USB", |
| 138 | + FQBN: "arduino:avr:LilyPadUSB", |
| 139 | + IsHidden: false, |
| 140 | + }) |
| 141 | + require.Contains(t, res.Boards, &rpc.BoardListItem{ |
| 142 | + Name: "LilyPad Arduino", |
| 143 | + FQBN: "arduino:avr:lilypad", |
| 144 | + IsHidden: false, |
| 145 | + }) |
| 146 | + require.Contains(t, res.Boards, &rpc.BoardListItem{ |
| 147 | + Name: "Arduino Pro or Pro Mini", |
| 148 | + FQBN: "arduino:avr:pro", |
| 149 | + IsHidden: false, |
| 150 | + }) |
| 151 | + require.Contains(t, res.Boards, &rpc.BoardListItem{ |
| 152 | + Name: "Arduino NG or older", |
| 153 | + FQBN: "arduino:avr:atmegang", |
| 154 | + IsHidden: false, |
| 155 | + }) |
| 156 | + require.Contains(t, res.Boards, &rpc.BoardListItem{ |
| 157 | + Name: "Arduino Robot Control", |
| 158 | + FQBN: "arduino:avr:robotControl", |
| 159 | + IsHidden: false, |
| 160 | + }) |
| 161 | + require.Contains(t, res.Boards, &rpc.BoardListItem{ |
| 162 | + Name: "Arduino Robot Motor", |
| 163 | + FQBN: "arduino:avr:robotMotor", |
| 164 | + IsHidden: false, |
| 165 | + }) |
| 166 | + require.Contains(t, res.Boards, &rpc.BoardListItem{ |
| 167 | + Name: "Arduino Gemma", |
| 168 | + FQBN: "arduino:avr:gemma", |
| 169 | + IsHidden: false, |
| 170 | + }) |
| 171 | + require.Contains(t, res.Boards, &rpc.BoardListItem{ |
| 172 | + Name: "Adafruit Circuit Playground", |
| 173 | + FQBN: "arduino:avr:circuitplay32u4cat", |
| 174 | + IsHidden: false, |
| 175 | + }) |
| 176 | + require.Contains(t, res.Boards, &rpc.BoardListItem{ |
| 177 | + Name: "Arduino Yún Mini", |
| 178 | + FQBN: "arduino:avr:yunmini", |
| 179 | + IsHidden: false, |
| 180 | + }) |
| 181 | + require.Contains(t, res.Boards, &rpc.BoardListItem{ |
| 182 | + Name: "Arduino Industrial 101", |
| 183 | + FQBN: "arduino:avr:chiwawa", |
| 184 | + IsHidden: false, |
| 185 | + }) |
| 186 | + require.Contains(t, res.Boards, &rpc.BoardListItem{ |
| 187 | + Name: "Linino One", |
| 188 | + FQBN: "arduino:avr:one", |
| 189 | + IsHidden: false, |
| 190 | + }) |
| 191 | + require.Contains(t, res.Boards, &rpc.BoardListItem{ |
| 192 | + Name: "Arduino Uno WiFi", |
| 193 | + FQBN: "arduino:avr:unowifi", |
| 194 | + IsHidden: false, |
| 195 | + }) |
| 196 | + |
| 197 | +} |
0 commit comments