@@ -20,6 +20,7 @@ import (
20
20
"testing"
21
21
"time"
22
22
23
+ sConfig "github.com/GoogleContainerTools/skaffold/pkg/skaffold/config"
23
24
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/util"
24
25
"github.com/GoogleContainerTools/skaffold/testutil"
25
26
)
@@ -69,21 +70,20 @@ func TestSurveyActive(t *testing.T) {
69
70
description : "expiry in past" ,
70
71
s : config {
71
72
id : "expired" ,
72
- expiresAt : time .Date (2020 , time . August , 14 , 00 , 00 , 00 , 0 , time .UTC ),
73
+ expiresAt : time .Date (2020 , 8 , 1 , 0 , 0 , 0 , 0 , time .UTC ),
73
74
},
74
75
},
75
76
{
76
77
description : "expiry in future" ,
77
78
s : config {
78
79
id : "active" ,
79
- expiresAt : time .Date ( 2022 , time . August , 14 , 00 , 00 , 00 , 0 , time . UTC ),
80
+ expiresAt : time .Now (). AddDate ( 1 , 0 , 0 ),
80
81
},
81
82
expected : true ,
82
83
},
83
84
}
84
85
for _ , test := range tests {
85
86
testutil .Run (t , test .description , func (t * testutil.T ) {
86
- t .Override (& today , time .Date (2021 , time .August , 14 , 0 , 0 , 0 , 0 , time .UTC ))
87
87
t .CheckDeepEqual (test .s .isActive (), test .expected )
88
88
})
89
89
}
@@ -108,7 +108,7 @@ func TestSurveyRelevant(t *testing.T) {
108
108
description : "relevant based on input configs" ,
109
109
s : config {
110
110
id : "foo" ,
111
- isRelevantFn : func (cfgs []util.VersionedConfig ) bool {
111
+ isRelevantFn : func (cfgs []util.VersionedConfig , _ sConfig. RunMode ) bool {
112
112
return len (cfgs ) > 1
113
113
},
114
114
},
@@ -119,7 +119,7 @@ func TestSurveyRelevant(t *testing.T) {
119
119
description : "not relevant based on config" ,
120
120
s : config {
121
121
id : "foo" ,
122
- isRelevantFn : func (cfgs []util.VersionedConfig ) bool {
122
+ isRelevantFn : func (cfgs []util.VersionedConfig , _ sConfig. RunMode ) bool {
123
123
return len (cfgs ) > 1
124
124
},
125
125
},
@@ -129,7 +129,7 @@ func TestSurveyRelevant(t *testing.T) {
129
129
description : "contains a config with test version" ,
130
130
s : config {
131
131
id : "version-value-test" ,
132
- isRelevantFn : func (cfgs []util.VersionedConfig ) bool {
132
+ isRelevantFn : func (cfgs []util.VersionedConfig , _ sConfig. RunMode ) bool {
133
133
for _ , cfg := range cfgs {
134
134
if m , ok := cfg .(mockVersionedConfig ); ok {
135
135
if m .version == "test" {
@@ -147,7 +147,7 @@ func TestSurveyRelevant(t *testing.T) {
147
147
description : "does not contains a config with test version" ,
148
148
s : config {
149
149
id : "version-value-test" ,
150
- isRelevantFn : func (cfgs []util.VersionedConfig ) bool {
150
+ isRelevantFn : func (cfgs []util.VersionedConfig , _ sConfig. RunMode ) bool {
151
151
for _ , cfg := range cfgs {
152
152
if m , ok := cfg .(mockVersionedConfig ); ok {
153
153
if m .version == "test" {
@@ -163,7 +163,58 @@ func TestSurveyRelevant(t *testing.T) {
163
163
}
164
164
for _ , test := range tests {
165
165
testutil .Run (t , test .description , func (t * testutil.T ) {
166
- t .CheckDeepEqual (test .s .isRelevant (test .cfgs ), test .expected )
166
+ t .CheckDeepEqual (test .s .isRelevant (test .cfgs , "dev" ), test .expected )
167
+ })
168
+ }
169
+ }
170
+
171
+ func TestIsValid (t * testing.T ) {
172
+ tests := []struct {
173
+ description string
174
+ s config
175
+ expected bool
176
+ }{
177
+ {
178
+ description : "only hats" ,
179
+ s : hats ,
180
+ expected : true ,
181
+ },
182
+ {
183
+ description : "4 weeks valid survey with start date" ,
184
+ s : config {
185
+ id : "invalid" ,
186
+ startsAt : time .Now ().AddDate (0 , 1 , 0 ),
187
+ expiresAt : time .Now ().AddDate (0 , 2 , 0 ),
188
+ },
189
+ expected : true ,
190
+ },
191
+ {
192
+ description : "4 weeks valid survey without start date" ,
193
+ s : config {
194
+ id : "valid" ,
195
+ expiresAt : time .Now ().AddDate (0 , 1 , 0 ),
196
+ },
197
+ expected : true ,
198
+ },
199
+ {
200
+ description : "90 days invalid survey without start date" ,
201
+ s : config {
202
+ id : "invalid" ,
203
+ expiresAt : time .Now ().AddDate (0 , 0 , 90 ),
204
+ },
205
+ },
206
+ {
207
+ description : "90 days invalid survey with start date" ,
208
+ s : config {
209
+ id : "invalid" ,
210
+ startsAt : time .Now ().AddDate (0 , 1 , 0 ),
211
+ expiresAt : time .Now ().AddDate (0 , 1 , 90 ),
212
+ },
213
+ },
214
+ }
215
+ for _ , test := range tests {
216
+ testutil .Run (t , test .description , func (t * testutil.T ) {
217
+ t .CheckDeepEqual (test .s .isValid (), test .expected )
167
218
})
168
219
}
169
220
}
0 commit comments