libnetwork: getTestEnv(): use literals for options

Contructing these options was a bit convoluted; let's use literals
for these.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
Sebastiaan van Stijn 2023-07-16 20:13:43 +02:00
parent 534858aaed
commit 9f9d57590b
No known key found for this signature in database
GPG key ID: 76698F39D527CE8C

View file

@ -1,8 +1,8 @@
package libnetwork
import (
"fmt"
"runtime"
"strconv"
"testing"
"github.com/docker/docker/libnetwork/config"
@ -17,17 +17,12 @@ import (
func getTestEnv(t *testing.T, opts ...[]NetworkOption) (*Controller, []Network) {
skip.If(t, runtime.GOOS == "windows", "test only works on linux")
netType := "bridge"
option := options.Generic{
"EnableIPForwarding": true,
}
genericOption := make(map[string]interface{})
genericOption[netlabel.GenericData] = option
const netType = "bridge"
c, err := New(
OptionBoltdbWithRandomDBFile(t),
config.OptionDriverConfig(netType, genericOption),
config.OptionDriverConfig(netType, map[string]any{
netlabel.GenericData: options.Generic{"EnableIPForwarding": true},
}),
)
if err != nil {
t.Fatal(err)
@ -40,14 +35,12 @@ func getTestEnv(t *testing.T, opts ...[]NetworkOption) (*Controller, []Network)
nwList := make([]Network, 0, len(opts))
for i, opt := range opts {
name := fmt.Sprintf("test_nw_%d", i)
netOption := options.Generic{
netlabel.GenericData: options.Generic{
"BridgeName": name,
},
name := "test_nw_" + strconv.Itoa(i)
newOptions := []NetworkOption{
NetworkOptionGeneric(options.Generic{
netlabel.GenericData: options.Generic{"BridgeName": name},
}),
}
newOptions := make([]NetworkOption, 1, len(opt)+1)
newOptions[0] = NetworkOptionGeneric(netOption)
newOptions = append(newOptions, opt...)
n, err := c.NewNetwork(netType, name, "", newOptions...)
if err != nil {