-
Notifications
You must be signed in to change notification settings - Fork 0
/
filesetFiltersSerial_test.go
132 lines (127 loc) · 4.99 KB
/
filesetFiltersSerial_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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
package api
import (
"bytes"
"testing"
"github.com/polydawn/refmt"
"github.com/polydawn/refmt/json"
"github.com/polydawn/refmt/obj/atlas"
. "github.com/warpfork/go-wish"
)
func TestFilesetFilterSerialization(t *testing.T) {
t.Run("pack filters", func(t *testing.T) {
shouldRtPack := func(t *testing.T, atl atlas.Atlas, obj FilesetPackFilter, canon string) {
t.Helper()
t.Run("marshal", func(t *testing.T) {
bs, err := refmt.MarshalAtlased(json.EncodeOptions{}, obj, atl)
Wish(t, err, ShouldEqual, nil)
Wish(t, string(bs), ShouldEqual, canon)
})
t.Run("unmarshal", func(t *testing.T) {
targ := FilesetPackFilter{}
err := refmt.UnmarshalAtlased(json.DecodeOptions{}, bytes.NewBufferString(canon).Bytes(), &targ, atl)
Wish(t, err, ShouldEqual, nil)
Wish(t, targ, ShouldEqual, obj)
})
}
t.Run("string", func(t *testing.T) {
atl := atlas.MustBuild(FilesetPackFilter_AsString_AtlasEntry)
shouldRtPack := func(t *testing.T, obj FilesetPackFilter, canon string) {
shouldRtPack(t, atl, obj, canon)
}
t.Run("pack lossless should roundtrip", func(t *testing.T) {
shouldRtPack(t,
FilesetPackFilter_Lossless,
`"uid=keep,gid=keep,mtime=keep,sticky=keep,setid=keep,dev=keep"`)
})
t.Run("pack flatten should roundtrip", func(t *testing.T) {
shouldRtPack(t,
FilesetPackFilter_Flatten,
`"uid=1000,gid=1000,mtime=@1262304000,sticky=keep,setid=keep,dev=keep"`)
})
t.Run("pack partial specifications should roundtrip", func(t *testing.T) {
shouldRtPack(t,
FilesetPackFilter{true, ff_unspecified, 1000, ff_unspecified, ff_ignore, ff_unspecified, ff_unspecified},
`"gid=1000,sticky=ignore"`)
})
})
t.Run("obj", func(t *testing.T) {
atl := atlas.MustBuild(FilesetPackFilter_AtlasEntry)
shouldRtPack := func(t *testing.T, obj FilesetPackFilter, canon string) {
shouldRtPack(t, atl, obj, canon)
}
t.Run("pack lossless should roundtrip", func(t *testing.T) {
shouldRtPack(t,
FilesetPackFilter_Lossless,
`{"dev":"keep","gid":"keep","mtime":"keep","setid":"keep","sticky":"keep","uid":"keep"}`)
})
t.Run("pack flatten should roundtrip", func(t *testing.T) {
shouldRtPack(t,
FilesetPackFilter_Flatten,
`{"dev":"keep","gid":"1000","mtime":"@1262304000","setid":"keep","sticky":"keep","uid":"1000"}`)
})
t.Run("pack partial specifications should roundtrip", func(t *testing.T) {
shouldRtPack(t,
FilesetPackFilter{true, ff_unspecified, 1000, ff_unspecified, ff_ignore, ff_unspecified, ff_unspecified},
`{"gid":"1000","sticky":"ignore"}`)
})
})
})
t.Run("unpack filters", func(t *testing.T) {
shouldRtUnpack := func(t *testing.T, atl atlas.Atlas, obj FilesetUnpackFilter, canon string) {
t.Helper()
t.Run("marshal", func(t *testing.T) {
bs, err := refmt.MarshalAtlased(json.EncodeOptions{}, obj, atl)
Wish(t, err, ShouldEqual, nil)
Wish(t, string(bs), ShouldEqual, canon)
})
t.Run("unmarshal", func(t *testing.T) {
targ := FilesetUnpackFilter{}
err := refmt.UnmarshalAtlased(json.DecodeOptions{}, bytes.NewBufferString(canon).Bytes(), &targ, atl)
Wish(t, err, ShouldEqual, nil)
Wish(t, targ, ShouldEqual, obj)
})
}
t.Run("string", func(t *testing.T) {
atl := atlas.MustBuild(FilesetUnpackFilter_AsString_AtlasEntry)
shouldRtUnpack := func(t *testing.T, obj FilesetUnpackFilter, canon string) {
shouldRtUnpack(t, atl, obj, canon)
}
t.Run("unpack lossless should roundtrip", func(t *testing.T) {
shouldRtUnpack(t,
FilesetUnpackFilter_Lossless,
`"uid=follow,gid=follow,mtime=follow,sticky=follow,setid=follow,dev=follow"`)
})
t.Run("unpack lowpriv should roundtrip", func(t *testing.T) {
shouldRtUnpack(t,
FilesetUnpackFilter_LowPriv,
`"uid=mine,gid=mine,mtime=follow,sticky=follow,setid=reject,dev=reject"`)
})
t.Run("unpack partial specifications should roundtrip", func(t *testing.T) {
shouldRtUnpack(t,
FilesetUnpackFilter{true, ff_unspecified, 1000, ff_unspecified, ff_ignore, ff_unspecified, ff_unspecified},
`"gid=1000,sticky=ignore"`)
})
})
t.Run("obj", func(t *testing.T) {
atl := atlas.MustBuild(FilesetUnpackFilter_AtlasEntry)
shouldRtUnpack := func(t *testing.T, obj FilesetUnpackFilter, canon string) {
shouldRtUnpack(t, atl, obj, canon)
}
t.Run("unpack lossless should roundtrip", func(t *testing.T) {
shouldRtUnpack(t,
FilesetUnpackFilter_Lossless,
`{"dev":"follow","gid":"follow","mtime":"follow","setid":"follow","sticky":"follow","uid":"follow"}`)
})
t.Run("unpack lowpriv should roundtrip", func(t *testing.T) {
shouldRtUnpack(t,
FilesetUnpackFilter_LowPriv,
`{"dev":"reject","gid":"mine","mtime":"follow","setid":"reject","sticky":"follow","uid":"mine"}`)
})
t.Run("unpack partial specifications should roundtrip", func(t *testing.T) {
shouldRtUnpack(t,
FilesetUnpackFilter{true, ff_unspecified, 1000, ff_unspecified, ff_ignore, ff_unspecified, ff_unspecified},
`{"gid":"1000","sticky":"ignore"}`)
})
})
})
}