Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/thediveo/notwork
A tiny package to help with creating transient Linux virtual network elements for testing purposes.
https://github.com/thediveo/notwork
Last synced: about 1 month ago
JSON representation
A tiny package to help with creating transient Linux virtual network elements for testing purposes.
- Host: GitHub
- URL: https://github.com/thediveo/notwork
- Owner: thediveo
- License: apache-2.0
- Created: 2023-03-15T15:38:47.000Z (over 1 year ago)
- Default Branch: master
- Last Pushed: 2024-09-11T18:19:15.000Z (2 months ago)
- Last Synced: 2024-09-12T04:16:31.759Z (2 months ago)
- Language: Go
- Homepage:
- Size: 95.7 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# `notwork`
[![PkgGoDev](https://pkg.go.dev/badge/github.com/thediveo/notwork)](https://pkg.go.dev/github.com/thediveo/notwork)
[![GitHub](https://img.shields.io/github/license/thediveo/notwork)](https://img.shields.io/github/license/thediveo/notwork)
![build and test](https://github.com/thediveo/notwork/workflows/build%20and%20test/badge.svg?branch=master)
[![goroutines](https://img.shields.io/badge/go%20routines-not%20leaking-success)](https://pkg.go.dev/github.com/onsi/gomega/gleak)
[![file descriptors](https://img.shields.io/badge/file%20descriptors-not%20leaking-success)](https://pkg.go.dev/github.com/thediveo/fdooze)
[![Go Report Card](https://goreportcard.com/badge/github.com/thediveo/whalewatcher)](https://goreportcard.com/report/github.com/thediveo/notwork)
![Coverage](https://img.shields.io/badge/Coverage-94.2%25-brightgreen)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](https://github.com/vishvananda/netlink) module for
RTNETLINK communication, as well as the [Ginkgo](https://github.com/onsi/ginkgo)
testing framework with [Gomega](https://github.com/onsi/gomega) matchers.## Usage Example
Usually, you don't want to trash around in the host's network namespace.
Instead, let's trash around in a ephemeral ("throw-away") network namespace,
just created for testing purposes and removed at the end of the _current_ test
node.In it, we create a transient MACVLAN-type network interface with a dummy-type
parent network interface, also only for the duration of the current test (node):```go
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.
})})
```> [!IMPORTANT]
> Notice the double `()()` when `defer`'ing `netns.EnterTransient`.## 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.```go
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](https://en.wikipedia.org/wiki/Thomson_and_Thompson).## Go Version Support
`notwork` supports versions of Go that are noted by the Go release policy, that
is, major versions _N_ and _N_-1 (where _N_ is the current major version).## Make Targets
- `make`: lists all targets.
- `make coverage`: runs all tests with coverage and then **updates the coverage
badge in `README.md`**.
- `make pkgsite`: installs [`x/pkgsite`](https://golang.org/x/pkgsite/cmd/pkgsite), as
well as the [`browser-sync`](https://www.npmjs.com/package/browser-sync) and
[`nodemon`](https://www.npmjs.com/package/nodemon) npm packages first, if not
already done so. Then runs the `pkgsite` and hot reloads it whenever the
documentation changes.
- `make report`: installs
[`@gojp/goreportcard`](https://github.com/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`: installs
[`x/vuln/cmd/govulncheck`](https://golang.org/x/vuln/cmd/govulncheck) and then
runs it.## Copyright and License
Copyright 2023–24 Harald Albrecht, licensed under the Apache License, Version 2.0.