Skip to content

Commit

Permalink
Throw an error when a tool has no compatible flavour with the current…
Browse files Browse the repository at this point in the history
… OS (#214)

* Throw an error when a tool has no compatible flavour with the current OS

* Add TestDownloadToolMissingFlavour to unit tests
  • Loading branch information
MatteoPologruto committed Aug 22, 2023
1 parent 4cf4a56 commit 45b115d
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
5 changes: 5 additions & 0 deletions indexes/download/download.go
Expand Up @@ -45,6 +45,11 @@ import (
// DownloadTool downloads and returns the path on the local filesystem of a tool
func DownloadTool(toolRelease *cores.ToolRelease) (*paths.Path, error) {
resource := toolRelease.GetCompatibleFlavour()
if resource == nil {
err := fmt.Errorf("tool %s not available for this OS", toolRelease.String())
logrus.Error(err)
return nil, err
}
installDir := globals.FwUploaderPath.Join(
"tools",
toolRelease.Tool.Name,
Expand Down
22 changes: 22 additions & 0 deletions indexes/download/download_test.go
Expand Up @@ -140,3 +140,25 @@ func TestDownloadFirmware(t *testing.T) {
require.NotEmpty(t, firmwarePath)
require.FileExists(t, firmwarePath.String())
}

func TestDownloadToolMissingFlavour(t *testing.T) {
toolRelease := &cores.ToolRelease{
Version: semver.ParseRelaxed("1.7.0-arduino3"),
Tool: &cores.Tool{
Name: "bossac",
Package: &cores.Package{
Name: "arduino",
},
},
Flavors: []*cores.Flavor{},
}
defer os.RemoveAll(globals.FwUploaderPath.String())
indexFile := paths.New("testdata/package_index.json")
t.Logf("testing with index: %s", indexFile)
index, e := packageindex.LoadIndexNoSign(indexFile)
require.NoError(t, e)
require.NotEmpty(t, index)
toolDir, err := DownloadTool(toolRelease)
require.Error(t, err)
require.Empty(t, toolDir)
}

0 comments on commit 45b115d

Please sign in to comment.