1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00
moby--moby/daemon/config/builder_test.go
Tibor Vass fbdd437d29 daemon/config: fix filter type in BuildKit GC config
For backwards compatibility, the old incorrect object format for
builder.GC.Rule.Filter still works but is deprecated in favor of array of
strings akin to what needs to be passed on the CLI.

Signed-off-by: Tibor Vass <tibor@docker.com>
2019-10-03 00:09:58 +00:00

44 lines
1.4 KiB
Go

package config
import (
"testing"
"github.com/docker/docker/api/types/filters"
"github.com/google/go-cmp/cmp"
"gotest.tools/assert"
"gotest.tools/fs"
)
func TestBuilderGC(t *testing.T) {
tempFile := fs.NewFile(t, "config", fs.WithContent(`{
"builder": {
"gc": {
"enabled": true,
"policy": [
{"keepStorage": "10GB", "filter": ["unused-for=2200h"]},
{"keepStorage": "50GB", "filter": {"unused-for": {"3300h": true}}},
{"keepStorage": "100GB", "all": true}
]
}
}
}`))
defer tempFile.Remove()
configFile := tempFile.Path()
cfg, err := MergeDaemonConfigurations(&Config{}, nil, configFile)
assert.NilError(t, err)
assert.Assert(t, cfg.Builder.GC.Enabled)
f1 := filters.NewArgs()
f1.Add("unused-for", "2200h")
f2 := filters.NewArgs()
f2.Add("unused-for", "3300h")
expectedPolicy := []BuilderGCRule{
{KeepStorage: "10GB", Filter: BuilderGCFilter(f1)},
{KeepStorage: "50GB", Filter: BuilderGCFilter(f2)}, /* parsed from deprecated form */
{KeepStorage: "100GB", All: true},
}
assert.DeepEqual(t, cfg.Builder.GC.Policy, expectedPolicy, cmp.AllowUnexported(BuilderGCFilter{}))
// double check to please the skeptics
assert.Assert(t, filters.Args(cfg.Builder.GC.Policy[0].Filter).UniqueExactMatch("unused-for", "2200h"))
assert.Assert(t, filters.Args(cfg.Builder.GC.Policy[1].Filter).UniqueExactMatch("unused-for", "3300h"))
}