Skip to content

Commit 6b88371

Browse files
Migrated TestBoardList from test_board.py to board_test.go
I could not properly check if the test was working as intended because the command `board list --format json` returned an empty list if executed locally. Further improvements could be done regarding the type of ports, which I suspect should be `map[string][]string` and not simply `[]string`.
1 parent aa41d72 commit 6b88371

File tree

2 files changed

+48
-13
lines changed

2 files changed

+48
-13
lines changed
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
// This file is part of arduino-cli.
2+
//
3+
// Copyright 2022 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 license@arduino.cc.
15+
16+
package board_t_test
17+
18+
import (
19+
"encoding/json"
20+
"os"
21+
"testing"
22+
23+
"github.com/arduino/arduino-cli/internal/integrationtest"
24+
"github.com/stretchr/testify/require"
25+
)
26+
27+
func TestBoardList(t *testing.T) {
28+
if os.Getenv("CI") != "" {
29+
t.Skip("VMs have no serial ports")
30+
}
31+
32+
env, cli := integrationtest.CreateArduinoCLIWithEnvironment(t)
33+
defer env.CleanUp()
34+
35+
_, _, err := cli.Run("core", "update-index")
36+
require.NoError(t, err)
37+
stdout, _, err := cli.Run("board", "list", "--format", "json")
38+
require.NoError(t, err)
39+
// check is a valid json and contains a list of ports
40+
var ports []string
41+
err = json.Unmarshal(stdout, &ports)
42+
require.NoError(t, err)
43+
require.NotEmpty(t, ports)
44+
for _, port := range ports {
45+
require.Contains(t, port, "protocol")
46+
require.Contains(t, port, "protocol_label")
47+
}
48+
}

test/test_board.py

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -394,19 +394,6 @@
394394
""" # noqa: E501
395395

396396

397-
@pytest.mark.skipif(running_on_ci(), reason="VMs have no serial ports")
398-
def test_board_list(run_command):
399-
run_command(["core", "update-index"])
400-
result = run_command(["board", "list", "--format", "json"])
401-
assert result.ok
402-
# check is a valid json and contains a list of ports
403-
ports = json.loads(result.stdout)
404-
assert isinstance(ports, list)
405-
for port in ports:
406-
assert "protocol" in port["port"]
407-
assert "protocol_label" in port["port"]
408-
409-
410397
def test_board_list_with_invalid_discovery(run_command, data_dir):
411398
run_command(["core", "update-index"])
412399
result = run_command(["board", "list"])

0 commit comments

Comments
 (0)