get.porter.sh/porter@v1.3.0/pkg/grpc/portergrpc/portergrpc_test.go (about)

     1  package portergrpc
     2  
     3  import (
     4  	"context"
     5  	"testing"
     6  
     7  	"get.porter.sh/porter/pkg/config"
     8  	"get.porter.sh/porter/pkg/porter"
     9  	grpc_middleware "github.com/grpc-ecosystem/go-grpc-middleware"
    10  	"github.com/stretchr/testify/assert"
    11  	"google.golang.org/grpc"
    12  )
    13  
    14  func TestNewConnectionInterceptorCallsNextHandlerInTheChainWithThePorterConnectionInTheContext(t *testing.T) {
    15  	cfg := config.NewTestConfig(t)
    16  	srv := PorterServer{PorterConfig: cfg.Config}
    17  	parentUnaryInfo := &grpc.UnaryServerInfo{FullMethod: "SomeService.StreamMethod"}
    18  	input := "input"
    19  	testHandler := func(ctx context.Context, req interface{}) (interface{}, error) {
    20  		p, err := GetPorterConnectionFromContext(ctx)
    21  		return p, err
    22  	}
    23  	ctx := context.Background()
    24  	chain := grpc_middleware.ChainUnaryServer(srv.NewConnectionInterceptor)
    25  	newP, err := chain(ctx, input, parentUnaryInfo, testHandler)
    26  	assert.Nil(t, err)
    27  	assert.NotNil(t, newP)
    28  	assert.IsType(t, &porter.Porter{}, newP)
    29  }