1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

filters: add Clone() method

Signed-off-by: Tibor Vass <tibor@docker.com>
This commit is contained in:
Tibor Vass 2018-11-21 01:19:38 +00:00
parent 68cbc3712c
commit 59eacf28d6
2 changed files with 24 additions and 0 deletions

View file

@ -323,6 +323,22 @@ func (args Args) WalkValues(field string, op func(value string) error) error {
return nil
}
// Clone returns a copy of args.
func (args Args) Clone() (newArgs Args) {
newArgs.fields = make(map[string]map[string]bool, len(args.fields))
for k, m := range args.fields {
var mm map[string]bool
if m != nil {
mm = make(map[string]bool, len(m))
for kk, v := range m {
mm[kk] = v
}
}
newArgs.fields[k] = mm
}
return newArgs
}
func deprecatedArgs(d map[string][]string) map[string]map[string]bool {
m := map[string]map[string]bool{}
for k, v := range d {

View file

@ -421,3 +421,11 @@ func TestFuzzyMatch(t *testing.T) {
}
}
}
func TestClone(t *testing.T) {
f := NewArgs()
f.Add("foo", "bar")
f2 := f.Clone()
f2.Add("baz", "qux")
assert.Check(t, is.Len(f.Get("baz"), 0))
}