Skip to content

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

+5
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

+22
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)