Example #1
0
	"github.com/onsi/gomega/gbytes"
	"github.com/onsi/gomega/gexec"
)

var _ = Describe("Loopback", func() {
	var (
		networkNS   string
		containerID string
		command     *exec.Cmd
		environ     []string
	)

	BeforeEach(func() {
		command = exec.Command(pathToLoPlugin)
		containerID = "some-container-id"
		networkNS = testhelpers.MakeNetworkNS(containerID)

		environ = []string{
			fmt.Sprintf("CNI_CONTAINERID=%s", containerID),
			fmt.Sprintf("CNI_NETNS=%s", networkNS),
			fmt.Sprintf("CNI_IFNAME=%s", "this is ignored"),
			fmt.Sprintf("CNI_ARGS=%s", "none"),
			fmt.Sprintf("CNI_PATH=%s", "/some/test/path"),
		}
		command.Stdin = strings.NewReader("this doesn't matter")
	})

	AfterEach(func() {
		Expect(testhelpers.RemoveNetworkNS(networkNS)).To(Succeed())
	})
Example #2
0
	"fmt"
	"math/rand"
	"path/filepath"

	"golang.org/x/sys/unix"

	"github.com/appc/cni/pkg/testhelpers"
	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
)

var _ = Describe("Test helper functions", func() {
	Describe("MakeNetworkNS", func() {
		It("should return the filepath to a network namespace", func() {
			containerID := fmt.Sprintf("c-%x", rand.Int31())
			nsPath := testhelpers.MakeNetworkNS(containerID)

			Expect(nsPath).To(BeAnExistingFile())

			testhelpers.RemoveNetworkNS(containerID)
		})

		It("should return a network namespace different from that of the caller", func() {
			containerID := fmt.Sprintf("c-%x", rand.Int31())

			By("discovering the inode of the current netns")
			originalNetNSPath := currentNetNSPath()
			originalNetNSInode, err := testhelpers.GetInode(originalNetNSPath)
			Expect(err).NotTo(HaveOccurred())

			By("creating a new netns")