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 1558e7b

Browse files
committed
Updated integration tests
1 parent 31722ce commit 1558e7b

File tree

3 files changed

+86
-50
lines changed

3 files changed

+86
-50
lines changed

‎internal/integrationtest/daemon/daemon_core_test.go‎

Lines changed: 22 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -41,59 +41,38 @@ func TestDaemonCoreUpdateIndex(t *testing.T) {
4141
` "http://downloads.arduino.cc/package_inexistent_index.json"]`)
4242
require.NoError(t, err)
4343

44+
analyzeUpdateIndexClient := func(cl commands.ArduinoCoreService_UpdateIndexClient) (error, map[string]*commands.DownloadProgressEnd) {
45+
analyzer := NewDownloadProgressAnalyzer(t)
46+
for {
47+
msg, err := cl.Recv()
48+
// fmt.Println("DOWNLOAD>", msg)
49+
if err == io.EOF {
50+
return nil, analyzer.Results
51+
}
52+
if err != nil {
53+
return err, analyzer.Results
54+
}
55+
require.NoError(t, err)
56+
analyzer.Process(msg.GetDownloadProgress())
57+
}
58+
}
59+
4460
{
4561
cl, err := grpcInst.UpdateIndex(context.Background(), true)
4662
require.NoError(t, err)
47-
res, err := analyzeUpdateIndexStream(t, cl)
63+
err, res := analyzeUpdateIndexClient(cl)
4864
require.NoError(t, err)
4965
require.Len(t, res, 1)
50-
require.True(t, res["https://downloads.arduino.cc/packages/package_index.tar.bz2"].Successful)
66+
require.True(t, res["https://downloads.arduino.cc/packages/package_index.tar.bz2"].Success)
5167
}
5268
{
5369
cl, err := grpcInst.UpdateIndex(context.Background(), false)
5470
require.NoError(t, err)
55-
res, err := analyzeUpdateIndexStream(t, cl)
71+
err, res := analyzeUpdateIndexClient(cl)
5672
require.Error(t, err)
5773
require.Len(t, res, 3)
58-
require.True(t, res["https://downloads.arduino.cc/packages/package_index.tar.bz2"].Successful)
59-
require.True(t, res["http://arduino.esp8266.com/stable/package_esp8266com_index.json"].Successful)
60-
require.False(t, res["http://downloads.arduino.cc/package_inexistent_index.json"].Successful)
61-
}
62-
}
63-
64-
// analyzeUpdateIndexStream runs an update index checking if the sequence of DownloadProgress and
65-
// DownloadResult messages is correct. It returns a map reporting all the DownloadResults messages
66-
// received (it maps urls to DownloadResults).
67-
func analyzeUpdateIndexStream(t *testing.T, cl commands.ArduinoCoreService_UpdateIndexClient) (map[string]*commands.DownloadResult, error) {
68-
ongoingDownload := ""
69-
results := map[string]*commands.DownloadResult{}
70-
for {
71-
msg, err := cl.Recv()
72-
if err == io.EOF {
73-
return results, nil
74-
}
75-
if err != nil {
76-
return results, err
77-
}
78-
require.NoError(t, err)
79-
fmt.Printf("UPDATE> %+v\n", msg)
80-
if progress := msg.GetDownloadProgress(); progress != nil {
81-
if progress.Url != "" && progress.Url != ongoingDownload {
82-
require.Empty(t, ongoingDownload, "DownloadProgress: started a download without 'completing' the previous one")
83-
ongoingDownload = progress.Url
84-
}
85-
if progress.Completed {
86-
require.NotEmpty(t, ongoingDownload, "DownloadProgress: received a 'completed' notification but never initiated a download")
87-
ongoingDownload = ""
88-
}
89-
if progress.Downloaded > 0 {
90-
require.NotEmpty(t, ongoingDownload, "DownloadProgress: received a download update but never initiated a download")
91-
}
92-
} else if result := msg.GetDownloadResult(); result != nil {
93-
require.Empty(t, ongoingDownload, "DownloadResult: got a download result without completing the current download first")
94-
results[result.Url] = result
95-
} else {
96-
require.FailNow(t, "DownloadProgress: received an empty message (without a Progress or a Result)")
97-
}
74+
require.True(t, res["https://downloads.arduino.cc/packages/package_index.tar.bz2"].Success)
75+
require.True(t, res["http://arduino.esp8266.com/stable/package_esp8266com_index.json"].Success)
76+
require.False(t, res["http://downloads.arduino.cc/package_inexistent_index.json"].Success)
9877
}
9978
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
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 daemon_test
17+
18+
import (
19+
"testing"
20+
21+
"github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1"
22+
"github.com/stretchr/testify/require"
23+
)
24+
25+
// DownloadProgressAnalyzer analyzes DownloadProgress messages for consistency
26+
type DownloadProgressAnalyzer struct {
27+
t *testing.T
28+
ongoingDownload string
29+
Results map[string]*commands.DownloadProgressEnd
30+
}
31+
32+
// NewDownloadProgressAnalyzer creates a new DownloadProgressAnalyzer
33+
func NewDownloadProgressAnalyzer(t *testing.T) *DownloadProgressAnalyzer {
34+
return &DownloadProgressAnalyzer{
35+
t: t,
36+
Results: map[string]*commands.DownloadProgressEnd{},
37+
}
38+
}
39+
40+
// Process the given DownloadProgress message. If inconsistencies are detected the
41+
// test will fail.
42+
func (a *DownloadProgressAnalyzer) Process(progress *commands.DownloadProgress) {
43+
if progress == nil {
44+
return
45+
}
46+
if start := progress.GetStart(); start != nil {
47+
require.Empty(a.t, a.ongoingDownload, "DownloadProgressStart: started a download without 'completing' the previous one")
48+
a.ongoingDownload = start.Url
49+
} else if update := progress.GetUpdate(); update != nil {
50+
require.NotEmpty(a.t, a.ongoingDownload, "DownloadProgressUpdate: received update, but the download is not yet started...")
51+
} else if end := progress.GetEnd(); end != nil {
52+
require.NotEmpty(a.t, a.ongoingDownload, "DownloadProgress: received a 'completed' notification but never initiated a download")
53+
a.Results[a.ongoingDownload] = end
54+
a.ongoingDownload = ""
55+
} else {
56+
require.FailNow(a.t, "DownloadProgress: received an empty DownloadProgress (without Start, Update or End)")
57+
}
58+
}

‎test/test_core.py‎

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,10 @@ def test_core_updateindex_url_not_found(run_command, httpserver):
9494

9595
result = run_command(["core", "update-index", f"--additional-urls={url}"])
9696
assert result.failed
97-
lines = [l.strip() for l in result.stderr.splitlines()]
98-
assert f"Error updating index: Error downloading index '{url}': Server responded with: 404 NOT FOUND" in lines
97+
linesout = [l.strip() for l in result.stdout.splitlines()]
98+
assert "Downloading index: test_index.json Server responded with: 404 NOT FOUND" in linesout
99+
lineserr = [l.strip() for l in result.stderr.splitlines()]
100+
assert "Some indexes could not be updated." in lineserr
99101

100102

101103
def test_core_updateindex_internal_server_error(run_command, httpserver):
@@ -107,11 +109,8 @@ def test_core_updateindex_internal_server_error(run_command, httpserver):
107109

108110
result = run_command(["core", "update-index", f"--additional-urls={url}"])
109111
assert result.failed
110-
lines = [l.strip() for l in result.stderr.splitlines()]
111-
assert (
112-
f"Error updating index: Error downloading index '{url}': Server responded with: 500 INTERNAL SERVER ERROR"
113-
in lines
114-
)
112+
lines = [l.strip() for l in result.stdout.splitlines()]
113+
assert "Downloading index: test_index.json Server responded with: 500 INTERNAL SERVER ERROR" in lines
115114

116115

117116
def test_core_install_without_updateindex(run_command):

0 commit comments

Comments
(0)

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