Skip to content

Commit 7e1c6ba

Browse files
committed
add unit test
1 parent 7e53af6 commit 7e1c6ba

File tree

1 file changed

+81
-0
lines changed

1 file changed

+81
-0
lines changed
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
package bricks
2+
3+
import (
4+
"testing"
5+
6+
"github.com/arduino/arduino-app-cli/internal/orchestrator/bricksindex"
7+
"github.com/stretchr/testify/require"
8+
)
9+
10+
func TestGetBrickInstanceVariableDetails(t *testing.T) {
11+
tests := []struct {
12+
name string
13+
brick *bricksindex.Brick
14+
brickInstanceVariables map[string]string
15+
expected []BrickInstanceVariable
16+
}{
17+
{
18+
name: "variable is present in the map",
19+
brick: &bricksindex.Brick{
20+
Variables: []bricksindex.BrickVariable{
21+
{Name: "VAR1", Description: "desc"},
22+
},
23+
},
24+
brickInstanceVariables: map[string]string{"VAR1": "value1"},
25+
expected: []BrickInstanceVariable{
26+
{Name: "VAR1", Value: "value1", Description: "desc", Required: true},
27+
},
28+
},
29+
{
30+
name: "variable not present in the map",
31+
brick: &bricksindex.Brick{
32+
Variables: []bricksindex.BrickVariable{
33+
{Name: "VAR1", Description: "desc"},
34+
},
35+
},
36+
brickInstanceVariables: map[string]string{},
37+
expected: []BrickInstanceVariable{
38+
{Name: "VAR1", Value: "", Description: "desc", Required: true},
39+
},
40+
},
41+
{
42+
name: "variable with default value",
43+
brick: &bricksindex.Brick{
44+
Variables: []bricksindex.BrickVariable{
45+
{Name: "VAR1", DefaultValue: "default", Description: "desc"},
46+
},
47+
},
48+
brickInstanceVariables: map[string]string{},
49+
expected: []BrickInstanceVariable{
50+
{Name: "VAR1", Value: "", Description: "desc", Required: false},
51+
},
52+
},
53+
{
54+
name: "multiple variables",
55+
brick: &bricksindex.Brick{
56+
Variables: []bricksindex.BrickVariable{
57+
{Name: "VAR1", Description: "desc1"},
58+
{Name: "VAR2", DefaultValue: "def2", Description: "desc2"},
59+
},
60+
},
61+
brickInstanceVariables: map[string]string{"VAR1": "v1"},
62+
expected: []BrickInstanceVariable{
63+
{Name: "VAR1", Value: "v1", Description: "desc1", Required: true},
64+
{Name: "VAR2", Value: "", Description: "desc2", Required: false},
65+
},
66+
},
67+
{
68+
name: "no variables",
69+
brick: &bricksindex.Brick{Variables: []bricksindex.BrickVariable{}},
70+
brickInstanceVariables: map[string]string{},
71+
expected: []BrickInstanceVariable{},
72+
},
73+
}
74+
75+
for _, tt := range tests {
76+
t.Run(tt.name, func(t *testing.T) {
77+
got := getBrickInstanceVariableDetails(tt.brick, tt.brickInstanceVariables)
78+
require.Equal(t, tt.expected, got)
79+
})
80+
}
81+
}

0 commit comments

Comments
 (0)