daemon: inline filters in tests

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
Sebastiaan van Stijn 2023-04-25 15:13:26 +02:00
parent 081b5e3d4e
commit 5bc0832766
No known key found for this signature in database
GPG key ID: 76698F39D527CE8C
3 changed files with 42 additions and 83 deletions

View file

@ -7,26 +7,23 @@ import (
)
func TestNewListSecretsFilters(t *testing.T) {
validNameFilter := filters.NewArgs()
validNameFilter.Add("name", "test_name")
validNameFilter := filters.NewArgs(filters.Arg("name", "test_name"))
validIDFilter := filters.NewArgs(filters.Arg("id", "7c9009d6720f6de3b492f5"))
validIDFilter := filters.NewArgs()
validIDFilter.Add("id", "7c9009d6720f6de3b492f5")
validLabelFilter := filters.NewArgs(
filters.Arg("label", "type=test"),
filters.Arg("label", "storage=ssd"),
filters.Arg("label", "memory"),
)
validNamesFilter := filters.NewArgs(filters.Arg("names", "test_name"))
validLabelFilter := filters.NewArgs()
validLabelFilter.Add("label", "type=test")
validLabelFilter.Add("label", "storage=ssd")
validLabelFilter.Add("label", "memory")
validNamesFilter := filters.NewArgs()
validNamesFilter.Add("names", "test_name")
validAllFilter := filters.NewArgs()
validAllFilter.Add("name", "nodeName")
validAllFilter.Add("id", "7c9009d6720f6de3b492f5")
validAllFilter.Add("label", "type=test")
validAllFilter.Add("label", "memory")
validAllFilter.Add("names", "test_name")
validAllFilter := filters.NewArgs(
filters.Arg("name", "nodeName"),
filters.Arg("id", "7c9009d6720f6de3b492f5"),
filters.Arg("label", "type=test"),
filters.Arg("label", "memory"),
filters.Arg("names", "test_name"),
)
validFilters := []filters.Args{
validNameFilter,
@ -36,8 +33,7 @@ func TestNewListSecretsFilters(t *testing.T) {
validAllFilter,
}
invalidTypeFilter := filters.NewArgs()
invalidTypeFilter.Add("nonexist", "aaaa")
invalidTypeFilter := filters.NewArgs(filters.Arg("nonexist", "aaaa"))
invalidFilters := []filters.Args{
invalidTypeFilter,
@ -57,22 +53,21 @@ func TestNewListSecretsFilters(t *testing.T) {
}
func TestNewListConfigsFilters(t *testing.T) {
validNameFilter := filters.NewArgs()
validNameFilter.Add("name", "test_name")
validNameFilter := filters.NewArgs(filters.Arg("name", "test_name"))
validIDFilter := filters.NewArgs(filters.Arg("id", "7c9009d6720f6de3b492f5"))
validIDFilter := filters.NewArgs()
validIDFilter.Add("id", "7c9009d6720f6de3b492f5")
validLabelFilter := filters.NewArgs(
filters.Arg("label", "type=test"),
filters.Arg("label", "storage=ssd"),
filters.Arg("label", "memory"),
)
validLabelFilter := filters.NewArgs()
validLabelFilter.Add("label", "type=test")
validLabelFilter.Add("label", "storage=ssd")
validLabelFilter.Add("label", "memory")
validAllFilter := filters.NewArgs()
validAllFilter.Add("name", "nodeName")
validAllFilter.Add("id", "7c9009d6720f6de3b492f5")
validAllFilter.Add("label", "type=test")
validAllFilter.Add("label", "memory")
validAllFilter := filters.NewArgs(
filters.Arg("name", "nodeName"),
filters.Arg("id", "7c9009d6720f6de3b492f5"),
filters.Arg("label", "type=test"),
filters.Arg("label", "memory"),
)
validFilters := []filters.Args{
validNameFilter,
@ -81,8 +76,7 @@ func TestNewListConfigsFilters(t *testing.T) {
validAllFilter,
}
invalidTypeFilter := filters.NewArgs()
invalidTypeFilter.Add("nonexist", "aaaa")
invalidTypeFilter := filters.NewArgs(filters.Arg("nonexist", "aaaa"))
invalidFilters := []filters.Args{
invalidTypeFilter,

View file

@ -87,10 +87,8 @@ func TestListInvalidFilter(t *testing.T) {
containersReplica: db,
}
f := filters.NewArgs(filters.Arg("invalid", "foo"))
_, err = d.Containers(context.Background(), &types.ContainerListOptions{
Filters: f,
Filters: filters.NewArgs(filters.Arg("invalid", "foo")),
})
assert.Assert(t, is.Error(err, "invalid filter 'invalid'"))
}

View file

@ -55,39 +55,6 @@ func TestFilterNetworks(t *testing.T) {
},
}
bridgeDriverFilters := filters.NewArgs()
bridgeDriverFilters.Add("driver", "bridge")
overlayDriverFilters := filters.NewArgs()
overlayDriverFilters.Add("driver", "overlay")
nonameDriverFilters := filters.NewArgs()
nonameDriverFilters.Add("driver", "noname")
customDriverFilters := filters.NewArgs()
customDriverFilters.Add("type", "custom")
builtinDriverFilters := filters.NewArgs()
builtinDriverFilters.Add("type", "builtin")
invalidDriverFilters := filters.NewArgs()
invalidDriverFilters.Add("type", "invalid")
localScopeFilters := filters.NewArgs()
localScopeFilters.Add("scope", "local")
swarmScopeFilters := filters.NewArgs()
swarmScopeFilters.Add("scope", "swarm")
globalScopeFilters := filters.NewArgs()
globalScopeFilters.Add("scope", "global")
trueDanglingFilters := filters.NewArgs()
trueDanglingFilters.Add("dangling", "true")
falseDanglingFilters := filters.NewArgs()
falseDanglingFilters.Add("dangling", "false")
testCases := []struct {
filter filters.Args
resultCount int
@ -96,68 +63,68 @@ func TestFilterNetworks(t *testing.T) {
results []string
}{
{
filter: bridgeDriverFilters,
filter: filters.NewArgs(filters.Arg("driver", "bridge")),
resultCount: 1,
err: "",
name: "bridge driver filters",
},
{
filter: overlayDriverFilters,
filter: filters.NewArgs(filters.Arg("driver", "overlay")),
resultCount: 1,
err: "",
name: "overlay driver filters",
},
{
filter: nonameDriverFilters,
filter: filters.NewArgs(filters.Arg("driver", "noname")),
resultCount: 0,
err: "",
name: "no name driver filters",
},
{
filter: customDriverFilters,
filter: filters.NewArgs(filters.Arg("type", "custom")),
resultCount: 4,
err: "",
name: "custom driver filters",
},
{
filter: builtinDriverFilters,
filter: filters.NewArgs(filters.Arg("type", "builtin")),
resultCount: 3,
err: "",
name: "builtin driver filters",
},
{
filter: invalidDriverFilters,
filter: filters.NewArgs(filters.Arg("type", "invalid")),
resultCount: 0,
err: "invalid filter: 'type'='invalid'",
name: "invalid driver filters",
},
{
filter: localScopeFilters,
filter: filters.NewArgs(filters.Arg("scope", "local")),
resultCount: 5,
err: "",
name: "local scope filters",
},
{
filter: swarmScopeFilters,
filter: filters.NewArgs(filters.Arg("scope", "swarm")),
resultCount: 1,
err: "",
name: "swarm scope filters",
},
{
filter: globalScopeFilters,
filter: filters.NewArgs(filters.Arg("scope", "global")),
resultCount: 1,
err: "",
name: "global scope filters",
},
{
filter: trueDanglingFilters,
filter: filters.NewArgs(filters.Arg("dangling", "true")),
resultCount: 3,
err: "",
name: "dangling filter is 'True'",
results: []string{"myoverlay", "mydrivernet", "mykvnet"},
},
{
filter: falseDanglingFilters,
filter: filters.NewArgs(filters.Arg("dangling", "false")),
resultCount: 4,
err: "",
name: "dangling filter is 'False'",