- Notifications
You must be signed in to change notification settings - Fork3
fix(bricks): overwrite the brick variables of an app#44
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Merged
+150 −10
Merged
Changes fromall commits
Commits
Show all changes
20 commits Select commitHold shift + click to select a range
68ad650 fix(bricks): overwrite the variables of an app
dido18d1e01fe feat(bricks): enhance error messages and add tests for BrickCreate fu…
dido18c579998 feat(tests): update BrickCreate tests and add dummy app configurations
dido1834b6e0e fix(tests): correct error handling in TestOverrideBrickVariablesOfApp
dido18190f079 fix(go.sum): remove outdated dependencies for kin-openapi and oapi-co…
dido18d27a951 Update internal/orchestrator/bricks/bricks_test.go
dido18d2eefb4 Update internal/orchestrator/bricks/testdata/my-app.override/app.yaml
dido1813e77f0 Update internal/orchestrator/bricks/testdata/dummy-app/app.yaml
dido18d770c4b Update internal/orchestrator/bricks/testdata/my-app.source/app.yaml
dido18af3b76b delete: remove unused override files for my-app
dido1856124d4 Update main function in main.py to remove empty comment
dido1852feffd go mod revert
dido18079fdda fix: reorder import statements in bricks_test.go for consistency
dido189655a60 Update internal/orchestrator/bricks/testdata/dummy-app/python/main.py
dido188066017 refactor: update test cases for brick creation and variable overrides…
dido181ada20c Update internal/orchestrator/bricks/bricks.go
dido1853e7443 Update internal/orchestrator/bricks/bricks.go
dido18a00c705 Update internal/orchestrator/bricks/bricks.go
dido18e1f746b Update internal/orchestrator/bricks/bricks.go
dido18b06ff39 fix: update error messages in BrickCreate tests for consistency
dido18File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
14 changes: 4 additions & 10 deletionsinternal/orchestrator/bricks/bricks.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
112 changes: 112 additions & 0 deletionsinternal/orchestrator/bricks/bricks_test.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,112 @@ | ||
| // 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/arduino/go-paths-helper" | ||
| "github.com/stretchr/testify/require" | ||
| "go.bug.st/f" | ||
| "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) { | ||
| tempDummyApp := paths.New("testdata/dummy-app.temp") | ||
| err := tempDummyApp.RemoveAll() | ||
| require.Nil(t, err) | ||
| require.Nil(t, paths.New("testdata/dummy-app").CopyDirTo(tempDummyApp)) | ||
| req := BrickCreateUpdateRequest{ID: "arduino:dbstorage_sqlstore"} | ||
| err = brickService.BrickCreate(req, f.Must(app.Load(tempDummyApp.String()))) | ||
| require.Nil(t, err) | ||
| after, err := app.Load(tempDummyApp.String()) | ||
| require.Nil(t, err) | ||
| require.Len(t, after.Descriptor.Bricks, 2) | ||
| require.Equal(t, "arduino:dbstorage_sqlstore", after.Descriptor.Bricks[1].ID) | ||
| }) | ||
| t.Run("the variables of a brick are updated", func(t *testing.T) { | ||
| tempDummyApp := paths.New("testdata/dummy-app.brick-override.temp") | ||
| err := tempDummyApp.RemoveAll() | ||
| require.Nil(t, err) | ||
| err = paths.New("testdata/dummy-app").CopyDirTo(tempDummyApp) | ||
| 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(tempDummyApp.String()))) | ||
| require.Nil(t, err) | ||
| after, err := app.Load(tempDummyApp.String()) | ||
| 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 deletionsinternal/orchestrator/bricks/testdata/.gitignore
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| *.temp |
25 changes: 25 additions & 0 deletionsinternal/orchestrator/bricks/testdata/bricks-list.yaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
| 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 |
6 changes: 6 additions & 0 deletionsinternal/orchestrator/bricks/testdata/dummy-app/app.yaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
| 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 | ||
| icon: ☁️ | ||
| ports: [] | ||
| bricks: | ||
| - arduino:arduino_cloud: |
2 changes: 2 additions & 0 deletionsinternal/orchestrator/bricks/testdata/dummy-app/python/main.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| def main(): | ||
| pass |
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.