|
| 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 | + "testing" |
| 20 | + |
| 21 | + "github.com/arduino/arduino-app-cli/internal/orchestrator/app" |
| 22 | + "github.com/arduino/arduino-app-cli/internal/orchestrator/bricksindex" |
| 23 | + "github.com/arduino/arduino-app-cli/internal/orchestrator/modelsindex" |
| 24 | + "github.com/arduino/go-paths-helper" |
| 25 | + "github.com/stretchr/testify/require" |
| 26 | + "go.bug.st/f" |
| 27 | +) |
| 28 | + |
| 29 | +func TestBrickCreateWithModulesUpdate(t *testing.T) { |
| 30 | + bricksIndex, err := bricksindex.GenerateBricksIndexFromFile(paths.New("testdata")) |
| 31 | + require.Nil(t, err) |
| 32 | + modelsIndex, err := modelsindex.GenerateModelsIndexFromFile(paths.New("testdata")) |
| 33 | + require.Nil(t, err) |
| 34 | + brickService := NewService(modelsIndex, bricksIndex, nil) |
| 35 | + |
| 36 | + /* |
| 37 | + t.Run("add a new brick with a model to an App", func(t *testing.T) { |
| 38 | + // we want to verify the model key in the app.yaml |
| 39 | + } |
| 40 | + t.Run("add a new brick with a model and a variable to an App", func(t *testing.T) { |
| 41 | + // we want to verify the model key in the app.yaml |
| 42 | + // we want to verify the model-variable key and value in the app.yaml |
| 43 | + } |
| 44 | + t.Run("add a new brick with a model and a not defined variable to an App", func(t *testing.T) { |
| 45 | + // we want to raise error because the provided variable is not defined in the brick.conf |
| 46 | + // app.yaml fails |
| 47 | + // OR |
| 48 | + // we want to ignore unknown used defined variables (bricks variable behavior) |
| 49 | + } |
| 50 | + t.Run("add a new brick with a not defined model", func(t *testing.T) { |
| 51 | + // we want to raise error because the provided model is not defined in the brick.conf |
| 52 | + // app.yaml fails |
| 53 | + } |
| 54 | + t.Run("add a new brick with a model where we define only a part of the variables decalred in the brick", func(t *testing.T) { |
| 55 | + // we want to raise error because some variables are unset (this means all are required variables) |
| 56 | + // app.yaml fails |
| 57 | + } |
| 58 | + // TODO: could this break calls from upper layers? |
| 59 | + // Update BrickCreateUpdateRequest by adding Model Variables |
| 60 | + req := BrickCreateUpdateRequest{ |
| 61 | + ID: "arduino:test_brick", |
| 62 | + Variables: map[string]string{"TEST_VAR_1": "user-provided-test1"}, |
| 63 | + Model: &model, |
| 64 | + MoldelVariables: map[string]string{"EI_AUDIO_CLASSIFICATION_MODEL": "custom model variable"}, |
| 65 | + } |
| 66 | + */ |
| 67 | + t.Run("add a brick to an App", func(t *testing.T) { |
| 68 | + dummyApp := appDummySetup(t) |
| 69 | + |
| 70 | + model := "glass-breaking" |
| 71 | + req := BrickCreateUpdateRequest{ |
| 72 | + ID: "arduino:test_brick", |
| 73 | + Variables: map[string]string{"BRICK_VAR1": "user-provided-brick-level-var1"}, |
| 74 | + Model: &model, |
| 75 | + } |
| 76 | + |
| 77 | + // act |
| 78 | + err = brickService.BrickCreate(req, f.Must(app.Load(dummyApp.String()))) |
| 79 | + require.Nil(t, err) |
| 80 | + |
| 81 | + // assert |
| 82 | + after, err := app.Load(dummyApp.String()) |
| 83 | + require.Nil(t, err) |
| 84 | + require.Len(t, after.Descriptor.Bricks, 2) |
| 85 | + require.Equal(t, "arduino:test_brick", after.Descriptor.Bricks[1].ID) |
| 86 | + }) |
| 87 | + |
| 88 | +} |
| 89 | + |
| 90 | +func appDummySetup(t *testing.T) *paths.Path { |
| 91 | + tempDummyApp := paths.New("testdata/dummy-app.temp") |
| 92 | + err := tempDummyApp.RemoveAll() |
| 93 | + require.Nil(t, err) |
| 94 | + require.Nil(t, paths.New("testdata/dummy-app").CopyDirTo(tempDummyApp)) |
| 95 | + return tempDummyApp |
| 96 | +} |
0 commit comments