forked from bicomsystems/go-libzfs
-
Notifications
You must be signed in to change notification settings - Fork 1
/
types_test.go
executable file
·66 lines (63 loc) · 1.46 KB
/
types_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
61
62
63
64
65
66
package zfs
import(
"testing"
"encoding/json"
)
func TestProperties(t *testing.T) {
t.Run("convert to json", func(t *testing.T) {
var props = make(DatasetProperties)
props[DatasetPropName] = PropertyValue{
Value: "abc",
Source: "-",
}
props[DatasetPropWritten] = PropertyValue{
Value: "234234",
}
t.Log(props)
data, err := json.Marshal(props)
if err != nil {
t.Fatal(err)
}
t.Log(string(data))
})
t.Run("parse from json", func(t *testing.T) {
data := []byte(`{"name":{"value":"abc","source":"-"},"written":{"value":"234234","source":""}}`)
var props = make(DatasetProperties)
err := json.Unmarshal(data, &props)
if err != nil {
t.Fatal(err)
}
t.Log(props)
if props[DatasetPropName].Value != "abc" {
t.Error("wrong DatasetPropName")
}
})
t.Run("parse from json, emit a \"source\" field", func(t *testing.T) {
data := []byte(`{"name":{"value":"abc","source":"-"},"written":{"value":"234234"}}`)
var props = make(DatasetProperties)
err := json.Unmarshal(data, &props)
if err != nil {
t.Fatal(err)
}
t.Log(props)
})
}
func TestDataTypeProp(t *testing.T) {
t.Run("marshal", func(t *testing.T){
var p DatasetProp = DatasetPropSnapshotCount
data, err := json.Marshal(&p)
if err != nil {
t.Fatal(err)
}
t.Log(string(data))
})
t.Run("unmarshal", func(t *testing.T){
data := []byte(`"snapshot_count"`)
var p DatasetProp
err := json.Unmarshal(data, &p)
if err != nil {
t.Fatal(err)
}
t.Log(p)
})
}