@@ -10,10 +10,11 @@ import (
1010
1111func TestGetBrickInstanceVariableDetails (t * testing.T ) {
1212 tests := []struct {
13- name string
14- brick * bricksindex.Brick
15- brickInstanceVariables map [string ]string
16- expected []BrickInstanceVariable
13+ name string
14+ brick * bricksindex.Brick
15+ userVariables map [string ]string
16+ expectedInstanceVariable []BrickInstanceVariable
17+ expectedVariableMap map [string ]string
1718 }{
1819 {
1920 name : "variable is present in the map" ,
@@ -22,10 +23,11 @@ func TestGetBrickInstanceVariableDetails(t *testing.T) {
2223 {Name : "VAR1" , Description : "desc" },
2324 },
2425 },
25- brickInstanceVariables : map [string ]string {"VAR1" : "value1" },
26- expected : []BrickInstanceVariable {
26+ userVariables : map [string ]string {"VAR1" : "value1" },
27+ expectedInstanceVariable : []BrickInstanceVariable {
2728 {Name : "VAR1" , Value : "value1" , Description : "desc" , Required : true },
2829 },
30+ expectedVariableMap : map [string ]string {"VAR1" : "value1" },
2931 },
3032 {
3133 name : "variable not present in the map" ,
@@ -34,10 +36,11 @@ func TestGetBrickInstanceVariableDetails(t *testing.T) {
3436 {Name : "VAR1" , Description : "desc" },
3537 },
3638 },
37- brickInstanceVariables : map [string ]string {},
38- expected : []BrickInstanceVariable {
39+ userVariables : map [string ]string {},
40+ expectedInstanceVariable : []BrickInstanceVariable {
3941 {Name : "VAR1" , Value : "" , Description : "desc" , Required : true },
4042 },
43+ expectedVariableMap : map [string ]string {"VAR1" : "" },
4144 },
4245 {
4346 name : "variable with default value" ,
@@ -46,10 +49,11 @@ func TestGetBrickInstanceVariableDetails(t *testing.T) {
4649 {Name : "VAR1" , DefaultValue : "default" , Description : "desc" },
4750 },
4851 },
49- brickInstanceVariables : map [string ]string {},
50- expected : []BrickInstanceVariable {
51- {Name : "VAR1" , Value : "" , Description : "desc" , Required : false },
52+ userVariables : map [string ]string {},
53+ expectedInstanceVariable : []BrickInstanceVariable {
54+ {Name : "VAR1" , Value : "default " , Description : "desc" , Required : false },
5255 },
56+ expectedVariableMap : map [string ]string {"VAR1" : "default" },
5357 },
5458 {
5559 name : "multiple variables" ,
@@ -59,24 +63,27 @@ func TestGetBrickInstanceVariableDetails(t *testing.T) {
5963 {Name : "VAR2" , DefaultValue : "def2" , Description : "desc2" },
6064 },
6165 },
62- brickInstanceVariables : map [string ]string {"VAR1" : "v1" },
63- expected : []BrickInstanceVariable {
66+ userVariables : map [string ]string {"VAR1" : "v1" },
67+ expectedInstanceVariable : []BrickInstanceVariable {
6468 {Name : "VAR1" , Value : "v1" , Description : "desc1" , Required : true },
65- {Name : "VAR2" , Value : "" , Description : "desc2" , Required : false },
69+ {Name : "VAR2" , Value : "def2 " , Description : "desc2" , Required : false },
6670 },
71+ expectedVariableMap : map [string ]string {"VAR1" : "v1" , "VAR2" : "def2" },
6772 },
6873 {
69- name : "no variables" ,
70- brick : & bricksindex.Brick {Variables : []bricksindex.BrickVariable {}},
71- brickInstanceVariables : map [string ]string {},
72- expected : []BrickInstanceVariable {},
74+ name : "no variables" ,
75+ brick : & bricksindex.Brick {Variables : []bricksindex.BrickVariable {}},
76+ userVariables : map [string ]string {},
77+ expectedInstanceVariable : []BrickInstanceVariable {},
78+ expectedVariableMap : map [string ]string {},
7379 },
7480 }
7581
7682 for _ , tt := range tests {
7783 t .Run (tt .name , func (t * testing.T ) {
78- got := getBrickInstanceVariableDetails (tt .brick , tt .brickInstanceVariables )
79- require .Equal (t , tt .expected , got )
84+ actualVariableMap , actualInstanceVariables := getBrickVariableDetails (tt .brick , tt .userVariables )
85+ require .Equal (t , tt .expectedVariableMap , actualVariableMap )
86+ require .Equal (t , tt .expectedInstanceVariable , actualInstanceVariables )
8087 })
8188 }
8289}
0 commit comments