Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 7bb460d

Browse files
committed
testsuite: Converted a core_test.py test (WIP)
1 parent 0314b3a commit 7bb460d

File tree

2 files changed

+368
-0
lines changed

2 files changed

+368
-0
lines changed
Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
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 core_test
17+
18+
import (
19+
"encoding/json"
20+
"fmt"
21+
"strings"
22+
"testing"
23+
24+
"github.com/arduino/arduino-cli/internal/integrationtest"
25+
"github.com/arduino/go-paths-helper"
26+
"github.com/stretchr/testify/require"
27+
"github.com/tidwall/gjson"
28+
)
29+
30+
func TestCoreSearch(t *testing.T) {
31+
env := integrationtest.NewEnvironment(t)
32+
defer env.CleanUp()
33+
34+
cli := integrationtest.NewArduinoCliWithinEnvironment(t, &integrationtest.ArduinoCLIConfig{
35+
ArduinoCLIPath: paths.New("..", "..", "..", "arduino-cli"),
36+
UseSharedStagingFolder: true,
37+
}, env)
38+
defer cli.CleanUp()
39+
40+
// Set up an http server to serve our custom index file
41+
test_index := paths.New("..", "testdata", "test_index.json")
42+
url, httpClose := integrationtest.HTTPServeFile(t, 8000, test_index)
43+
defer httpClose()
44+
45+
// Run update-index with our test index
46+
_, _, err := cli.Run("core", "update-index", "--additional-urls="+url.String())
47+
require.NoError(t, err)
48+
49+
// Search a specific core
50+
out, _, err := cli.Run("core", "search", "avr")
51+
require.NoError(t, err)
52+
require.Greater(t, len(strings.Split(string(out), "\n")), 2)
53+
54+
out, _, err = cli.Run("core", "search", "avr", "--format", "json")
55+
require.NoError(t, err)
56+
data := make([]interface{}, 0)
57+
require.NoError(t, json.Unmarshal(out, &data))
58+
require.NotEmpty(t, data)
59+
// same check using gjson lib
60+
require.NotEmpty(t, gjson.ParseBytes(out).Array())
61+
62+
// additional URL
63+
out, _, err = cli.Run("core", "search", "test_core", "--format", "json", "--additional-urls="+url.String())
64+
require.NoError(t, err)
65+
require.NoError(t, json.Unmarshal(out, &data))
66+
require.Len(t, data, 1)
67+
68+
// show all versions
69+
out, _, err = cli.Run("core", "search", "test_core", "--all", "--format", "json", "--additional-urls="+url.String())
70+
require.NoError(t, err)
71+
require.NoError(t, json.Unmarshal(out, &data))
72+
require.Len(t, data, 2)
73+
// alternative check using gjson:
74+
require.Len(t, gjson.ParseBytes(out).Array(), 2)
75+
// alternative using gojq:
76+
integrationtest.JQQuery(t, out, "length", 2)
77+
78+
checkPlatformIsInJSONOutput := func(stdout []byte, id, version string) {
79+
// Alternative solution with gojq
80+
jqquery := fmt.Sprintf(`contains( [{id:"%s", latest:"%s"}] )`, id, version)
81+
integrationtest.JQQuery(t, out, jqquery, true, "platform %s@%s is missing from the output", id, version)
82+
83+
// Alternative solution with gjson
84+
// query := fmt.Sprintf("#(id=%s)#|#(latest=%s)", id, version)
85+
// if gjson.ParseBytes(out).Get(query).Exists() {
86+
// return
87+
// }
88+
// require.FailNowf(t, "Wrong output", "platform %s@%s is missing from the output", id, version)
89+
90+
// Alternative solution:
91+
// for _, platform := range gjson.ParseBytes(out).Array() {
92+
// if platform.Get("id").Str == id && platform.Get("latest").Str == version {
93+
// return
94+
// }
95+
// }
96+
// require.FailNowf(t, "Wrong output", "platform %s@%s is missing from the output", id, version)
97+
}
98+
99+
// Search all Retrokit platforms
100+
out, _, err = cli.Run("core", "search", "retrokit", "--all", "--additional-urls="+url.String(), "--format", "json")
101+
require.NoError(t, err)
102+
checkPlatformIsInJSONOutput(out, "Retrokits-RK002:arm", "1.0.5")
103+
checkPlatformIsInJSONOutput(out, "Retrokits-RK002:arm", "1.0.6")
104+
//checkPlatformIsInJSONOutput(out, "Retrokits-RK002:arm", "1.0.9") // Test failure
105+
106+
// Search using Retrokit Package Maintainer
107+
out, _, err = cli.Run("core", "search", "Retrokits-RK002", "--all", "--additional-urls="+url.String(), "--format", "json")
108+
require.NoError(t, err)
109+
checkPlatformIsInJSONOutput(out, "Retrokits-RK002:arm", "1.0.5")
110+
checkPlatformIsInJSONOutput(out, "Retrokits-RK002:arm", "1.0.6")
111+
112+
// Search using the Retrokit Platform name
113+
out, _, err = cli.Run("core", "search", "rk002", "--all", "--additional-urls="+url.String(), "--format", "json")
114+
require.NoError(t, err)
115+
checkPlatformIsInJSONOutput(out, "Retrokits-RK002:arm", "1.0.5")
116+
checkPlatformIsInJSONOutput(out, "Retrokits-RK002:arm", "1.0.6")
117+
118+
// Search using board names
119+
out, _, err = cli.Run("core", "search", "myboard", "--all", "--additional-urls="+url.String(), "--format", "json")
120+
require.NoError(t, err)
121+
checkPlatformIsInJSONOutput(out, "Package:x86", "1.2.3")
122+
123+
// Check search with case, accents and spaces
124+
runSearch := func(searchArgs string, expectedIDs ...string) {
125+
args := []string{"core", "search", "--format", "json"}
126+
args = append(args, strings.Split(searchArgs, " ")...)
127+
out, _, err := cli.Run(args...)
128+
require.NoError(t, err)
129+
130+
// Alternative solution with gojq
131+
for _, id := range expectedIDs {
132+
jqquery := fmt.Sprintf(`contains( [{id:"%s"}] )`, id)
133+
integrationtest.JQQuery(t, out, jqquery, true, "platform %s is missing from the output", id)
134+
}
135+
136+
// Alternative solution with gjson
137+
// data := gjson.ParseBytes(out)
138+
// for _, expectedID := range expectedIDs {
139+
// query := fmt.Sprintf("#(id=%s)", expectedID)
140+
// if !data.Get(query).Exists() {
141+
// require.FailNowf(t, "Wrong output", "platform %s is missing from the output", expectedID)
142+
// }
143+
// }
144+
}
145+
146+
runSearch("mkr1000", "arduino:samd")
147+
runSearch("mkr 1000", "arduino:samd")
148+
149+
runSearch("yún", "arduino:avr")
150+
runSearch("yùn", "arduino:avr")
151+
runSearch("yun", "arduino:avr")
152+
153+
runSearch("nano 33", "arduino:samd", "arduino:mbed_nano")
154+
runSearch("nano ble", "arduino:mbed_nano")
155+
runSearch("ble", "arduino:mbed_nano")
156+
runSearch("ble nano", "arduino:mbed_nano")
157+
runSearch("nano", "arduino:avr", "arduino:megaavr", "arduino:samd", "arduino:mbed_nano")
158+
}
Lines changed: 210 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,210 @@
1+
{
2+
"packages": [
3+
{
4+
"maintainer": "Arduino",
5+
"help": {
6+
"online": "https://github.com/Arduino/arduino-cli"
7+
},
8+
"websiteURL": "https://github.com/Arduino/arduino-cli",
9+
"platforms": [
10+
{
11+
"category": "Test Category",
12+
"help": {
13+
"online": "https://github.com/Arduino/arduino-cli"
14+
},
15+
"url": "https://raw.githubusercontent.com/arduino/arduino-cli/master/test/testdata/core.zip",
16+
"checksum": "SHA-256:6a338cf4d6d501176a2d352c87a8d72ac7488b8c5b82cdf2a4e2cef630391092",
17+
"name": "test_core",
18+
"version": "1.0.0",
19+
"architecture": "x86",
20+
"archiveFileName": "core.zip",
21+
"size": "486",
22+
"toolsDependencies": [],
23+
"boards": [
24+
{
25+
"name": "Test Board"
26+
}
27+
]
28+
},
29+
{
30+
"category": "Test Category",
31+
"help": {
32+
"online": "https://github.com/Arduino/arduino-cli"
33+
},
34+
"url": "https://raw.githubusercontent.com/arduino/arduino-cli/master/test/testdata/core.zip",
35+
"checksum": "SHA-256:6a338cf4d6d501176a2d352c87a8d72ac7488b8c5b82cdf2a4e2cef630391092",
36+
"name": "test_core",
37+
"version": "2.0.0",
38+
"architecture": "x86",
39+
"archiveFileName": "core.zip",
40+
"size": "486",
41+
"toolsDependencies": [],
42+
"boards": [
43+
{
44+
"name": "Test Board"
45+
}
46+
]
47+
}
48+
],
49+
"tools": [],
50+
"email": "test@example.com",
51+
"name": "test"
52+
},
53+
{
54+
"name": "zipslip",
55+
"tools": [],
56+
"email": "test@example.com",
57+
"maintainer": "Arduino",
58+
"help": {
59+
"online": "https://github.com/Arduino/arduino-cli"
60+
},
61+
"websiteURL": "https://github.com/Arduino/arduino-cli",
62+
"platforms": [
63+
{
64+
"category": "Zipslip Test",
65+
"help": {
66+
"online": "https://github.com/Arduino/arduino-cli"
67+
},
68+
"url": "https://raw.githubusercontent.com/arduino/arduino-cli/master/test/testdata/evil.zip",
69+
"checksum": "SHA-256:9b85dfe23f13318efc0e541327f584a0f3674a773d46a7eb8b25f0f408d07f96",
70+
"name": "zipslip",
71+
"version": "1.0.0",
72+
"architecture": "x86",
73+
"archiveFileName": "evil.zip",
74+
"size": "2184",
75+
"toolsDependencies": [],
76+
"boards": [
77+
{
78+
"name": "Test Board"
79+
}
80+
]
81+
}
82+
]
83+
},
84+
{
85+
"name": "brokenchecksum",
86+
"tools": [],
87+
"email": "test@example.com",
88+
"maintainer": "Arduino",
89+
"help": {
90+
"online": "https://github.com/Arduino/arduino-cli"
91+
},
92+
"websiteURL": "https://github.com/Arduino/arduino-cli",
93+
"platforms": [
94+
{
95+
"category": "BrokenChecksum Test",
96+
"help": {
97+
"online": "https://github.com/Arduino/arduino-cli"
98+
},
99+
"url": "https://raw.githubusercontent.com/arduino/arduino-cli/master/test/testdata/core.zip",
100+
"checksum": "SHA-256:1a338cf4d6d501176a2d352c87a8d72ac7488b8c5b82cdf2a4e2cef630391092",
101+
"name": "zipslip",
102+
"version": "1.0.0",
103+
"architecture": "x86",
104+
"archiveFileName": "core.zip",
105+
"size": "486",
106+
"toolsDependencies": [],
107+
"boards": [
108+
{
109+
"name": "Test Board"
110+
}
111+
]
112+
}
113+
]
114+
},
115+
{
116+
"name": "Retrokits-RK002",
117+
"maintainer": "Retrokits (www.retrokits.com)",
118+
"websiteURL": "https://www.retrokits.com",
119+
"email": "info@retrokits.com",
120+
"help": { "online": "https://www.retrokits.com/rk002/arduino" },
121+
"platforms": [
122+
{
123+
"name": "RK002",
124+
"architecture": "arm",
125+
"version": "1.0.5",
126+
"category": "Contributed",
127+
"help": {
128+
"online": "https://www.retrokits.com/rk002/arduino"
129+
},
130+
"url": "https://www.retrokits.com/rk002/arduino/retrokits-rk002-1.0.5.tar.bz2",
131+
"archiveFileName": "retrokits-rk002-1.0.5.tar.bz2",
132+
"checksum": "SHA-256:9a012867baf4bb26f656f84502e0acce6a653c3452cca4505ebac77256802fb6",
133+
"size": "290784",
134+
"boards": [{ "name": "RK002" }],
135+
"toolsDependencies": [
136+
{
137+
"packager": "arduino",
138+
"version": "4.8.3-2014q1",
139+
"name": "arm-none-eabi-gcc"
140+
}
141+
]
142+
}
143+
],
144+
"tools": []
145+
},
146+
{
147+
"name": "Retrokits-RK002",
148+
"maintainer": "Retrokits (www.retrokits.com)",
149+
"websiteURL": "https://www.retrokits.com",
150+
"email": "info@retrokits.com",
151+
"help": { "online": "https://www.retrokits.com/rk002/arduino" },
152+
"platforms": [
153+
{
154+
"name": "RK002",
155+
"architecture": "arm",
156+
"version": "1.0.6",
157+
"category": "Contributed",
158+
"help": {
159+
"online": "https://www.retrokits.com/rk002/arduino"
160+
},
161+
"url": "https://www.retrokits.com/rk002/arduino/retrokits-rk002-1.0.6.tar.bz2",
162+
"archiveFileName": "retrokits-rk002-1.0.6.tar.bz2",
163+
"checksum": "SHA-256:8a3b63efcf4dfaed047a37844861387e542d8519485b5305d5979630cb3feb20",
164+
"size": "291631",
165+
"boards": [{ "name": "RK002" }],
166+
"toolsDependencies": [
167+
{
168+
"packager": "arduino",
169+
"version": "4.8.3-2014q1",
170+
"name": "arm-none-eabi-gcc"
171+
}
172+
]
173+
}
174+
],
175+
"tools": []
176+
},
177+
{
178+
"name": "Package",
179+
"tools": [],
180+
"email": "test@example.com",
181+
"maintainer": "Arduino",
182+
"help": {
183+
"online": "https://github.com/Arduino/arduino-cli"
184+
},
185+
"websiteURL": "https://github.com/Arduino/arduino-cli",
186+
"platforms": [
187+
{
188+
"category": "Test",
189+
"help": {
190+
"online": "https://github.com/Arduino/arduino-cli"
191+
},
192+
"url": "https://raw.githubusercontent.com/arduino/arduino-cli/master/test/testdata/core.zip",
193+
"checksum": "SHA-256:6a338cf4d6d501176a2d352c87a8d72ac7488b8c5b82cdf2a4e2cef630391092",
194+
"name": "Platform",
195+
"version": "1.2.3",
196+
"deprecated": true,
197+
"architecture": "x86",
198+
"archiveFileName": "core.zip",
199+
"size": "486",
200+
"toolsDependencies": [],
201+
"boards": [
202+
{
203+
"name": "MyBoard"
204+
}
205+
]
206+
}
207+
]
208+
}
209+
]
210+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /