Skip to content

Commit 51bc271

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 f43c9ec commit 51bc271

File tree

2 files changed

+55
-13
lines changed

2 files changed

+55
-13
lines changed
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
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 [email protected].
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/arduino/go-paths-helper"
25+
"github.com/stretchr/testify/require"
26+
"go.bug.st/testsuite"
27+
)
28+
29+
func TestBoardList(t *testing.T) {
30+
if os.Getenv("CI") != "" {
31+
t.Skip("VMs have no serial ports")
32+
}
33+
34+
env := testsuite.NewEnvironment(t)
35+
defer env.CleanUp()
36+
37+
cli := integrationtest.NewArduinoCliWithinEnvironment(env, &integrationtest.ArduinoCLIConfig{
38+
ArduinoCLIPath: paths.New("..", "..", "..", "arduino-cli"),
39+
UseSharedStagingFolder: true,
40+
})
41+
42+
_, _, err := cli.Run("core", "update-index")
43+
require.NoError(t, err)
44+
stdout, _, err := cli.Run("board", "list", "--format", "json")
45+
require.NoError(t, err)
46+
// check is a valid json and contains a list of ports
47+
var ports []string
48+
err = json.Unmarshal(stdout, &ports)
49+
require.NoError(t, err)
50+
require.NotEmpty(t, ports)
51+
for _, port := range ports {
52+
require.Contains(t, port, "protocol")
53+
require.Contains(t, port, "protocol_label")
54+
}
55+
}

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)