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 45b115d

Browse files
Throw an error when a tool has no compatible flavour with the current OS (#214)
* Throw an error when a tool has no compatible flavour with the current OS * Add TestDownloadToolMissingFlavour to unit tests
1 parent 4cf4a56 commit 45b115d

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

‎indexes/download/download.go‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,11 @@ import (
4545
// DownloadTool downloads and returns the path on the local filesystem of a tool
4646
func DownloadTool(toolRelease *cores.ToolRelease) (*paths.Path, error) {
4747
resource := toolRelease.GetCompatibleFlavour()
48+
if resource == nil {
49+
err := fmt.Errorf("tool %s not available for this OS", toolRelease.String())
50+
logrus.Error(err)
51+
return nil, err
52+
}
4853
installDir := globals.FwUploaderPath.Join(
4954
"tools",
5055
toolRelease.Tool.Name,

‎indexes/download/download_test.go‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,3 +140,25 @@ func TestDownloadFirmware(t *testing.T) {
140140
require.NotEmpty(t, firmwarePath)
141141
require.FileExists(t, firmwarePath.String())
142142
}
143+
144+
func TestDownloadToolMissingFlavour(t *testing.T) {
145+
toolRelease := &cores.ToolRelease{
146+
Version: semver.ParseRelaxed("1.7.0-arduino3"),
147+
Tool: &cores.Tool{
148+
Name: "bossac",
149+
Package: &cores.Package{
150+
Name: "arduino",
151+
},
152+
},
153+
Flavors: []*cores.Flavor{},
154+
}
155+
defer os.RemoveAll(globals.FwUploaderPath.String())
156+
indexFile := paths.New("testdata/package_index.json")
157+
t.Logf("testing with index: %s", indexFile)
158+
index, e := packageindex.LoadIndexNoSign(indexFile)
159+
require.NoError(t, e)
160+
require.NotEmpty(t, index)
161+
toolDir, err := DownloadTool(toolRelease)
162+
require.Error(t, err)
163+
require.Empty(t, toolDir)
164+
}

0 commit comments

Comments
(0)

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