@@ -126,3 +126,65 @@ func TestCoreSearch(t *testing.T) {
126
126
runSearch ("ble nano" , "arduino:mbed_nano" )
127
127
runSearch ("nano" , "arduino:avr" , "arduino:megaavr" , "arduino:samd" , "arduino:mbed_nano" )
128
128
}
129
+
130
+ func TestCoreSearchNoArgs (t * testing.T ) {
131
+ // This tests `core search` with and without additional URLs in case no args
132
+ // are passed (i.e. all results are shown).
133
+
134
+ env , cli := integrationtest .CreateArduinoCLIWithEnvironment (t )
135
+ defer env .CleanUp ()
136
+
137
+ // Set up an http server to serve our custom index file
138
+ testIndex := paths .New (".." , "testdata" , "test_index.json" )
139
+ url := env .HTTPServeFile (8000 , testIndex )
140
+
141
+ // update custom index and install test core (installed cores affect `core search`)
142
+ _ , _ , err := cli .Run ("core" , "update-index" , "--additional-urls=" + url .String ())
143
+ require .NoError (t , err )
144
+ _ , _ , err = cli .Run ("core" , "install" , "test:x86" , "--additional-urls=" + url .String ())
145
+ require .NoError (t , err )
146
+
147
+ // list all with no additional urls, ensure the test core won't show up
148
+ stdout , _ , err := cli .Run ("core" , "search" )
149
+ require .NoError (t , err )
150
+ var lines [][]string
151
+ for _ , v := range strings .Split (strings .TrimSpace (string (stdout )), "\n " ) {
152
+ lines = append (lines , strings .Fields (strings .TrimSpace (v )))
153
+ }
154
+ // The header is printed on the first lines
155
+ require .Equal (t , []string {"test:x86" , "2.0.0" , "test_core" }, lines [19 ])
156
+ // We use black to format and flake8 to lint .py files but they disagree on certain
157
+ // things like this one, thus we ignore this specific flake8 rule and stand by black
158
+ // opinion.
159
+ // We ignore this specific case because ignoring it globally would probably cause more
160
+ // issue. For more info about the rule see: https://www.flake8rules.com/rules/E203.html
161
+ numPlatforms := len (lines ) - 1 // noqa: E203
162
+
163
+ // same thing in JSON format, also check the number of platforms found is the same
164
+ stdout , _ , err = cli .Run ("core" , "search" , "--format" , "json" )
165
+ require .NoError (t , err )
166
+ requirejson .Query (t , stdout , " .[] | select(.name == \" test_core\" ) | . != \" \" " , "true" )
167
+ requirejson .Query (t , stdout , "length" , fmt .Sprint (numPlatforms ))
168
+
169
+ // list all with additional urls, check the test core is there
170
+ stdout , _ , err = cli .Run ("core" , "search" , "--additional-urls=" + url .String ())
171
+ require .NoError (t , err )
172
+ lines = nil
173
+ for _ , v := range strings .Split (strings .TrimSpace (string (stdout )), "\n " ) {
174
+ lines = append (lines , strings .Fields (strings .TrimSpace (v )))
175
+ }
176
+ // The header is printed on the first lines
177
+ require .Equal (t , []string {"test:x86" , "2.0.0" , "test_core" }, lines [20 ])
178
+ // We use black to format and flake8 to lint .py files but they disagree on certain
179
+ // things like this one, thus we ignore this specific flake8 rule and stand by black
180
+ // opinion.
181
+ // We ignore this specific case because ignoring it globally would probably cause more
182
+ // issue. For more info about the rule see: https://www.flake8rules.com/rules/E203.html
183
+ numPlatforms = len (lines ) - 1 // noqa: E203
184
+
185
+ // same thing in JSON format, also check the number of platforms found is the same
186
+ stdout , _ , err = cli .Run ("core" , "search" , "--format" , "json" , "--additional-urls=" + url .String ())
187
+ require .NoError (t , err )
188
+ requirejson .Query (t , stdout , " .[] | select(.name == \" test_core\" ) | . != \" \" " , "true" )
189
+ requirejson .Query (t , stdout , "length" , fmt .Sprint (numPlatforms ))
190
+ }
0 commit comments