@@ -71,23 +71,6 @@ func TestCorrectBoardListOrdering(t *testing.T) {
7171 ]` )
7272}
7373
74- func TestBoardList (t * testing.T ) {
75- env , cli := integrationtest .CreateArduinoCLIWithEnvironment (t )
76- defer env .CleanUp ()
77-
78- _ , _ , err := cli .Run ("core" , "update-index" )
79- require .NoError (t , err )
80-
81- cli .InstallMockedSerialDiscovery (t )
82-
83- stdout , _ , err := cli .Run ("board" , "list" , "--json" )
84- require .NoError (t , err )
85- // check is a valid json and contains a list of ports
86- requirejson .Parse (t , stdout ).
87- Query (`[ .detected_ports | .[].port | select(.protocol == null or .protocol_label == null) ]` ).
88- MustBeEmpty ()
89- }
90-
9174func TestBoardListMock (t * testing.T ) {
9275 env , cli := integrationtest .CreateArduinoCLIWithEnvironment (t )
9376 defer env .CleanUp ()
@@ -97,11 +80,20 @@ func TestBoardListMock(t *testing.T) {
9780
9881 cli .InstallMockedSerialDiscovery (t )
9982
100- stdout , _ , err := cli .Run ("board" , "list" , "--json" )
101- require .NoError (t , err )
83+ t .Run ("IsValidJsonPortList" , func (t * testing.T ) {
84+ // 1. Check is a valid JSON
85+ // 2. Check is a valid port list (has address/protocol)
86+ stdout , _ , err := cli .Run ("board" , "list" , "--json" )
87+ require .NoError (t , err )
88+ requirejson .Parse (t , stdout ).
89+ Query (`[ .detected_ports | .[].port | select(.address == null or .protocol == null) ]` ).
90+ MustBeEmpty ()
91+ })
10292
103- // check is a valid json and contains a list of ports
104- requirejson .Contains (t , stdout , `{
93+ t .Run ("ContainsMockedPorts" , func (t * testing.T ) {
94+ stdout , _ , err := cli .Run ("board" , "list" , "--json" )
95+ require .NoError (t , err )
96+ requirejson .Contains (t , stdout , `{
10597 "detected_ports": [
10698 {
10799 "matching_boards": [
@@ -124,35 +116,20 @@ func TestBoardListMock(t *testing.T) {
124116 }
125117 }
126118 ]
127- }` )
128- }
129-
130- func TestBoardListWithFqbnFilter (t * testing.T ) {
131- env , cli := integrationtest .CreateArduinoCLIWithEnvironment (t )
132- defer env .CleanUp ()
133-
134- _ , _ , err := cli .Run ("core" , "update-index" )
135- require .NoError (t , err )
136-
137- cli .InstallMockedSerialDiscovery (t )
138-
139- stdout , _ , err := cli .Run ("board" , "list" , "-b" , "foo:bar:baz" , "--json" )
140- require .NoError (t , err )
141- requirejson .Query (t , stdout , `.detected_ports | length` , `0` )
142- }
143-
144- func TestBoardListWithFqbnFilterInvalid (t * testing.T ) {
145- env , cli := integrationtest .CreateArduinoCLIWithEnvironment (t )
146- defer env .CleanUp ()
147-
148- _ , _ , err := cli .Run ("core" , "update-index" )
149- require .NoError (t , err )
119+ }` )
120+ })
150121
151- cli .InstallMockedSerialDiscovery (t )
122+ t .Run ("ListWithFqbnFilter" , func (t * testing.T ) {
123+ stdout , _ , err := cli .Run ("board" , "list" , "-b" , "foo:bar:baz" , "--json" )
124+ require .NoError (t , err )
125+ requirejson .Query (t , stdout , `.detected_ports | length` , `0` )
126+ })
152127
153- _ , stderr , err := cli .Run ("board" , "list" , "-b" , "yadayada" , "--json" )
154- require .Error (t , err )
155- requirejson .Query (t , stderr , ".error" , `"Invalid FQBN: not an FQBN: yadayada"` )
128+ t .Run ("ListWithFqbnFilterInvalid" , func (t * testing.T ) {
129+ _ , stderr , err := cli .Run ("board" , "list" , "-b" , "yadayada" , "--json" )
130+ require .Error (t , err )
131+ requirejson .Query (t , stderr , ".error" , `"Invalid FQBN: not an FQBN: yadayada"` )
132+ })
156133}
157134
158135func TestBoardListall (t * testing.T ) {
0 commit comments