github.com/docker/docker@v299999999.0.0-20200612211812-aaf470eca7b5+incompatible/daemon/config/builder_test.go (about)

     1  package config
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/docker/docker/api/types/filters"
     7  	"github.com/google/go-cmp/cmp"
     8  	"gotest.tools/v3/assert"
     9  	"gotest.tools/v3/fs"
    10  )
    11  
    12  func TestBuilderGC(t *testing.T) {
    13  	tempFile := fs.NewFile(t, "config", fs.WithContent(`{
    14    "builder": {
    15      "gc": {
    16        "enabled": true,
    17        "policy": [
    18          {"keepStorage": "10GB", "filter": ["unused-for=2200h"]},
    19          {"keepStorage": "50GB", "filter": {"unused-for": {"3300h": true}}},
    20          {"keepStorage": "100GB", "all": true}
    21        ]
    22      }
    23    }
    24  }`))
    25  	defer tempFile.Remove()
    26  	configFile := tempFile.Path()
    27  
    28  	cfg, err := MergeDaemonConfigurations(&Config{}, nil, configFile)
    29  	assert.NilError(t, err)
    30  	assert.Assert(t, cfg.Builder.GC.Enabled)
    31  	f1 := filters.NewArgs()
    32  	f1.Add("unused-for", "2200h")
    33  	f2 := filters.NewArgs()
    34  	f2.Add("unused-for", "3300h")
    35  	expectedPolicy := []BuilderGCRule{
    36  		{KeepStorage: "10GB", Filter: BuilderGCFilter(f1)},
    37  		{KeepStorage: "50GB", Filter: BuilderGCFilter(f2)}, /* parsed from deprecated form */
    38  		{KeepStorage: "100GB", All: true},
    39  	}
    40  	assert.DeepEqual(t, cfg.Builder.GC.Policy, expectedPolicy, cmp.AllowUnexported(BuilderGCFilter{}))
    41  	// double check to please the skeptics
    42  	assert.Assert(t, filters.Args(cfg.Builder.GC.Policy[0].Filter).UniqueExactMatch("unused-for", "2200h"))
    43  	assert.Assert(t, filters.Args(cfg.Builder.GC.Policy[1].Filter).UniqueExactMatch("unused-for", "3300h"))
    44  }