# README
notwork
A tiny package to help with creating transient Linux virtual network elements for testing purposes, without having to deal with the tedious details of proper and robust cleanup.
notwork
leverages the
vishvananda/netlink module for
RTNETLINK communication, as well as the Ginkgo
testing framework with Gomega matchers.
Usage Example
Usually, you don't want to trash around in the host's network namespace. Insteaed, let's trash around in a transient "throw-away" network namespace, just created for testing purposes and removed at the end of the current test.
In it, we create a transient MACVLAN network interface with a dummy-type parent network interface, also only for the duration of the current test (node):
import (
"github.com/thediveo/notwork/dummy"
"github.com/thediveo/notwork/macvlan"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
)
var _ = Describe("some testing", func() {
It("creates a transient MACVLAN with a dummy parent in a throw-away network namespace", func() {
defer netns.EnterTransient()() // !!! double ()()
// current temporary network namespace will be remove automatically
// at the end of this test.
mcvlan := macvlan.NewTransient(dummy.NewTransient())
// ...virtual network interface will be automatically removed
// at the end of this test.
})
})
VETH Pair Ends in Different Network Namespaces
With the previous example under our black notwork belts, let's create a VETH pair of network interfaces that connect two transient network namespaces.
import (
"github.com/notwork/netns"
"github.com/notwork/veth"
)
var _ = Describe("some isolated testing", func() {
It("connects two temporary network namespaces", func() {
dupondNetns := netns.NewTransient() // create, but don't enter
dupontNetns := netns.NewTransient() // create, but don't enter
dupond, dupont := veth.NewTransient(InNamespace(dupondNetns), WithPeerNamespace(dupontNetns))
})
})
As for the names of the VETH pair end variables, please refer to Dupond et Dupont.
Make Targets
make
: lists all targets.make coverage
: runs all tests with coverage and then updates the coverage badge inREADME.md
.make pkgsite
: installsx/pkgsite
, as well as thebrowser-sync
andnodemon
npm packages first, if not already done so. Then runs thepkgsite
and hot reloads it whenever the documentation changes.make report
: installs@gojp/goreportcard
if not yet done so and then runs it on the code base.make test
: runs all tests (as root), always.make vuln
: installsx/vuln/cmd/govulncheck
and then runs it.
Copyright and License
Copyright 2023 Harald Albrecht, licensed under the Apache License, Version 2.0.