diff --git a/Dockerfile b/Dockerfile index 22c2fa20..1a0271f0 100644 --- a/Dockerfile +++ b/Dockerfile @@ -23,7 +23,7 @@ COPY . . RUN go build -o /bin/forwarder . FROM build as test -CMD go test -run ForwarderTestSuite ./internal/tests -testify.m TestCombinations +CMD go test -test.v ./... FROM test as debug WORKDIR /build/internal/tests/ diff --git a/internal/tests/suite_combinatronics_test.go b/internal/tests/suite_combinatronics_test.go index ba6bdada..6440b96b 100644 --- a/internal/tests/suite_combinatronics_test.go +++ b/internal/tests/suite_combinatronics_test.go @@ -1,4 +1,4 @@ -// Copyright (c) 2020-2021 Cisco and/or its affiliates. +// Copyright (c) 2020-2022 Cisco and/or its affiliates. // // SPDX-License-Identifier: Apache-2.0 // diff --git a/internal/tests/suite_kernel_test.go b/internal/tests/suite_kernel_test.go index bca3e518..6bd1faa8 100644 --- a/internal/tests/suite_kernel_test.go +++ b/internal/tests/suite_kernel_test.go @@ -1,4 +1,4 @@ -// Copyright (c) 2020-2021 Cisco and/or its affiliates. +// Copyright (c) 2020-2022 Cisco and/or its affiliates. // // SPDX-License-Identifier: Apache-2.0 // diff --git a/internal/tests/suite_setup_test.go b/internal/tests/suite_setup_test.go index 428b5c48..c44d2e12 100644 --- a/internal/tests/suite_setup_test.go +++ b/internal/tests/suite_setup_test.go @@ -57,9 +57,6 @@ import ( ) func (f *ForwarderTestSuite) SetupSuite() { -} - -func (f *ForwarderTestSuite) SetupSuite1(t *testing.T) { logrus.SetFormatter(&nested.Formatter{}) logrus.SetLevel(logrus.DebugLevel) log.EnableTracing(true) @@ -72,32 +69,32 @@ func (f *ForwarderTestSuite) SetupSuite1(t *testing.T) { log.FromContext(f.ctx).Infof("Getting Config from Env (time since start: %s)", time.Since(starttime)) // ******************************************************************************** _ = os.Setenv("NSM_TUNNEL_IP", forwarderIP) - require.NoError(t, f.config.Process()) + f.Require().NoError(f.config.Process()) // ******************************************************************************** log.FromContext(f.ctx).Infof("Creating test bridge (time since start: %s)", time.Since(starttime)) // ******************************************************************************** - require.NoError(t, SetupBridge()) + f.Require().NoError(SetupBridge()) // ******************************************************************************** log.FromContext(f.ctx).Infof("Creating test vpp Server (time since start: %s)", time.Since(starttime)) // ******************************************************************************** - f.vppServerConn, f.vppServerRoot, f.vppServerErrCh = f.createVpp(t, f.ctx, "vpp-server") + f.vppServerConn, f.vppServerRoot, f.vppServerErrCh = f.createVpp(f.ctx, "vpp-server") _, err := vppinit.LinkToAfPacket(f.ctx, f.vppServerConn, net.ParseIP(serverIP)) - require.NoError(t, err) + f.Require().NoError(err) // ******************************************************************************** log.FromContext(f.ctx).Infof("Creating test vpp Client (time since start: %s)", time.Since(starttime)) // ******************************************************************************** - f.vppClientConn, f.vppClientRoot, f.vppClientErrCh = f.createVpp(t, f.ctx, "vpp-client") + f.vppClientConn, f.vppClientRoot, f.vppClientErrCh = f.createVpp(f.ctx, "vpp-client") _, err = vppinit.LinkToAfPacket(f.ctx, f.vppClientConn, net.ParseIP(clientIP)) - require.NoError(t, err) + f.Require().NoError(err) // ******************************************************************************** log.FromContext(f.ctx).Infof("Running Spire (time since start: %s)", time.Since(starttime)) // ******************************************************************************** executable, err := os.Executable() - require.NoError(t, err) + f.Require().NoError(err) f.spireErrCh = spire.Start( spire.WithContext(f.ctx), spire.WithEntry("spiffe://example.org/forwarder", "unix:path:/usr/bin/forwarder"), @@ -105,7 +102,7 @@ func (f *ForwarderTestSuite) SetupSuite1(t *testing.T) { fmt.Sprintf("unix:path:%s", executable), ), ) - require.Len(t, f.spireErrCh, 0) + f.Require().Len(f.spireErrCh, 0) // ******************************************************************************** log.FromContext(f.ctx).Infof("Getting X509Source (time since start: %s)", time.Since(starttime)) @@ -113,9 +110,9 @@ func (f *ForwarderTestSuite) SetupSuite1(t *testing.T) { source, err := workloadapi.NewX509Source(f.ctx) f.x509source = source f.x509bundle = source - require.NoError(t, err) + f.Require().NoError(err) svid, err := f.x509source.GetX509SVID() - require.NoError(t, err, "error getting x509 svid") + f.Require().NoError(err, "error getting x509 svid") log.FromContext(f.ctx).Infof("SVID: %q received (time since start: %s)", svid.ID, time.Since(starttime)) // ******************************************************************************** @@ -129,7 +126,7 @@ func (f *ForwarderTestSuite) SetupSuite1(t *testing.T) { exechelper.WithStderr(os.Stderr), exechelper.WithGracePeriod(30*time.Second), ) - require.Len(t, f.sutErrCh, 0) + f.Require().Len(f.sutErrCh, 0) // ******************************************************************************** log.FromContext(f.ctx).Infof("Creating registryServer and registryClient (time since start: %s)", time.Since(starttime)) @@ -153,7 +150,7 @@ func (f *ForwarderTestSuite) SetupSuite1(t *testing.T) { registry.RegisterNetworkServiceEndpointRegistryServer(server, f.registryServer) registry.RegisterNetworkServiceRegistryServer(server, f.registryNSServer) - require.Len(t, f.ListenAndServe(f.ctx, &f.config.ConnectTo, server), 0) + f.Require().Len(f.ListenAndServe(f.ctx, &f.config.ConnectTo, server), 0) ctx := f.ctx recv, err := adapters.NetworkServiceEndpointServerToClient(memrg).Find(ctx, ®istry.NetworkServiceEndpointQuery{ @@ -162,10 +159,10 @@ func (f *ForwarderTestSuite) SetupSuite1(t *testing.T) { }, Watch: true, }) - require.NoError(t, err) + f.Require().NoError(err) regEndpoint, err := recv.Recv() - require.NoError(t, err) + f.Require().NoError(err) log.FromContext(ctx).Infof("Received regEndpoint: %+v (time since start: %s)", regEndpoint, time.Since(starttime)) // ******************************************************************************** @@ -183,11 +180,11 @@ func (f *ForwarderTestSuite) SetupSuite1(t *testing.T) { grpcfd.WithChainUnaryInterceptor(), grpcfd.WithChainStreamInterceptor(), ) - require.NoError(t, err) + f.Require().NoError(err) now := time.Now() version, err := vpe.NewServiceClient(f.vppClientConn).ShowVersion(ctx, &vpe.ShowVersion{}) - require.NoError(t, err) + f.Require().NoError(err) log.FromContext(ctx). WithField("duration", time.Since(now)). WithField("vppName", "vpp-client"). @@ -195,7 +192,7 @@ func (f *ForwarderTestSuite) SetupSuite1(t *testing.T) { now = time.Now() version, err = vpe.NewServiceClient(f.vppServerConn).ShowVersion(ctx, &vpe.ShowVersion{}) - require.NoError(t, err) + f.Require().NoError(err) log.FromContext(ctx). WithField("duration", time.Since(now)). WithField("vppName", "vpp-server"). @@ -206,23 +203,23 @@ func (f *ForwarderTestSuite) SetupSuite1(t *testing.T) { // ******************************************************************************** } -func (f *ForwarderTestSuite) createVpp(t *testing.T, ctx context.Context, name string) (vppConn vpphelper.Connection, vppRoot string, errCh <-chan error) { +func (f *ForwarderTestSuite) createVpp(ctx context.Context, name string) (vppConn vpphelper.Connection, vppRoot string, errCh <-chan error) { now := time.Now() var err error vppRoot, err = ioutil.TempDir("", fmt.Sprintf("%s-", name)) - require.NoError(t, err) + require.NoError(err) - require.NoError(t, err) + f.Require().NoError(err) vppConn, errCh = vpphelper.StartAndDialContext( ctx, vpphelper.WithRootDir(vppRoot), ) - require.Len(t, errCh, 0) + f.Require().Len(errCh, 0) log.FromContext(ctx).WithField("duration", time.Since(now)).Infof("Launched vpp %q. Access with vppctl -s /tmp/%s/var/run/vpp/cli.sock", vppRoot, vppRoot) return vppConn, vppRoot, errCh } -func (f *ForwarderTestSuite) TearDownSuite1() { +func (f *ForwarderTestSuite) TearDownSuite() { f.cancel() for { _, ok := <-f.sutErrCh diff --git a/internal/tests/suite_test.go b/internal/tests/suite_test.go index 8eb46ac6..0de1b563 100644 --- a/internal/tests/suite_test.go +++ b/internal/tests/suite_test.go @@ -64,14 +64,5 @@ type ForwarderTestSuite struct { } func TestForwarderTestSuite(t *testing.T) { - - f := new(ForwarderTestSuite) - - f.SetupSuite1(t) - - for i := 0; i < 10; i++ { - suite.Run(t, f) - } - - f.TearDownSuite1() + suite.Run(t, new(ForwarderTestSuite)) } diff --git a/main.go b/main.go index c22b0b37..d5f11820 100644 --- a/main.go +++ b/main.go @@ -72,7 +72,6 @@ func main() { syscall.SIGTERM, syscall.SIGQUIT, ) - defer cancel() // ********************************************************************************