-
Notifications
You must be signed in to change notification settings - Fork 1
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+150
−10
Merged
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 d1e01fe
feat(bricks): enhance error messages and add tests for BrickCreate fu…
dido18 c579998
feat(tests): update BrickCreate tests and add dummy app configurations
dido18 34b6e0e
fix(tests): correct error handling in TestOverrideBrickVariablesOfApp
dido18 190f079
fix(go.sum): remove outdated dependencies for kin-openapi and oapi-co…
dido18 d27a951
Update internal/orchestrator/bricks/bricks_test.go
dido18 d2eefb4
Update internal/orchestrator/bricks/testdata/my-app.override/app.yaml
dido18 13e77f0
Update internal/orchestrator/bricks/testdata/dummy-app/app.yaml
dido18 d770c4b
Update internal/orchestrator/bricks/testdata/my-app.source/app.yaml
dido18 af3b76b
delete: remove unused override files for my-app
dido18 56124d4
Update main function in main.py to remove empty comment
dido18 52feffd
go mod revert
dido18 079fdda
fix: reorder import statements in bricks_test.go for consistency
dido18 9655a60
Update internal/orchestrator/bricks/testdata/dummy-app/python/main.py
dido18 8066017
refactor: update test cases for brick creation and variable overrides…
dido18 1ada20c
Update internal/orchestrator/bricks/bricks.go
dido18 53e7443
Update internal/orchestrator/bricks/bricks.go
dido18 a00c705
Update internal/orchestrator/bricks/bricks.go
dido18 e1f746b
Update internal/orchestrator/bricks/bricks.go
dido18 b06ff39
fix: update error messages in BrickCreate tests for consistency
dido18 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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,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" | ||
dido18 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| "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 | ||
dido18 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| // 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"]) | ||
| } | ||
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 @@ | ||
| my-app.override/ |
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 |
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,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: ☁️ | ||
dido18 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
2 changes: 2 additions & 0 deletions
2
internal/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(): | ||
| # empty file | ||
dido18 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
9 changes: 9 additions & 0 deletions
9
internal/orchestrator/bricks/testdata/my-app.override/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,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: ☁️ | ||
dido18 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
2 changes: 2 additions & 0 deletions
2
internal/orchestrator/bricks/testdata/my-app.override/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(): | ||
| # empty file |
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 | ||
| ports: [] | ||
| bricks: | ||
| - arduino:arduino_cloud: | ||
| icon: ☁️ | ||
dido18 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
2 changes: 2 additions & 0 deletions
2
internal/orchestrator/bricks/testdata/my-app.source/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(): | ||
| # empty file | ||
dido18 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
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.
Uh oh!
There was an error while loading. Please reload this page.