77 "github.com/stretchr/testify/assert"
88
99 "github.com/go-task/task/v3/internal/experiments"
10+ "github.com/go-task/task/v3/taskrc/ast"
1011)
1112
1213func TestNew (t * testing.T ) {
@@ -16,60 +17,124 @@ func TestNew(t *testing.T) {
1617 )
1718 tests := []struct {
1819 name string
20+ config * ast.TaskRC
1921 allowedValues []int
20- value int
22+ env int
2123 wantEnabled bool
2224 wantActive bool
2325 wantValid error
26+ wantValue int
2427 }{
2528 {
26- name : `[] allowed, value =""` ,
29+ name : `[] allowed, env =""` ,
2730 wantEnabled : false ,
2831 wantActive : false ,
2932 },
3033 {
31- name : `[] allowed, value ="1"` ,
32- value : 1 ,
34+ name : `[] allowed, env ="1"` ,
35+ env : 1 ,
3336 wantEnabled : false ,
3437 wantActive : false ,
3538 wantValid : & experiments.InactiveError {
3639 Name : exampleExperiment ,
3740 },
41+ wantValue : 1 ,
3842 },
3943 {
40- name : `[1] allowed, value =""` ,
44+ name : `[1] allowed, env =""` ,
4145 allowedValues : []int {1 },
4246 wantEnabled : false ,
4347 wantActive : true ,
4448 },
4549 {
46- name : `[1] allowed, value ="1"` ,
50+ name : `[1] allowed, env ="1"` ,
4751 allowedValues : []int {1 },
48- value : 1 ,
52+ env : 1 ,
4953 wantEnabled : true ,
5054 wantActive : true ,
55+ wantValue : 1 ,
5156 },
5257 {
53- name : `[1] allowed, value ="2"` ,
58+ name : `[1] allowed, env ="2"` ,
5459 allowedValues : []int {1 },
55- value : 2 ,
60+ env : 2 ,
5661 wantEnabled : false ,
5762 wantActive : true ,
5863 wantValid : & experiments.InvalidValueError {
5964 Name : exampleExperiment ,
6065 AllowedValues : []int {1 },
6166 Value : 2 ,
6267 },
68+ wantValue : 2 ,
69+ },
70+ {
71+ name : `[1, 2] allowed, env="1"` ,
72+ allowedValues : []int {1 , 2 },
73+ env : 1 ,
74+ wantEnabled : true ,
75+ wantActive : true ,
76+ wantValue : 1 ,
77+ },
78+ {
79+ name : `[1, 2] allowed, env="1"` ,
80+ allowedValues : []int {1 , 2 },
81+ env : 2 ,
82+ wantEnabled : true ,
83+ wantActive : true ,
84+ wantValue : 2 ,
85+ },
86+ {
87+ name : `[1] allowed, config="1"` ,
88+ config : & ast.TaskRC {
89+ Experiments : map [string ]int {
90+ exampleExperiment : 1 ,
91+ },
92+ },
93+ allowedValues : []int {1 },
94+ wantEnabled : true ,
95+ wantActive : true ,
96+ wantValue : 1 ,
97+ },
98+ {
99+ name : `[1] allowed, config="2"` ,
100+ config : & ast.TaskRC {
101+ Experiments : map [string ]int {
102+ exampleExperiment : 2 ,
103+ },
104+ },
105+ allowedValues : []int {1 },
106+ wantEnabled : false ,
107+ wantActive : true ,
108+ wantValid : & experiments.InvalidValueError {
109+ Name : exampleExperiment ,
110+ AllowedValues : []int {1 },
111+ Value : 2 ,
112+ },
113+ wantValue : 2 ,
114+ },
115+ {
116+ name : `[1, 2] allowed, env="1", config="2"` ,
117+ config : & ast.TaskRC {
118+ Experiments : map [string ]int {
119+ exampleExperiment : 2 ,
120+ },
121+ },
122+ allowedValues : []int {1 , 2 },
123+ env : 1 ,
124+ wantEnabled : true ,
125+ wantActive : true ,
126+ wantValue : 2 ,
63127 },
64128 }
65129 for _ , tt := range tests {
66130 t .Run (tt .name , func (t * testing.T ) {
67- t .Setenv (exampleExperimentEnv , strconv .Itoa (tt .value ))
68- x := experiments .New (exampleExperiment , tt .allowedValues ... )
131+ t .Setenv (exampleExperimentEnv , strconv .Itoa (tt .env ))
132+ x := experiments .New (exampleExperiment , tt .config , tt . allowedValues ... )
69133 assert .Equal (t , exampleExperiment , x .Name )
70134 assert .Equal (t , tt .wantEnabled , x .Enabled ())
71135 assert .Equal (t , tt .wantActive , x .Active ())
72136 assert .Equal (t , tt .wantValid , x .Valid ())
137+ assert .Equal (t , tt .wantValue , x .Value )
73138 })
74139 }
75140}
0 commit comments