Skip to content

Commit d4518bc

Browse files
committed
add test for cloudinit
1 parent 215052e commit d4518bc

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

cloud/cloudinit/common_test.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package cloudinit_test
2+
3+
import (
4+
"testing"
5+
6+
"github.com/sp-yduck/cluster-api-provider-proxmox/cloud/cloudinit"
7+
)
8+
9+
func TestIsValidType(t *testing.T) {
10+
testTypes := []string{"user", "users", "meta", "memetah", "network", "networkig"}
11+
expectedValidity := []bool{true, false, true, false, true, false}
12+
for i, tt := range testTypes {
13+
if cloudinit.IsValidType(tt) != expectedValidity[i] {
14+
t.Errorf("expected validity for %s is %v", tt, expectedValidity[i])
15+
}
16+
}
17+
}

cloud/cloudinit/user_test.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
package cloudinit_test
22

33
import (
4+
"reflect"
45
"testing"
56

7+
infrav1 "github.com/sp-yduck/cluster-api-provider-proxmox/api/v1beta1"
68
"github.com/sp-yduck/cluster-api-provider-proxmox/cloud/cloudinit"
79
)
810

@@ -51,3 +53,25 @@ runcmd:
5153
t.Fatalf("generate : %v", err)
5254
}
5355
}
56+
57+
func TestMergeUsers(t *testing.T) {
58+
a := infrav1.User{
59+
User: "override-user",
60+
RunCmd: []string{"command A", "command B"},
61+
}
62+
b := infrav1.User{
63+
User: "test-user",
64+
RunCmd: []string{"command C"},
65+
}
66+
expected := infrav1.User{
67+
User: "override-user",
68+
RunCmd: []string{"command A", "command B", "command C"},
69+
}
70+
c, err := cloudinit.MergeUsers(a, b)
71+
if err != nil {
72+
t.Errorf("failed to merge cloud init user data: %v", err)
73+
}
74+
if !reflect.DeepEqual(*c, expected) {
75+
t.Errorf("%v is expected to same as %v", *c, expected)
76+
}
77+
}

0 commit comments

Comments
 (0)