|
| 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 | +} |
0 commit comments