Skip to content

Commit

Permalink
clean up
Browse files Browse the repository at this point in the history
Signed-off-by: Nikita Skrynnik <[email protected]>
  • Loading branch information
NikitaSkrynnik committed Jan 28, 2022
1 parent 09bf913 commit 938a3b4
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 39 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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/
Expand Down
2 changes: 1 addition & 1 deletion internal/tests/suite_combinatronics_test.go
Original file line number Diff line number Diff line change
@@ -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
//
Expand Down
2 changes: 1 addition & 1 deletion internal/tests/suite_kernel_test.go
Original file line number Diff line number Diff line change
@@ -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
//
Expand Down
47 changes: 22 additions & 25 deletions internal/tests/suite_setup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -72,50 +69,50 @@ 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"),
spire.WithEntry(fmt.Sprintf("spiffe://example.org/%s", filepath.Base(executable)),
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))
// ********************************************************************************
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))

// ********************************************************************************
Expand All @@ -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))
Expand All @@ -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, &registry.NetworkServiceEndpointQuery{
Expand All @@ -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))

// ********************************************************************************
Expand All @@ -183,19 +180,19 @@ 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").
WithField("version", version.Version).Info("complete")

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").
Expand All @@ -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
Expand Down
11 changes: 1 addition & 10 deletions internal/tests/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
1 change: 0 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ func main() {
syscall.SIGTERM,
syscall.SIGQUIT,
)

defer cancel()

// ********************************************************************************
Expand Down

0 comments on commit 938a3b4

Please sign in to comment.