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

Appearance settings

Commit 60ad95e

Browse filesBrowse files
Add integration test
1 parent b78fdb5 commit 60ad95e
Copy full SHA for 60ad95e

File tree

3 files changed

+44
-12
lines changed
Filter options

3 files changed

+44
-12
lines changed

‎internal/integrationtest/core/core_test.go

Copy file name to clipboardExpand all lines: internal/integrationtest/core/core_test.go
+10-10Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ func TestCoreSearch(t *testing.T) {
6969

7070
// Set up an http server to serve our custom index file
7171
test_index := paths.New("..", "testdata", "test_index.json")
72-
url := env.HTTPServeFile(8000, test_index)
72+
url := env.HTTPServeFile(8000, test_index, false)
7373

7474
// Run update-index with our test index
7575
_, _, err := cli.Run("core", "update-index", "--additional-urls="+url.String())
@@ -161,7 +161,7 @@ func TestCoreSearchNoArgs(t *testing.T) {
161161

162162
// Set up an http server to serve our custom index file
163163
testIndex := paths.New("..", "testdata", "test_index.json")
164-
url := env.HTTPServeFile(8000, testIndex)
164+
url := env.HTTPServeFile(8000, testIndex, false)
165165

166166
// update custom index and install test core (installed cores affect `core search`)
167167
_, _, err := cli.Run("core", "update-index", "--additional-urls="+url.String())
@@ -749,7 +749,7 @@ func TestCoreSearchSortedResults(t *testing.T) {
749749

750750
// Set up the server to serve our custom index file
751751
testIndex := paths.New("..", "testdata", "test_index.json")
752-
url := env.HTTPServeFile(8000, testIndex)
752+
url := env.HTTPServeFile(8000, testIndex, false)
753753

754754
// update custom index
755755
_, _, err := cli.Run("core", "update-index", "--additional-urls="+url.String())
@@ -821,7 +821,7 @@ func TestCoreListSortedResults(t *testing.T) {
821821

822822
// Set up the server to serve our custom index file
823823
testIndex := paths.New("..", "testdata", "test_index.json")
824-
url := env.HTTPServeFile(8000, testIndex)
824+
url := env.HTTPServeFile(8000, testIndex, false)
825825

826826
// update custom index
827827
_, _, err := cli.Run("core", "update-index", "--additional-urls="+url.String())
@@ -892,7 +892,7 @@ func TestCoreListDeprecatedPlatformWithInstalledJson(t *testing.T) {
892892

893893
// Set up the server to serve our custom index file
894894
testIndex := paths.New("..", "testdata", "test_index.json")
895-
url := env.HTTPServeFile(8000, testIndex)
895+
url := env.HTTPServeFile(8000, testIndex, false)
896896

897897
// update custom index
898898
_, _, err := cli.Run("core", "update-index", "--additional-urls="+url.String())
@@ -1110,8 +1110,8 @@ func TestCoreInstallRunsToolPostInstallScript(t *testing.T) {
11101110
env, cli := integrationtest.CreateArduinoCLIWithEnvironment(t)
11111111
defer env.CleanUp()
11121112

1113-
url := env.HTTPServeFile(8080, paths.New("testdata", "package_with_postinstall_index.json"))
1114-
env.HTTPServeFile(8081, paths.New("testdata", "core_with_postinst.zip"))
1113+
url := env.HTTPServeFile(8080, paths.New("testdata", "package_with_postinstall_index.json"), false)
1114+
env.HTTPServeFile(8081, paths.New("testdata", "core_with_postinst.zip"), false)
11151115

11161116
_, _, err := cli.Run("core", "update-index", "--additional-urls", url.String())
11171117
require.NoError(t, err)
@@ -1129,7 +1129,7 @@ func TestCoreBrokenDependency(t *testing.T) {
11291129

11301130
// Set up an http server to serve our custom index file
11311131
test_index := paths.New("..", "testdata", "test_index.json")
1132-
url := env.HTTPServeFile(8000, test_index)
1132+
url := env.HTTPServeFile(8000, test_index, false)
11331133

11341134
// Run update-index with our test index
11351135
_, _, err := cli.Run("core", "update-index", "--additional-urls="+url.String())
@@ -1145,7 +1145,7 @@ func TestCoreUpgradeWarningWithPackageInstalledButNotIndexed(t *testing.T) {
11451145
env, cli := integrationtest.CreateArduinoCLIWithEnvironment(t)
11461146
defer env.CleanUp()
11471147

1148-
url := env.HTTPServeFile(8000, paths.New("..", "testdata", "test_index.json")).String()
1148+
url := env.HTTPServeFile(8000, paths.New("..", "testdata", "test_index.json"), false).String()
11491149

11501150
t.Run("missing additional-urls", func(t *testing.T) {
11511151
// update index
@@ -1187,7 +1187,7 @@ func TestCoreHavingIncompatibleDepTools(t *testing.T) {
11871187
env, cli := integrationtest.CreateArduinoCLIWithEnvironment(t)
11881188
defer env.CleanUp()
11891189

1190-
url := env.HTTPServeFile(8000, paths.New("..", "testdata", "test_index.json")).String()
1190+
url := env.HTTPServeFile(8000, paths.New("..", "testdata", "test_index.json"), false).String()
11911191
additionalURLs := "--additional-urls=" + url
11921192

11931193
_, _, err := cli.Run("core", "update-index", additionalURLs)

‎internal/integrationtest/daemon/daemon_test.go

Copy file name to clipboardExpand all lines: internal/integrationtest/daemon/daemon_test.go
+28Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -555,6 +555,34 @@ func TestDaemonCoreUpgradePlatform(t *testing.T) {
555555
})
556556
}
557557

558+
func TestDaemonUserAgent(t *testing.T) {
559+
env, cli := integrationtest.CreateEnvForDaemon(t)
560+
defer env.CleanUp()
561+
562+
// Set up an http server to serve our custom index file
563+
// The user-agent is tested inside the HTTPServeFile function
564+
test_index := paths.New("..", "testdata", "test_index.json")
565+
url := env.HTTPServeFile(8000, test_index, true)
566+
567+
grpcInst := cli.Create()
568+
require.NoError(t, grpcInst.Init("", "", func(ir *commands.InitResponse) {
569+
fmt.Printf("INIT> %v\n", ir.GetMessage())
570+
}))
571+
572+
// Set extra indexes
573+
err := cli.SetValue("board_manager.additional_urls", `["http://127.0.0.1:8000/test_index.json"]`)
574+
require.NoError(t, err)
575+
576+
{
577+
cl, err := grpcInst.UpdateIndex(context.Background(), false)
578+
require.NoError(t, err)
579+
res, err := analyzeUpdateIndexClient(t, cl)
580+
require.NoError(t, err)
581+
require.Len(t, res, 2)
582+
require.True(t, res[url.String()].GetSuccess())
583+
}
584+
}
585+
558586
func analyzeUpdateIndexClient(t *testing.T, cl commands.ArduinoCoreService_UpdateIndexClient) (map[string]*commands.DownloadProgressEnd, error) {
559587
analyzer := NewDownloadProgressAnalyzer(t)
560588
for {

‎internal/integrationtest/http_server.go

Copy file name to clipboardExpand all lines: internal/integrationtest/http_server.go
+6-2Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,21 @@ import (
2626

2727
// HTTPServeFile spawn an http server that serve a single file. The server
2828
// is started on the given port. The URL to the file and a cleanup function are returned.
29-
func (env *Environment) HTTPServeFile(port uint16, path *paths.Path) *url.URL {
29+
func (env *Environment) HTTPServeFile(port uint16, path *paths.Path, isDaemon bool) *url.URL {
30+
t := env.T()
3031
mux := http.NewServeMux()
3132
mux.HandleFunc("/"+path.Base(), func(w http.ResponseWriter, r *http.Request) {
3233
http.ServeFile(w, r, path.String())
34+
if isDaemon {
35+
// Test that the user-agent contains metadata from the context when the CLI is in daemon mode
36+
require.Contains(t, r.Header.Get("User-Agent"), "arduino-cli/git-snapshot grpc-go")
37+
}
3338
})
3439
server := &http.Server{
3540
Addr: fmt.Sprintf(":%d", port),
3641
Handler: mux,
3742
}
3843

39-
t := env.T()
4044
fileURL, err := url.Parse(fmt.Sprintf("http://127.0.0.1:%d/%s", port, path.Base()))
4145
require.NoError(t, err)
4246

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.