409ea700c7
This commit introduces a new integration test suite aimed at testing networking features like inter-container communication, network isolation, port mapping, etc... and how they interact with daemon-level and network-level parameters. So far, there's pretty much no tests making sure our networks are well configured: 1. there're a few tests for port mapping, but they don't cover all use cases ; 2. there're a few tests that check if a specific iptables rule exist, but that doesn't prevent that specific iptables rule to be wrong in the first place. As we're planning to refactor how iptables rules are written, and change some of them to fix known security issues, we need a way to test all combinations of parameters. So far, this was done by hand, which is particularly painful and time consuming. As such, this new test suite is foundational to upcoming work. Signed-off-by: Albin Kerouanton <albinker@gmail.com>
62 lines
1.2 KiB
Go
62 lines
1.2 KiB
Go
package networking
|
|
|
|
import (
|
|
"context"
|
|
"os"
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/docker/docker/testutil"
|
|
"github.com/docker/docker/testutil/environment"
|
|
"go.opentelemetry.io/otel"
|
|
"go.opentelemetry.io/otel/codes"
|
|
)
|
|
|
|
var (
|
|
testEnv *environment.Execution
|
|
baseContext context.Context
|
|
)
|
|
|
|
func TestMain(m *testing.M) {
|
|
shutdown := testutil.ConfigureTracing()
|
|
ctx, span := otel.Tracer("").Start(context.Background(), "integration/networking.TestMain")
|
|
baseContext = ctx
|
|
|
|
var err error
|
|
testEnv, err = environment.New(ctx)
|
|
if err != nil {
|
|
span.SetStatus(codes.Error, err.Error())
|
|
span.End()
|
|
shutdown(ctx)
|
|
panic(err)
|
|
}
|
|
|
|
err = environment.EnsureFrozenImagesLinux(ctx, testEnv)
|
|
if err != nil {
|
|
span.SetStatus(codes.Error, err.Error())
|
|
span.End()
|
|
shutdown(ctx)
|
|
panic(err)
|
|
}
|
|
|
|
testEnv.Print()
|
|
code := m.Run()
|
|
if code != 0 {
|
|
span.SetStatus(codes.Error, "m.Run() returned non-zero exit code")
|
|
}
|
|
span.End()
|
|
shutdown(ctx)
|
|
os.Exit(code)
|
|
}
|
|
|
|
func setupTest(t *testing.T) context.Context {
|
|
ctx := testutil.StartSpan(baseContext, t)
|
|
environment.ProtectAll(ctx, t, testEnv)
|
|
t.Cleanup(func() { testEnv.Clean(ctx, t) })
|
|
return ctx
|
|
}
|
|
|
|
func sanitizeCtrName(name string) string {
|
|
r := strings.NewReplacer("/", "-", "=", "-")
|
|
return r.Replace(name)
|
|
}
|