-
Notifications
You must be signed in to change notification settings - Fork 9
/
lvm_test.go
60 lines (51 loc) · 1.32 KB
/
lvm_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package disko_test
import (
"encoding/json"
"fmt"
"strings"
"testing"
"machinerun.io/disko"
)
var valid = map[string]disko.LVType{
"THICK": disko.THICK,
"THIN": disko.THIN,
"THINPOOL": disko.THINPOOL,
}
func TestLVTypeString(t *testing.T) {
for asStr, ltype := range valid {
found := ltype.String()
if found != asStr {
t.Errorf("disko.LVType(%d).String() found %s, expected %s",
ltype, found, asStr)
}
}
}
func TestLVTypeJsonSerialize(t *testing.T) {
for asStr, ltype := range valid {
ltype := ltype
jbytes, err := json.Marshal(<ype)
if err != nil {
t.Errorf("Failed to marshal %#v: %s", ltype, err)
continue
}
jstr := string(jbytes)
if !strings.Contains(jstr, asStr) {
t.Errorf("Did not find string ID '%s' in json: %s", asStr, jstr)
}
}
}
func TestLVTypeJsonUnSerialize(t *testing.T) {
var found disko.LVType
for asStr, ltype := range valid {
// "4" (no quotes) is valid json rep of int 4. "string" is rep of string.
validJsons := []string{fmt.Sprintf("%d", ltype), "\"" + asStr + "\""}
for _, jsonBlob := range validJsons {
err := json.Unmarshal([]byte(jsonBlob), &found)
if err != nil {
t.Errorf("Failed to unmarshal %s: %s", jsonBlob, err)
} else if found != ltype {
t.Errorf("Unserialized %s, got %d, expected %d", jsonBlob, found, ltype)
}
}
}
}