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

     1  //go:build integration
     2  
     3  package integration
     4  
     5  import (
     6  	"testing"
     7  
     8  	"get.porter.sh/porter/pkg/porter"
     9  	"github.com/stretchr/testify/require"
    10  )
    11  
    12  func TestSuppressOutput(t *testing.T) {
    13  	t.Parallel()
    14  
    15  	p := porter.NewTestPorter(t)
    16  	defer p.Close()
    17  	ctx := p.SetupIntegrationTest()
    18  
    19  	bundleName := p.AddTestBundleDir("testdata/bundles/suppressed-output-example", true)
    20  
    21  	// Install (Output suppressed)
    22  	installOpts := porter.NewInstallOptions()
    23  	err := installOpts.Validate(ctx, []string{}, p.Porter)
    24  	require.NoError(t, err)
    25  
    26  	err = p.InstallBundle(ctx, installOpts)
    27  	require.NoError(t, err)
    28  
    29  	// Verify that the bundle output was captured (despite stdout/err of command being suppressed)
    30  	bundleOutput, err := p.ReadBundleOutput(ctx, "greeting", bundleName, "")
    31  	require.NoError(t, err, "could not read config output")
    32  	require.Equal(t, "Hello World!", bundleOutput, "expected the bundle output to be populated correctly")
    33  
    34  	// Invoke - Log Error (Output suppressed)
    35  	invokeOpts := porter.NewInvokeOptions()
    36  	invokeOpts.Action = "log-error"
    37  	err = invokeOpts.Validate(ctx, []string{}, p.Porter)
    38  	require.NoError(t, err)
    39  
    40  	err = p.InvokeBundle(ctx, invokeOpts)
    41  	require.NoError(t, err)
    42  
    43  	// Uninstall
    44  	uninstallOpts := porter.NewUninstallOptions()
    45  	err = uninstallOpts.Validate(ctx, []string{}, p.Porter)
    46  	require.NoError(t, err)
    47  
    48  	err = p.UninstallBundle(ctx, uninstallOpts)
    49  	require.NoError(t, err)
    50  
    51  	gotCmdOutput := p.TestConfig.TestContext.GetOutput()
    52  
    53  	require.NotContains(t, gotCmdOutput, "Hello World!", "expected command output to be suppressed from Install step")
    54  	require.NotContains(t, gotCmdOutput, "Error!", "expected command output to be suppressed from Invoke step")
    55  	require.Contains(t, gotCmdOutput, "Farewell World!", "expected command output to be present from Uninstall step")
    56  }