Skip to content

Commit 68ad650

Browse files
committed
fix(bricks): overwrite the variables of an app
1 parent a2f7219 commit 68ad650

File tree

5 files changed

+82
-1
lines changed

5 files changed

+82
-1
lines changed

internal/orchestrator/bricks/bricks.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,6 @@ func (s *Service) BrickCreate(
204204
if _, exist := req.Variables[brickVar.Name]; !exist {
205205
return errors.New("variable does not exist")
206206
}
207-
return errors.New("variable default value cannot be empty")
208207
}
209208
}
210209

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
// This file is part of arduino-app-cli.
2+
//
3+
// Copyright 2025 ARDUINO SA (http://www.arduino.cc/)
4+
//
5+
// This software is released under the GNU General Public License version 3,
6+
// which covers the main part of arduino-app-cli.
7+
// The terms of this license can be found at:
8+
// https://www.gnu.org/licenses/gpl-3.0.en.html
9+
//
10+
// You can be released from the requirements of the above licenses by purchasing
11+
// a commercial license. Buying such a license is mandatory if you want to
12+
// modify or otherwise use the software for commercial activities involving the
13+
// Arduino software without disclosing the source code of your own applications.
14+
// To purchase a commercial license, send an email to license@arduino.cc.
15+
16+
package bricks
17+
18+
import (
19+
"fmt"
20+
"math/rand"
21+
"testing"
22+
23+
"github.com/stretchr/testify/require"
24+
"go.bug.st/f"
25+
26+
"github.com/arduino/arduino-app-cli/internal/orchestrator/app"
27+
"github.com/arduino/arduino-app-cli/internal/orchestrator/bricksindex"
28+
"github.com/arduino/go-paths-helper"
29+
)
30+
31+
func TestOverrideBrickVariablesOfApp(t *testing.T) {
32+
bricksIndex, err := bricksindex.GenerateBricksIndexFromFile(paths.New("testdata"))
33+
require.Nil(t, err)
34+
brickService := NewService(nil, bricksIndex, nil)
35+
36+
deviceID := fmt.Sprintf("my-device-id-%x", rand.Int())
37+
secret := fmt.Sprintf("my-device-secret-%x", rand.Int())
38+
39+
req := BrickCreateUpdateRequest{
40+
ID: "arduino:arduino_cloud",
41+
Variables: map[string]string{
42+
"ARDUINO_DEVICE_ID": deviceID,
43+
"ARDUINO_SECRET": secret,
44+
},
45+
}
46+
47+
err = brickService.BrickCreate(req, f.Must(app.Load("./testdata/my-app")))
48+
require.Nil(t, err)
49+
50+
after, err := app.Load("./testdata/my-app")
51+
require.Nil(t, err)
52+
require.Len(t, after.Descriptor.Bricks, 1)
53+
require.Equal(t, "arduino:arduino_cloud", after.Descriptor.Bricks[0].ID)
54+
require.Equal(t, deviceID, after.Descriptor.Bricks[0].Variables["ARDUINO_DEVICE_ID"])
55+
require.Equal(t, secret, after.Descriptor.Bricks[0].Variables["ARDUINO_SECRET"])
56+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
bricks:
2+
- id: arduino:arduino_cloud
3+
name: Arduino Cloud
4+
description: Connects to Arduino Cloud
5+
require_container: false
6+
require_model: false
7+
require_devices: false
8+
mount_devices_into_container: false
9+
ports: []
10+
category: null
11+
variables:
12+
- name: ARDUINO_DEVICE_ID
13+
description: Arduino Cloud Device ID
14+
- name: ARDUINO_SECRET
15+
description: Arduino Cloud Secret
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
name: Copy of Blinking LED from Arduino Cloud
2+
description: Control the LED from the Arduino IoT Cloud using RPC calls
3+
ports: []
4+
bricks:
5+
- arduino:arduino_cloud:
6+
variables:
7+
ARDUINO_DEVICE_ID: my-device-id-79c4b05ef7b6a39
8+
ARDUINO_SECRET: my-device-secret-43f4a190b1ffb8ce
9+
icon: ☁️
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
def main():
2+
# empty file

0 commit comments

Comments
 (0)