func Test_cniPlugin_getCNIRuntimeConf(t *testing.T) {
	t.Parallel()
	plugin, _, tmpDir := testCNIPlugin(t)
	defer os.RemoveAll(tmpDir)
	conf := plugin.getCNIRuntimeConf("foo")
	assert.Equal(t, &libcni.RuntimeConf{
		ContainerID: "foo",
		NetNS:       "",
		IfName:      DefaultInterface,
		Args:        [][2]string{},
	}, conf)
}
TODO: test getCNINetworkConfig
package network
import (
	"io/ioutil"
	"os"
	"path/filepath"
	"testing"
	"github.com/automaticserver/lxe/network/libcnifake"
	"github.com/containernetworking/cni/libcni"
	types020 "github.com/containernetworking/cni/pkg/types/020"
	"github.com/containernetworking/cni/pkg/types/current"
	"github.com/stretchr/testify/assert"
)
var (
	_ Plugin           = &cniPlugin{}
	_ PodNetwork       = &cniPodNetwork{}
	_ ContainerNetwork = &cniContainerNetwork{}
)
func fakeCNIFiles(t *testing.T) (string, string, string, string) {
	tmpDir, err := ioutil.TempDir("", "cni")
	assert.NoError(t, err)
	binPath := filepath.Join(tmpDir, DefaultCNIbinPath)
	confPath := filepath.Join(tmpDir, DefaultCNIconfPath)
	netnsPath := filepath.Join(tmpDir, defaultCNInetnsPath)
	err = os.MkdirAll(confPath, 0700)
	assert.NoError(t, err)
	err = ioutil.WriteFile(filepath.Join(confPath, "99-lo.conf"), []byte(`
	{
		"cniVersion": "0.4.0",
		"name": "lo",
		"type": "loopback"
	}`), 0600)
	assert.NoError(t, err)
	err = os.MkdirAll(netnsPath, 0700)
	assert.NoError(t, err)
	return tmpDir, binPath, confPath, netnsPath
}
func TestInitPluginCNI(t *testing.T) {
	t.Parallel()
	tmpDir, binPath, confPath, netnsPath := fakeCNIFiles(t)
	defer os.RemoveAll(tmpDir)
	plugin, err := InitPluginCNI(ConfCNI{
		BinPath:   binPath,
		ConfPath:  confPath,
		NetnsPath: netnsPath,
	})
	assert.NoError(t, err)
	assert.NotNil(t, plugin.cni)
	assert.NotEmpty(t, plugin.conf)
}
func TestConfCNI_setDefaults(t *testing.T) {
	t.Parallel()
	conf := &ConfCNI{}
	conf.setDefaults()
	assert.NotEmpty(t, conf.BinPath)
	assert.NotEmpty(t, conf.ConfPath)
	assert.NotEmpty(t, conf.NetnsPath)
}
func testCNIPlugin(t *testing.T) (*cniPlugin, *libcnifake.FakeCNI, string) {
	fake := &libcnifake.FakeCNI{}
	tmpDir, binPath, confPath, netnsPath := fakeCNIFiles(t)
	return &cniPlugin{
		cni: fake,
		conf: ConfCNI{
			BinPath:   binPath,
			ConfPath:  confPath,
			NetnsPath: netnsPath,
		},
	}, fake, tmpDir
}
func Test_cniPlugin_PodNetwork_Simple(t *testing.T) {
	t.Parallel()
	plugin, _, tmpDir := testCNIPlugin(t)
	defer os.RemoveAll(tmpDir)
	podNet, err := plugin.PodNetwork("foo", nil)
	assert.NoError(t, err)
	assert.NotNil(t, podNet)
	tPodNet := podNet.(*cniPodNetwork)
	assert.NotNil(t, tPodNet.netList)
	assert.NotNil(t, tPodNet.runtimeConf)
}
func Test_cniPlugin_UpdateRuntimeConfig(t *testing.T) {
	t.Parallel()
	plugin, _, tmpDir := testCNIPlugin(t)
	defer os.RemoveAll(tmpDir)
	err := plugin.UpdateRuntimeConfig(nil)
	assert.Error(t, err)
}