Merge pull request #45988 from thaJeztah/libnetwork_drivers_clean
libnetwork, libnetwork/drivers: some minor cleanups
This commit is contained in:
commit
0761240c43
6 changed files with 18 additions and 30 deletions
|
@ -440,12 +440,7 @@ func (d *driver) configure(option map[string]interface{}) error {
|
|||
d.config = config
|
||||
d.Unlock()
|
||||
|
||||
err = d.initStore(option)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
return d.initStore(option)
|
||||
}
|
||||
|
||||
func (d *driver) getNetwork(id string) (*bridgeNetwork, error) {
|
||||
|
|
|
@ -52,7 +52,7 @@ func TestSetupNewNonDefaultBridge(t *testing.T) {
|
|||
|
||||
err = setupDevice(config, br)
|
||||
if err == nil {
|
||||
t.Fatal("Expected bridge creation failure with \"non default name\", succeeded")
|
||||
t.Fatal(`Expected bridge creation failure with "non default name", succeeded`)
|
||||
}
|
||||
|
||||
if _, ok := err.(NonDefaultBridgeExistError); !ok {
|
||||
|
|
|
@ -43,7 +43,7 @@ func (d *driver) CreateNetwork(id string, option map[string]interface{}, nInfo d
|
|||
defer d.Unlock()
|
||||
|
||||
if d.network != "" {
|
||||
return types.ForbiddenErrorf("only one instance of \"%s\" network is allowed", NetworkType)
|
||||
return types.ForbiddenErrorf("only one instance of %q network is allowed", NetworkType)
|
||||
}
|
||||
|
||||
d.network = id
|
||||
|
@ -52,7 +52,7 @@ func (d *driver) CreateNetwork(id string, option map[string]interface{}, nInfo d
|
|||
}
|
||||
|
||||
func (d *driver) DeleteNetwork(nid string) error {
|
||||
return types.ForbiddenErrorf("network of type \"%s\" cannot be deleted", NetworkType)
|
||||
return types.ForbiddenErrorf("network of type %q cannot be deleted", NetworkType)
|
||||
}
|
||||
|
||||
func (d *driver) CreateEndpoint(nid, eid string, ifInfo driverapi.InterfaceInfo, epOptions map[string]interface{}) error {
|
||||
|
|
|
@ -43,7 +43,7 @@ func (d *driver) CreateNetwork(id string, option map[string]interface{}, nInfo d
|
|||
defer d.Unlock()
|
||||
|
||||
if d.network != "" {
|
||||
return types.ForbiddenErrorf("only one instance of \"%s\" network is allowed", NetworkType)
|
||||
return types.ForbiddenErrorf("only one instance of %q network is allowed", NetworkType)
|
||||
}
|
||||
|
||||
d.network = id
|
||||
|
@ -52,7 +52,7 @@ func (d *driver) CreateNetwork(id string, option map[string]interface{}, nInfo d
|
|||
}
|
||||
|
||||
func (d *driver) DeleteNetwork(nid string) error {
|
||||
return types.ForbiddenErrorf("network of type \"%s\" cannot be deleted", NetworkType)
|
||||
return types.ForbiddenErrorf("network of type %q cannot be deleted", NetworkType)
|
||||
}
|
||||
|
||||
func (d *driver) CreateEndpoint(nid, eid string, ifInfo driverapi.InterfaceInfo, epOptions map[string]interface{}) error {
|
||||
|
|
|
@ -43,14 +43,14 @@ func TestAppendVNIList(t *testing.T) {
|
|||
slice: []uint32{4, 5, 6},
|
||||
csv: "1,2,3,abc",
|
||||
want: []uint32{4, 5, 6, 1, 2, 3},
|
||||
wantErr: "invalid vxlan id value \"abc\" passed",
|
||||
wantErr: `invalid vxlan id value "abc" passed`,
|
||||
},
|
||||
{
|
||||
name: "InvalidVNI2",
|
||||
slice: []uint32{4, 5, 6},
|
||||
csv: "abc,1,2,3",
|
||||
want: []uint32{4, 5, 6},
|
||||
wantErr: "invalid vxlan id value \"abc\" passed",
|
||||
wantErr: `invalid vxlan id value "abc" passed`,
|
||||
},
|
||||
}
|
||||
for _, tt := range cases {
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Add table
Reference in a new issue