libnetwork/netavark: add plugin tests
The the plugin integration with the testplugin. Signed-off-by: Paul Holzinger <pholzing@redhat.com>
This commit is contained in:
parent
8ff1bd975e
commit
13dbce596d
|
|
@ -97,7 +97,7 @@ install:
|
|||
test: test-unit
|
||||
|
||||
.PHONY: test-unit
|
||||
test-unit:
|
||||
test-unit: netavark-testplugin
|
||||
go test --tags $(BUILDTAGS) -v ./libimage
|
||||
go test --tags $(BUILDTAGS) -v ./libnetwork/...
|
||||
go test --tags $(BUILDTAGS) -v ./pkg/...
|
||||
|
|
|
|||
|
|
@ -40,6 +40,15 @@ func getNetworkInterface(confDir string) (types.ContainerNetwork, error) {
|
|||
})
|
||||
}
|
||||
|
||||
func getNetworkInterfaceWithPlugins(confDir string, pluginDirs []string) (types.ContainerNetwork, error) {
|
||||
return netavark.NewNetworkInterface(&netavark.InitConfig{
|
||||
NetworkConfigDir: confDir,
|
||||
NetavarkBinary: netavarkBinary,
|
||||
NetworkRunDir: confDir,
|
||||
PluginDirs: pluginDirs,
|
||||
})
|
||||
}
|
||||
|
||||
// EqualSubnet is a custom GomegaMatcher to match a subnet
|
||||
// This makes sure to not use the 16 bytes ip representation.
|
||||
func EqualSubnet(subnet *net.IPNet) gomegaTypes.GomegaMatcher {
|
||||
|
|
|
|||
|
|
@ -0,0 +1,106 @@
|
|||
//go:build linux
|
||||
// +build linux
|
||||
|
||||
package netavark_test
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/containers/common/libnetwork/types"
|
||||
. "github.com/onsi/ginkgo/v2"
|
||||
. "github.com/onsi/gomega"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
const pluginName = "netavark-testplugin"
|
||||
|
||||
var _ = Describe("Plugins", func() {
|
||||
var (
|
||||
libpodNet types.ContainerNetwork
|
||||
networkConfDir string
|
||||
logBuffer bytes.Buffer
|
||||
)
|
||||
|
||||
BeforeEach(func() {
|
||||
var err error
|
||||
networkConfDir, err = os.MkdirTemp("", "podman_netavark_test")
|
||||
if err != nil {
|
||||
Fail("Failed to create tmpdir")
|
||||
}
|
||||
logBuffer = bytes.Buffer{}
|
||||
logrus.SetOutput(&logBuffer)
|
||||
})
|
||||
|
||||
JustBeforeEach(func() {
|
||||
var err error
|
||||
libpodNet, err = getNetworkInterfaceWithPlugins(networkConfDir, []string{"../../bin"})
|
||||
if err != nil {
|
||||
Fail("Failed to create NewNetworkInterface")
|
||||
}
|
||||
})
|
||||
|
||||
AfterEach(func() {
|
||||
os.RemoveAll(networkConfDir)
|
||||
})
|
||||
|
||||
It("create plugin network", func() {
|
||||
network := types.Network{Driver: pluginName}
|
||||
network1, err := libpodNet.NetworkCreate(network, nil)
|
||||
Expect(err).To(BeNil())
|
||||
Expect(network1.Name).ToNot(BeEmpty())
|
||||
Expect(network1.ID).ToNot(BeEmpty())
|
||||
Expect(filepath.Join(networkConfDir, network1.Name+".json")).To(BeARegularFile())
|
||||
})
|
||||
|
||||
It("create plugin network with name", func() {
|
||||
name := "test123"
|
||||
network := types.Network{Driver: pluginName, Name: name}
|
||||
network1, err := libpodNet.NetworkCreate(network, nil)
|
||||
Expect(err).To(BeNil())
|
||||
Expect(network1.Name).To(Equal(name))
|
||||
Expect(network1.ID).ToNot(BeEmpty())
|
||||
Expect(filepath.Join(networkConfDir, network1.Name+".json")).To(BeARegularFile())
|
||||
})
|
||||
|
||||
It("create plugin error", func() {
|
||||
network := types.Network{
|
||||
Driver: pluginName,
|
||||
Options: map[string]string{"error": "my custom error"},
|
||||
}
|
||||
_, err := libpodNet.NetworkCreate(network, nil)
|
||||
Expect(err).To(HaveOccurred())
|
||||
Expect(err.Error()).To(Equal("plugin ../../bin/netavark-testplugin failed: netavark (exit code 1): my custom error"))
|
||||
})
|
||||
|
||||
It("create plugin change name error", func() {
|
||||
network := types.Network{
|
||||
Driver: pluginName,
|
||||
Options: map[string]string{"name": "newName"},
|
||||
}
|
||||
_, err := libpodNet.NetworkCreate(network, nil)
|
||||
Expect(err).To(HaveOccurred())
|
||||
Expect(err.Error()).To(Equal("invalid plugin result: changed network name"))
|
||||
})
|
||||
|
||||
It("create plugin change id error", func() {
|
||||
network := types.Network{
|
||||
Driver: pluginName,
|
||||
Options: map[string]string{"id": "newID"},
|
||||
}
|
||||
_, err := libpodNet.NetworkCreate(network, nil)
|
||||
Expect(err).To(HaveOccurred())
|
||||
Expect(err.Error()).To(Equal("invalid plugin result: changed network ID"))
|
||||
})
|
||||
|
||||
It("create plugin change driver error", func() {
|
||||
network := types.Network{
|
||||
Driver: pluginName,
|
||||
Options: map[string]string{"driver": "newDriver"},
|
||||
}
|
||||
_, err := libpodNet.NetworkCreate(network, nil)
|
||||
Expect(err).To(HaveOccurred())
|
||||
Expect(err.Error()).To(Equal("invalid plugin result: changed network driver"))
|
||||
})
|
||||
})
|
||||
Loading…
Reference in New Issue