Skip to content

Commit

Permalink
return error if conf missing, add test
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Zappa <[email protected]>
  • Loading branch information
MikeZappa87 committed Aug 5, 2023
1 parent ff76d3e commit 985ec85
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
2 changes: 2 additions & 0 deletions cni.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,8 @@ func (c *libcni) BuildMultiNetwork(networkNames []*NetworkInterface) ([]*Network
}

ifs[name] = net
} else {
return nil, fmt.Errorf("the network config: %v does not exist", v.NetworkName)
}
}

Expand Down
28 changes: 28 additions & 0 deletions cni_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,34 @@ func TestBuildNetworksDuplicateIfName(t *testing.T) {
assert.EqualError(t, err, "the interface: net10 already exists and must be unique")
}

func TestBuildNetworksMissingNetworkConfig(t *testing.T) {
// Get the default CNI config
l := defaultCNIConfig()
// Create a fake cni config directory and file
cniDir, confDir := makeFakeCNIConfig(t)
defer tearDownCNIConfig(t, cniDir)
l.pluginConfDir = confDir
// Set the minimum network count as 2 for this test
l.networkCount = 2
err := l.Load(WithLoNetwork, WithAllConf)
assert.NoError(t, err)

err = l.Status()
assert.NoError(t, err)

net := []*NetworkInterface{
{
NetworkName: "thisdoesnotexist",
InterfaceName: "net10",
},
}

_, err = l.BuildMultiNetwork(net)

assert.Error(t, err)
assert.EqualError(t, err, "the network config: thisdoesnotexist does not exist")
}

type MockCNI struct {
mock.Mock
}
Expand Down

0 comments on commit 985ec85

Please sign in to comment.