Skip to content

Commit

Permalink
Move {test/bufconn => mtls/bufconn_test}.go
Browse files Browse the repository at this point in the history
  • Loading branch information
andrejtokarcik committed Oct 28, 2020
1 parent de8ef72 commit d7efdff
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
7 changes: 4 additions & 3 deletions test/bufconn.go → mtls/bufconn_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package test
package mtls_test

import (
"context"
Expand All @@ -10,6 +10,7 @@ import (
"google.golang.org/grpc/test/bufconn"

"github.com/andrejtokarcik/jobworker/client"
"github.com/andrejtokarcik/jobworker/server"
)

type BufconnConfig struct {
Expand All @@ -32,8 +33,8 @@ func NewBufconnSuite() (suite BufconnSuite) {
return
}

func (suite *BufconnSuite) SetupBufconn(grpcServer *grpc.Server) {
suite.grpcServer = grpcServer
func (suite *BufconnSuite) SetupBufconn(opts ...grpc.ServerOption) {
suite.grpcServer = server.New(opts...)
suite.listener = bufconn.Listen(suite.BufSize)
go func() {
if err := suite.grpcServer.Serve(suite.listener); err != nil {
Expand Down
12 changes: 5 additions & 7 deletions mtls/mtls_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,10 @@ import (
"google.golang.org/grpc"

"github.com/andrejtokarcik/jobworker/mtls"
"github.com/andrejtokarcik/jobworker/test"
)

type mTLSTestSuite struct {
test.BufconnSuite
BufconnSuite
}

type mTLSTestCase struct {
Expand All @@ -31,8 +30,7 @@ func (suite *mTLSTestSuite) SetupSuite() {
panic(err)
}

grpcServer := grpc.NewServer(grpc.Creds(serverCreds))
suite.SetupBufconn(grpcServer)
suite.SetupBufconn(grpc.Creds(serverCreds))
}

func (suite *mTLSTestSuite) TearDownSuite() {
Expand All @@ -41,7 +39,7 @@ func (suite *mTLSTestSuite) TearDownSuite() {

func (suite *mTLSTestSuite) runTestCase(tc mTLSTestCase) {
clientCreds, err := mtls.NewClientCreds(tc.clientCredsFiles)
suite.Require().Nil(err)
suite.Require().Nil(err, err)

conn, err := suite.DialBufconn(
tc.serverName,
Expand All @@ -52,7 +50,7 @@ func (suite *mTLSTestSuite) runTestCase(tc mTLSTestCase) {
}

if tc.expectedErr == nil {
suite.Require().Nil(err)
suite.Require().Nil(err, err)
} else {
suite.Require().NotNil(err)
suite.Assert().Contains(err.Error(), tc.expectedErr.Error())
Expand Down Expand Up @@ -99,5 +97,5 @@ func (suite *mTLSTestSuite) TestInvalidServerName() {
}

func TestMutualTLS(t *testing.T) {
suite.Run(t, &mTLSTestSuite{test.NewBufconnSuite()})
suite.Run(t, &mTLSTestSuite{NewBufconnSuite()})
}

0 comments on commit d7efdff

Please sign in to comment.