Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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
dido18 merged 20 commits intomainfromfix-bricks-variables
Nov 6, 2025
Merged
Show file tree
Hide file tree
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
dido18Nov 4, 2025
d1e01fe
feat(bricks): enhance error messages and add tests for BrickCreate fu…
dido18Nov 4, 2025
c579998
feat(tests): update BrickCreate tests and add dummy app configurations
dido18Nov 5, 2025
34b6e0e
fix(tests): correct error handling in TestOverrideBrickVariablesOfApp
dido18Nov 5, 2025
190f079
fix(go.sum): remove outdated dependencies for kin-openapi and oapi-co…
dido18Nov 5, 2025
d27a951
Update internal/orchestrator/bricks/bricks_test.go
dido18Nov 5, 2025
d2eefb4
Update internal/orchestrator/bricks/testdata/my-app.override/app.yaml
dido18Nov 5, 2025
13e77f0
Update internal/orchestrator/bricks/testdata/dummy-app/app.yaml
dido18Nov 5, 2025
d770c4b
Update internal/orchestrator/bricks/testdata/my-app.source/app.yaml
dido18Nov 5, 2025
af3b76b
delete: remove unused override files for my-app
dido18Nov 5, 2025
56124d4
Update main function in main.py to remove empty comment
dido18Nov 5, 2025
52feffd
go mod revert
dido18Nov 5, 2025
079fdda
fix: reorder import statements in bricks_test.go for consistency
dido18Nov 5, 2025
9655a60
Update internal/orchestrator/bricks/testdata/dummy-app/python/main.py
dido18Nov 5, 2025
8066017
refactor: update test cases for brick creation and variable overrides…
dido18Nov 6, 2025
1ada20c
Update internal/orchestrator/bricks/bricks.go
dido18Nov 6, 2025
53e7443
Update internal/orchestrator/bricks/bricks.go
dido18Nov 6, 2025
a00c705
Update internal/orchestrator/bricks/bricks.go
dido18Nov 6, 2025
e1f746b
Update internal/orchestrator/bricks/bricks.go
dido18Nov 6, 2025
b06ff39
fix: update error messages in BrickCreate tests for consistency
dido18Nov 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

Some comments aren't visible on the classic Files Changed page.

14 changes: 4 additions & 10 deletionsinternal/orchestrator/bricks/bricks.go
View file
Open in desktop
Original file line numberDiff line numberDiff 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%qnot found", req.ID)
}

for name, reqValue := range req.Variables {
value, exist := brick.GetVariable(name)
if !exist {
returnerrors.New("variable does not exist")
returnfmt.Errorf("variable%qdoes not exist on brick %q", name, brick.ID)
}
if value.DefaultValue == "" && reqValue == "" {
returnerrors.New("variabledefault valuecannot be empty")
returnfmt.Errorf("variable%qcannot be empty", name)
}
}

for _, brickVar := range brick.Variables {
if brickVar.DefaultValue == "" {
if _, exist := req.Variables[brickVar.Name]; !exist {
returnerrors.New("variabledoes not exist")
returnfmt.Errorf("requiredvariable%q 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
112 changes: 112 additions & 0 deletionsinternal/orchestrator/bricks/bricks_test.go
View file
Open in desktop
Original file line numberDiff line numberDiff 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
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
*.temp
25 changes: 25 additions & 0 deletionsinternal/orchestrator/bricks/testdata/bricks-list.yaml
View file
Open in desktop
Original file line numberDiff line numberDiff 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
View file
Open in desktop
Original file line numberDiff line numberDiff 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:
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
def main():
pass

[8]ページ先頭

©2009-2025 Movatter.jp