get.porter.sh/porter@v1.3.0/tests/integration/connection_nix_test.go (about)

     1  //go:build integration && !windows
     2  
     3  package integration
     4  
     5  import (
     6  	"context"
     7  	"strings"
     8  	"testing"
     9  
    10  	"get.porter.sh/porter/pkg/config"
    11  	"get.porter.sh/porter/pkg/plugins"
    12  	"get.porter.sh/porter/pkg/plugins/pluggable"
    13  	"get.porter.sh/porter/pkg/portercontext"
    14  	secretsplugins "get.porter.sh/porter/pkg/secrets/plugins"
    15  	"get.porter.sh/porter/pkg/secrets/pluginstore"
    16  	"github.com/stretchr/testify/assert"
    17  	"github.com/stretchr/testify/require"
    18  	"go.uber.org/zap/zapcore"
    19  )
    20  
    21  func TestPluginConnectionForLeaks(t *testing.T) {
    22  	// We are only running this test on linux/darwin because windows doesn't have SIGCONT
    23  	ctx := context.Background()
    24  
    25  	c := config.NewTestConfig(t)
    26  	defer c.Close()
    27  	c.SetupIntegrationTest()
    28  	c.ConfigureLogging(ctx, portercontext.LogConfiguration{
    29  		LogLevel:       zapcore.DebugLevel,
    30  		StructuredLogs: true,
    31  	})
    32  	ctx, log := c.StartRootSpan(ctx, t.Name())
    33  	defer log.Close()
    34  
    35  	pluginKey := plugins.PluginKey{
    36  		Interface:      secretsplugins.PluginInterface,
    37  		Binary:         "porter",
    38  		Implementation: "host",
    39  		IsInternal:     true,
    40  	}
    41  	pluginType := pluginstore.NewSecretsPluginConfig()
    42  	conn := pluggable.NewPluginConnection(c.Config, pluginType, pluginKey)
    43  	defer conn.Close(ctx)
    44  
    45  	err := conn.Start(ctx, strings.NewReader(""))
    46  	require.NoError(t, err, "failed to start the plugin")
    47  	assert.True(t, conn.IsPluginRunning(), "the plugin did not start")
    48  
    49  	err = conn.Close(ctx)
    50  	require.NoError(t, err, "failed to close the plugin")
    51  	assert.False(t, conn.IsPluginRunning(), "the plugin connection was leaked")
    52  }