6
6
"strings"
7
7
"testing"
8
8
9
+ "github.com/stretchr/testify/assert"
9
10
"github.com/sunggun-yu/envp/internal/config"
10
- "gopkg.in/yaml.v2 "
11
+ "gopkg.in/yaml.v3 "
11
12
)
12
13
13
14
var (
@@ -86,6 +87,11 @@ func TestProfileNames(t *testing.T) {
86
87
"org.nprod.vpn.vpn1" ,
87
88
"org.nprod.vpn.vpn2" ,
88
89
"parent-has-env" ,
90
+ "profile-with-init-script" ,
91
+ "profile-with-multi-init-script" ,
92
+ "profile-with-multi-init-script-but-no-run" ,
93
+ "profile-with-no-init-script" ,
94
+ "profile-with-single-init-script-but-array" ,
89
95
}
90
96
91
97
actual := profiles .ProfileNames ()
@@ -111,8 +117,8 @@ func TestFindParentProfile(t *testing.T) {
111
117
testCaseNormal ("lab.cluster1" , "lab" )
112
118
})
113
119
114
- t .Run ("find exisiting parent of non-existing child profile" , func (t * testing.T ) {
115
- // should return parent even child is not exisiting
120
+ t .Run ("find existing parent of non-existing child profile" , func (t * testing.T ) {
121
+ // should return parent even child is not existing
116
122
testCaseNormal ("lab.cluster-not-existing-in-config" , "lab" )
117
123
})
118
124
@@ -123,7 +129,7 @@ func TestFindParentProfile(t *testing.T) {
123
129
}
124
130
})
125
131
126
- t .Run ("find non-exisiting parent of non-existing child profile" , func (t * testing.T ) {
132
+ t .Run ("find non-existing parent of non-existing child profile" , func (t * testing.T ) {
127
133
// should return nil for non existing profile
128
134
if p , err := profiles .FindParentProfile ("non-existing-parent.non-existing-child" ); p != nil && err == nil {
129
135
t .Error ("supposed to be nil and err" )
@@ -181,7 +187,7 @@ func TestDeleteProfile(t *testing.T) {
181
187
testCase ("org.nprod.argocd.argo2" )
182
188
})
183
189
184
- t .Run ("delete non-exisiting nested profile" , func (t * testing.T ) {
190
+ t .Run ("delete non-existing nested profile" , func (t * testing.T ) {
185
191
testCaseNonExistingProfile ("non-existing-parent.non-existing-child" )
186
192
})
187
193
}
@@ -267,3 +273,49 @@ func TestSetProfile(t *testing.T) {
267
273
}
268
274
})
269
275
}
276
+
277
+ func TestProfileInitScript (t * testing.T ) {
278
+
279
+ cfg := testDataConfig
280
+ profile := cfg ().Profiles
281
+
282
+ t .Run ("profile with no init-script" , func (t * testing.T ) {
283
+ p , err := profile .FindProfile ("profile-with-no-init-script" )
284
+ assert .NoError (t , err , "error should not occurred" )
285
+ assert .NotEmpty (t , p , "profile is found" )
286
+ expect := 0
287
+ assert .Len (t , p .InitScripts (), expect , fmt .Sprintf ("should be %v init-script" , expect ))
288
+ })
289
+
290
+ t .Run ("profile with single init-script" , func (t * testing.T ) {
291
+ p , err := profile .FindProfile ("profile-with-init-script" )
292
+ assert .NoError (t , err , "error should not occurred" )
293
+ assert .NotEmpty (t , p , "profile is found" )
294
+ expect := 1
295
+ assert .Len (t , p .InitScripts (), expect , fmt .Sprintf ("should be %v init-script" , expect ))
296
+ })
297
+
298
+ t .Run ("profile with single init-script but array type" , func (t * testing.T ) {
299
+ p , err := profile .FindProfile ("profile-with-single-init-script-but-array" )
300
+ assert .NoError (t , err , "error should not occurred" )
301
+ assert .NotEmpty (t , p , "profile is found" )
302
+ expect := 1
303
+ assert .Len (t , p .InitScripts (), expect , fmt .Sprintf ("should be %v init-script" , expect ))
304
+ })
305
+
306
+ t .Run ("profile with multiple init-script" , func (t * testing.T ) {
307
+ p , err := profile .FindProfile ("profile-with-multi-init-script" )
308
+ assert .NoError (t , err , "error should not occurred" )
309
+ assert .NotEmpty (t , p , "profile is found" )
310
+ expect := 2
311
+ assert .Len (t , p .InitScripts (), expect , fmt .Sprintf ("should be %v init-script" , expect ))
312
+ })
313
+
314
+ t .Run ("profile with multiple init-script but has no map of run keyword" , func (t * testing.T ) {
315
+ p , err := profile .FindProfile ("profile-with-multi-init-script-but-no-run" )
316
+ assert .NoError (t , err , "error should not occurred" )
317
+ assert .NotEmpty (t , p , "profile is found" )
318
+ expect := 0
319
+ assert .Len (t , p .InitScripts (), expect , fmt .Sprintf ("should be %v init-script" , expect ))
320
+ })
321
+ }
0 commit comments