Skip to content

Commit 3f34852

Browse files
committed
add tests for cloudinit,providerid
1 parent 133d3b2 commit 3f34852

File tree

4 files changed

+53
-28
lines changed

4 files changed

+53
-28
lines changed

cloud/cloudinit/common.go

Lines changed: 0 additions & 10 deletions
This file was deleted.

cloud/cloudinit/common_test.go

Lines changed: 0 additions & 17 deletions
This file was deleted.

cloud/cloudinit/user_test.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,20 @@ runcmd:
2424
`
2525
_, err := cloudinit.ParseUser(testYaml)
2626
if err != nil {
27-
t.Fatalf("failed to parse user: %v", err)
27+
t.Errorf("failed to parse user: %v", err)
28+
}
29+
30+
testYaml = `
31+
write_files:
32+
- path: /run/kubeadm/kubeadm.yaml
33+
owner: root:root
34+
permissions: '0640'
35+
content: |
36+
asdfasdfasdf
37+
`
38+
user, err := cloudinit.ParseUser(testYaml)
39+
if err == nil {
40+
t.Errorf("should returns an error. user=%v", *user)
2841
}
2942
}
3043

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package providerid
2+
3+
import (
4+
"testing"
5+
)
6+
7+
func TestNew(t *testing.T) {
8+
uuid := ""
9+
providerID, err := New(uuid)
10+
if err == nil {
11+
t.Errorf("err should not be nil. providerID=%s", providerID)
12+
}
13+
14+
uuid = "asdf"
15+
providerID, err = New(uuid)
16+
if err != nil {
17+
t.Errorf("failed to create providerID: %v", err)
18+
}
19+
}
20+
21+
func TestUUID(t *testing.T) {
22+
pid := providerID{
23+
uuid: "asdf",
24+
}
25+
uuid := pid.UUID()
26+
if uuid != "asdf" {
27+
t.Errorf("should be asdf")
28+
}
29+
}
30+
31+
func TestString(t *testing.T) {
32+
pid := providerID{
33+
uuid: "asdf",
34+
}
35+
uuid := pid.String()
36+
if uuid != Prefix+"asdf" {
37+
t.Errorf("should be %sasdf", Prefix)
38+
}
39+
}

0 commit comments

Comments
 (0)