File tree 1 file changed +50
-0
lines changed
1 file changed +50
-0
lines changed Original file line number Diff line number Diff line change
1
+ /*
2
+ Copyright © 2021 VMware, Inc. All Rights Reserved.
3
+ SPDX-License-Identifier: MPL-2.0
4
+ */
5
+
6
+ package helper
7
+
8
+ import (
9
+ "testing"
10
+
11
+ "github.com/stretchr/testify/require"
12
+ )
13
+
14
+ func TestGetFirstElementOf (t * testing.T ) {
15
+ t .Parallel ()
16
+
17
+ cases := []struct {
18
+ name string
19
+ parent string
20
+ children []string
21
+ expected string
22
+ }{
23
+ {
24
+ name : "case for no children" ,
25
+ parent : "p1" ,
26
+ children : []string {},
27
+ expected : "p1" ,
28
+ },
29
+ {
30
+ name : "case when parent has one child" ,
31
+ parent : "p2" ,
32
+ children : []string {"c1" },
33
+ expected : "p2.0.c1" ,
34
+ },
35
+ {
36
+ name : "case when parent has more than one child" ,
37
+ parent : "p3" ,
38
+ children : []string {"c2" , "c3" , "c4" },
39
+ expected : "p3.0.c2.0.c3.0.c4" ,
40
+ },
41
+ }
42
+
43
+ for _ , each := range cases {
44
+ test := each
45
+ t .Run (test .name , func (t * testing.T ) {
46
+ actual := GetFirstElementOf (test .parent , test .children ... )
47
+ require .Equal (t , test .expected , actual )
48
+ })
49
+ }
50
+ }
You can’t perform that action at this time.
0 commit comments