Skip to content

Commit 7f64261

Browse files
committed
Resource: increase code coverage
1 parent d552883 commit 7f64261

File tree

2 files changed

+28
-5
lines changed

2 files changed

+28
-5
lines changed

Diff for: arduino/resources/helpers.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,11 @@ func (r *DownloadResource) IsCached(downloadDir *paths.Path) (bool, error) {
5252

5353
// Download a DownloadResource.
5454
func (r *DownloadResource) Download(downloadDir *paths.Path, config *downloader.Config) (*downloader.Downloader, error) {
55+
path, err := r.ArchivePath(downloadDir)
56+
if err != nil {
57+
return nil, fmt.Errorf("getting archive path: %s", err)
58+
}
59+
5560
cached, err := r.TestLocalArchiveIntegrity(downloadDir)
5661
if err != nil {
5762
return nil, fmt.Errorf("testing local archive integrity: %s", err)
@@ -61,11 +66,6 @@ func (r *DownloadResource) Download(downloadDir *paths.Path, config *downloader.
6166
return nil, nil
6267
}
6368

64-
path, err := r.ArchivePath(downloadDir)
65-
if err != nil {
66-
return nil, fmt.Errorf("getting archive path: %s", err)
67-
}
68-
6969
if stats, err := path.Stat(); os.IsNotExist(err) {
7070
// normal download
7171
} else if err == nil && stats.Size() > r.Size {

Diff for: arduino/resources/helpers_test.go

+23
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,29 @@ func TestResourcesSanityChecks(t *testing.T) {
8484
}
8585
}
8686

87+
func TestResourceErrorHandling(t *testing.T) {
88+
tmp, err := paths.MkTempDir("", "")
89+
require.NoError(t, err)
90+
defer tmp.RemoveAll()
91+
92+
r := &DownloadResource{
93+
ArchiveFileName: "..",
94+
CachePath: "cache",
95+
}
96+
97+
c, err := r.IsCached(tmp)
98+
require.Error(t, err)
99+
require.False(t, c)
100+
101+
d, err := r.Download(tmp, nil)
102+
require.Error(t, err)
103+
require.Nil(t, d)
104+
105+
e, err := r.TestLocalArchiveIntegrity(tmp)
106+
require.Error(t, err)
107+
require.False(t, e)
108+
}
109+
87110
func TestDownloadApplyUserAgentHeaderUsingConfig(t *testing.T) {
88111
goldUserAgentValue := fmt.Sprintf("arduino-cli/0.0.0-test.preview (amd64; linux; go1.12.4) Commit:deadbeef/Build:2019-06-12 11:11:11.111")
89112
goldUserAgentString := "User-Agent: " + goldUserAgentValue

0 commit comments

Comments
 (0)