Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
68ad650
fix(bricks): overwrite the variables of an app
dido18 Nov 4, 2025
d1e01fe
feat(bricks): enhance error messages and add tests for BrickCreate fu…
dido18 Nov 4, 2025
c579998
feat(tests): update BrickCreate tests and add dummy app configurations
dido18 Nov 5, 2025
34b6e0e
fix(tests): correct error handling in TestOverrideBrickVariablesOfApp
dido18 Nov 5, 2025
190f079
fix(go.sum): remove outdated dependencies for kin-openapi and oapi-co…
dido18 Nov 5, 2025
d27a951
Update internal/orchestrator/bricks/bricks_test.go
dido18 Nov 5, 2025
d2eefb4
Update internal/orchestrator/bricks/testdata/my-app.override/app.yaml
dido18 Nov 5, 2025
13e77f0
Update internal/orchestrator/bricks/testdata/dummy-app/app.yaml
dido18 Nov 5, 2025
d770c4b
Update internal/orchestrator/bricks/testdata/my-app.source/app.yaml
dido18 Nov 5, 2025
af3b76b
delete: remove unused override files for my-app
dido18 Nov 5, 2025
56124d4
Update main function in main.py to remove empty comment
dido18 Nov 5, 2025
52feffd
go mod revert
dido18 Nov 5, 2025
079fdda
fix: reorder import statements in bricks_test.go for consistency
dido18 Nov 5, 2025
9655a60
Update internal/orchestrator/bricks/testdata/dummy-app/python/main.py
dido18 Nov 5, 2025
8066017
refactor: update test cases for brick creation and variable overrides…
dido18 Nov 6, 2025
1ada20c
Update internal/orchestrator/bricks/bricks.go
dido18 Nov 6, 2025
53e7443
Update internal/orchestrator/bricks/bricks.go
dido18 Nov 6, 2025
a00c705
Update internal/orchestrator/bricks/bricks.go
dido18 Nov 6, 2025
e1f746b
Update internal/orchestrator/bricks/bricks.go
dido18 Nov 6, 2025
b06ff39
fix: update error messages in BrickCreate tests for consistency
dido18 Nov 6, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ require (
github.com/fsnotify/fsnotify v1.9.0 // indirect
github.com/fvbommel/sortorder v1.1.0 // indirect
github.com/fxamacker/cbor/v2 v2.7.0 // indirect
github.com/getkin/kin-openapi v0.132.0 // indirect
github.com/getkin/kin-openapi v0.133.0 // indirect
github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376 // indirect
github.com/go-git/go-billy/v5 v5.6.2 // indirect
github.com/go-git/go-git/v5 v5.16.2 // indirect
Expand Down Expand Up @@ -206,7 +206,7 @@ require (
github.com/morikuni/aec v1.0.0 // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/mxk/go-flowrate v0.0.0-20140419014527-cca7078d478f // indirect
github.com/oapi-codegen/oapi-codegen/v2 v2.5.0 // indirect
github.com/oapi-codegen/oapi-codegen/v2 v2.5.1 // indirect
github.com/oasdiff/yaml v0.0.0-20250309154309-f31be36b4037 // indirect
github.com/oasdiff/yaml3 v0.0.0-20250309153720-d2182401db90 // indirect
github.com/opencontainers/go-digest v1.0.0 // indirect
Expand Down Expand Up @@ -257,6 +257,7 @@ require (
github.com/ulikunitz/xz v0.5.15 // indirect
github.com/vmihailenco/tagparser/v2 v2.0.0 // indirect
github.com/vmware-labs/yaml-jsonpath v0.3.2 // indirect
github.com/woodsbury/decimal128 v1.3.0 // indirect
github.com/x448/float16 v0.8.4 // indirect
github.com/xanzy/ssh-agent v0.3.3 // indirect
github.com/xeipuuv/gojsonpointer v0.0.0-20190905194746-02993c407bfb // indirect
Expand Down
10 changes: 6 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -310,8 +310,8 @@ github.com/fvbommel/sortorder v1.1.0 h1:fUmoe+HLsBTctBDoaBwpQo5N+nrCp8g/BjKb/6ZQ
github.com/fvbommel/sortorder v1.1.0/go.mod h1:uk88iVf1ovNn1iLfgUVU2F9o5eO30ui720w+kxuqRs0=
github.com/fxamacker/cbor/v2 v2.7.0 h1:iM5WgngdRBanHcxugY4JySA0nk1wZorNOpTgCMedv5E=
github.com/fxamacker/cbor/v2 v2.7.0/go.mod h1:pxXPTn3joSm21Gbwsv0w9OSA2y1HFR9qXEeXQVeNoDQ=
github.com/getkin/kin-openapi v0.132.0 h1:3ISeLMsQzcb5v26yeJrBcdTCEQTag36ZjaGk7MIRUwk=
github.com/getkin/kin-openapi v0.132.0/go.mod h1:3OlG51PCYNsPByuiMB0t4fjnNlIDnaEDsjiKUV8nL58=
github.com/getkin/kin-openapi v0.133.0 h1:pJdmNohVIJ97r4AUFtEXRXwESr8b0bD721u/Tz6k8PQ=
github.com/getkin/kin-openapi v0.133.0/go.mod h1:boAciF6cXk5FhPqe/NQeBTeenbjqU4LhWBf09ILVvWE=
github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04=
github.com/gliderlabs/ssh v0.3.8 h1:a4YXD1V7xMF9g5nTkdfnja3Sxy1PVDCj1Zg4Wb8vY6c=
github.com/gliderlabs/ssh v0.3.8/go.mod h1:xYoytBv1sV0aL3CavoDuJIQNURXkkfPA/wxQ1pL1fAU=
Expand Down Expand Up @@ -676,8 +676,8 @@ github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLA
github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A=
github.com/nxadm/tail v1.4.8 h1:nPr65rt6Y5JFSKQO7qToXr7pePgD6Gwiw05lkbyAQTE=
github.com/nxadm/tail v1.4.8/go.mod h1:+ncqLTQzXmGhMZNUePPaPqPvBxHAIsmXswZKocGu+AU=
github.com/oapi-codegen/oapi-codegen/v2 v2.5.0 h1:iJvF8SdB/3/+eGOXEpsWkD8FQAHj6mqkb6Fnsoc8MFU=
github.com/oapi-codegen/oapi-codegen/v2 v2.5.0/go.mod h1:fwlMxUEMuQK5ih9aymrxKPQqNm2n8bdLk1ppjH+lr9w=
github.com/oapi-codegen/oapi-codegen/v2 v2.5.1 h1:5vHNY1uuPBRBWqB2Dp0G7YB03phxLQZupZTIZaeorjc=
github.com/oapi-codegen/oapi-codegen/v2 v2.5.1/go.mod h1:ro0npU1BWkcGpCgGD9QwPp44l5OIZ94tB3eabnT7DjQ=
github.com/oapi-codegen/runtime v1.1.1 h1:EXLHh0DXIJnWhdRPN2w4MXAzFyE4CskzhNLUmtpMYro=
github.com/oapi-codegen/runtime v1.1.1/go.mod h1:SK9X900oXmPWilYR5/WKPzt3Kqxn/uS/+lbpREv+eCg=
github.com/oasdiff/yaml v0.0.0-20250309154309-f31be36b4037 h1:G7ERwszslrBzRxj//JalHPu/3yz+De2J+4aLtSRlHiY=
Expand Down Expand Up @@ -909,6 +909,8 @@ github.com/warthog618/go-gpiocdev v0.9.1 h1:pwHPaqjJfhCipIQl78V+O3l9OKHivdRDdmgX
github.com/warthog618/go-gpiocdev v0.9.1/go.mod h1:dN3e3t/S2aSNC+hgigGE/dBW8jE1ONk9bDSEYfoPyl8=
github.com/warthog618/go-gpiosim v0.1.1 h1:MRAEv+T+itmw+3GeIGpQJBfanUVyg0l3JCTwHtwdre4=
github.com/warthog618/go-gpiosim v0.1.1/go.mod h1:YXsnB+I9jdCMY4YAlMSRrlts25ltjmuIsrnoUrBLdqU=
github.com/woodsbury/decimal128 v1.3.0 h1:8pffMNWIlC0O5vbyHWFZAt5yWvWcrHA+3ovIIjVWss0=
github.com/woodsbury/decimal128 v1.3.0/go.mod h1:C5UTmyTjW3JftjUFzOVhC20BEQa2a4ZKOB5I6Zjb+ds=
github.com/x448/float16 v0.8.4 h1:qLwI1I70+NjRFUR3zs1JPUCgaCXSh3SW62uAKT1mSBM=
github.com/x448/float16 v0.8.4/go.mod h1:14CWIYCyZA/cWjXOioeEpHeN/83MdbZDRQHoFcYsOfg=
github.com/xanzy/ssh-agent v0.3.3 h1:+/15pJfg/RsTxqYcX6fHqOXZwwMP+2VyYWJeWM2qQFM=
Expand Down
14 changes: 4 additions & 10 deletions internal/orchestrator/bricks/bricks.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,25 +186,24 @@ func (s *Service) BrickCreate(
) error {
brick, present := s.bricksIndex.FindBrickByID(req.ID)
if !present {
return fmt.Errorf("brick not found with id %s", req.ID)
return fmt.Errorf("brick '%s' not found", req.ID)
}

for name, reqValue := range req.Variables {
value, exist := brick.GetVariable(name)
if !exist {
return errors.New("variable does not exist")
return fmt.Errorf("variable '%s' does not exist on brick '%s'", name, brick.ID)
}
if value.DefaultValue == "" && reqValue == "" {
return errors.New("variable default value cannot be empty")
return fmt.Errorf("variable '%s' cannot be empty", name)
}
}

for _, brickVar := range brick.Variables {
if brickVar.DefaultValue == "" {
if _, exist := req.Variables[brickVar.Name]; !exist {
return errors.New("variable does not exist")
return fmt.Errorf("required variable '%s' is mandatory", brickVar.Name)
}
return errors.New("variable default value cannot be empty")
}
}

Expand All @@ -227,25 +226,20 @@ func (s *Service) BrickCreate(
if idx == -1 {
return fmt.Errorf("model %s does not exsist", *req.Model)
}

brickInstance.Model = models[idx].ID
}
brickInstance.Variables = req.Variables

if brickIndex == -1 {

appCurrent.Descriptor.Bricks = append(appCurrent.Descriptor.Bricks, brickInstance)

} else {
appCurrent.Descriptor.Bricks[brickIndex] = brickInstance

}

err := appCurrent.Save()
if err != nil {
return fmt.Errorf("cannot save brick instance with id %s", req.ID)
}

return nil
}

Expand Down
109 changes: 109 additions & 0 deletions internal/orchestrator/bricks/bricks_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
// This file is part of arduino-app-cli.
//
// Copyright 2025 ARDUINO SA (http://www.arduino.cc/)
//
// This software is released under the GNU General Public License version 3,
// which covers the main part of arduino-app-cli.
// The terms of this license can be found at:
// https://www.gnu.org/licenses/gpl-3.0.en.html
//
// You can be released from the requirements of the above licenses by purchasing
// a commercial license. Buying such a license is mandatory if you want to
// modify or otherwise use the software for commercial activities involving the
// Arduino software without disclosing the source code of your own applications.
// To purchase a commercial license, send an email to license@arduino.cc.

package bricks

import (
"testing"

"github.com/stretchr/testify/require"
"go.bug.st/f"

"github.com/arduino/go-paths-helper"

"github.com/arduino/arduino-app-cli/internal/orchestrator/app"
"github.com/arduino/arduino-app-cli/internal/orchestrator/bricksindex"
)

func TestBrickCreate(t *testing.T) {
bricksIndex, err := bricksindex.GenerateBricksIndexFromFile(paths.New("testdata"))
require.Nil(t, err)
brickService := NewService(nil, bricksIndex, nil)

t.Run("fails if brick id does not exist", func(t *testing.T) {
err = brickService.BrickCreate(BrickCreateUpdateRequest{ID: "not-existing-id"}, f.Must(app.Load("testdata/dummy-app")))
require.Error(t, err)
require.Equal(t, "brick 'not-existing-id' not found", err.Error())
})

t.Run("fails if the requestes variable is not present in the brick definition", func(t *testing.T) {
req := BrickCreateUpdateRequest{ID: "arduino:arduino_cloud", Variables: map[string]string{
"NON_EXISTING_VARIABLE": "some-value",
}}
err = brickService.BrickCreate(req, f.Must(app.Load("testdata/dummy-app")))
require.Error(t, err)
require.Equal(t, "variable 'NON_EXISTING_VARIABLE' does not exist on brick 'arduino:arduino_cloud'", err.Error())
})

t.Run("fails if a required variable is set empty", func(t *testing.T) {
req := BrickCreateUpdateRequest{ID: "arduino:arduino_cloud", Variables: map[string]string{
"ARDUINO_DEVICE_ID": "",
"ARDUINO_SECRET": "a-secret-a",
}}
err = brickService.BrickCreate(req, f.Must(app.Load("testdata/dummy-app")))
require.Error(t, err)
require.Equal(t, "variable 'ARDUINO_DEVICE_ID' cannot be empty", err.Error())
})

t.Run("fails if a mandatory variable is not present in the request", func(t *testing.T) {
req := BrickCreateUpdateRequest{ID: "arduino:arduino_cloud", Variables: map[string]string{
"ARDUINO_SECRET": "a-secret-a",
}}
err = brickService.BrickCreate(req, f.Must(app.Load("testdata/dummy-app")))
require.Error(t, err)
require.Equal(t, "required variable 'ARDUINO_DEVICE_ID' is mandatory", err.Error())
})

t.Run("the brick is added if it does not exist in the app", func(t *testing.T) {
req := BrickCreateUpdateRequest{ID: "arduino:dbstorage_sqlstore"}
// TODO: find a better way to test if the brick has been added to the app.yaml
// Currently we only check that there is no error since the app.yaml is populated with the brick at every test execution.
err = brickService.BrickCreate(req, f.Must(app.Load("testdata/dummy-app")))
require.Nil(t, err)
})
}

func TestOverrideBrickVariablesOfApp(t *testing.T) {
appWithOverride := paths.New("testdata/my-app.override")
err := appWithOverride.RemoveAll()
require.Nil(t, err)

err = paths.New("testdata/my-app.source").CopyDirTo(appWithOverride)
require.Nil(t, err)
bricksIndex, err := bricksindex.GenerateBricksIndexFromFile(paths.New("testdata"))
require.Nil(t, err)
brickService := NewService(nil, bricksIndex, nil)

deviceID := "this-is-a-device-id"
secret := "this-is-a-secret"

req := BrickCreateUpdateRequest{
ID: "arduino:arduino_cloud",
Variables: map[string]string{
"ARDUINO_DEVICE_ID": deviceID,
"ARDUINO_SECRET": secret,
},
}

err = brickService.BrickCreate(req, f.Must(app.Load("testdata/my-app.override")))
require.Nil(t, err)

after, err := app.Load("testdata/my-app.override")
require.Nil(t, err)
require.Len(t, after.Descriptor.Bricks, 1)
require.Equal(t, "arduino:arduino_cloud", after.Descriptor.Bricks[0].ID)
require.Equal(t, deviceID, after.Descriptor.Bricks[0].Variables["ARDUINO_DEVICE_ID"])
require.Equal(t, secret, after.Descriptor.Bricks[0].Variables["ARDUINO_SECRET"])
}
1 change: 1 addition & 0 deletions internal/orchestrator/bricks/testdata/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
my-app.override/
25 changes: 25 additions & 0 deletions internal/orchestrator/bricks/testdata/bricks-list.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
bricks:
- id: arduino:arduino_cloud
name: Arduino Cloud
description: Connects to Arduino Cloud
require_container: false
require_model: false
require_devices: false
mount_devices_into_container: false
ports: []
category: null
variables:
- name: ARDUINO_DEVICE_ID
description: Arduino Cloud Device ID
- name: ARDUINO_SECRET
description: Arduino Cloud Secret
- id: arduino:dbstorage_sqlstore
name: Database - SQL
description: Simplified database storage layer for Arduino sensor data using SQLite
local database.
require_container: false
require_model: false
require_devices: false
mount_devices_into_container: false
ports: []
category: storage
10 changes: 10 additions & 0 deletions internal/orchestrator/bricks/testdata/dummy-app/app.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
name: Copy of Blinking LED from Arduino Cloud
description: Control the LED from the Arduino IoT Cloud using RPC calls
ports: []
bricks:
- arduino:arduino_cloud:
variables:
ARDUINO_DEVICE_ID: my-device-id-79c4b05ef7b6a39
ARDUINO_SECRET: my-device-secret-43f4a190b1ffb8ce
- arduino:dbstorage_sqlstore: {}
icon: ☁️
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
def main():
# empty file
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
name: Copy of Blinking LED from Arduino Cloud
description: Control the LED from the Arduino IoT Cloud using RPC calls
ports: []
bricks:
- arduino:arduino_cloud:
variables:
ARDUINO_DEVICE_ID: this-is-a-device-id
ARDUINO_SECRET: this-is-a-secret
icon: ☁️
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
def main():
# empty file
6 changes: 6 additions & 0 deletions internal/orchestrator/bricks/testdata/my-app.source/app.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
name: Copy of Blinking LED from Arduino Cloud
description: Control the LED from the Arduino IoT Cloud using RPC calls
ports: []
bricks:
- arduino:arduino_cloud:
icon: ☁️
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
def main():
# empty file