소스 검색

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>
Sebastiaan van Stijn 1 년 전
부모
커밋
9f9d57590b
1개의 변경된 파일10개의 추가작업 그리고 17개의 파일을 삭제
  1. 10 17
      libnetwork/sandbox_test.go

+ 10 - 17
libnetwork/sandbox_test.go

@@ -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 {