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

     1  //go:build integration
     2  
     3  package integration
     4  
     5  import (
     6  	"fmt"
     7  	"testing"
     8  
     9  	"get.porter.sh/porter/tests/tester"
    10  	"github.com/stretchr/testify/require"
    11  	"github.com/uwu-tools/magex/shx"
    12  )
    13  
    14  func TestPluginDebugLogsVerbosityArgument(t *testing.T) {
    15  	testcases := []struct {
    16  		name              string
    17  		verbosity         string
    18  		shouldContain     bool
    19  		expectedPluginLog string
    20  	}{
    21  		{"plugin debug logs", "debug", true, "plugin started"},
    22  		{"plugin info logs doesn't contain plugin process exited", "info", false, "plugin process exited"},
    23  		{"plugin debug logs contains plugin process exited", "debug", true, "plugin process exited"},
    24  		{"plugin info logs", "info", false, "plugin started"},
    25  	}
    26  	for _, tc := range testcases {
    27  		test, err := tester.NewTest(t)
    28  		require.NoError(t, err, "test setup failed")
    29  		defer test.Close()
    30  
    31  		output, _ := test.RequirePorter("list", "--verbosity", tc.verbosity)
    32  		if tc.shouldContain {
    33  			require.Contains(t, output, tc.expectedPluginLog)
    34  		} else {
    35  			require.NotContains(t, output, tc.expectedPluginLog)
    36  		}
    37  	}
    38  }
    39  
    40  func TestPluginDebugLogsVerbosityEnvironmentVariable(t *testing.T) {
    41  	testcases := []struct {
    42  		name              string
    43  		verbosity         string
    44  		shouldContain     bool
    45  		expectedPluginLog string
    46  	}{
    47  		{"plugin debug logs", "debug", true, "plugin started"},
    48  		{"plugin info logs doesn't contain plugin process exited", "info", false, "plugin process exited"},
    49  		{"plugin debug logs contains plugin process exited", "debug", true, "plugin process exited"},
    50  		{"plugin info logs", "info", false, "plugin started"},
    51  	}
    52  	for _, tc := range testcases {
    53  		test, err := tester.NewTest(t)
    54  		require.NoError(t, err, "test setup failed")
    55  		defer test.Close()
    56  
    57  		output, _, err := test.RunPorterWith(func(cmd *shx.PreparedCommand) {
    58  			cmd.Args("list")
    59  			cmd.Env(fmt.Sprintf("PORTER_VERBOSITY=%s", tc.verbosity))
    60  		})
    61  		if tc.shouldContain {
    62  			require.Contains(t, output, tc.expectedPluginLog)
    63  		} else {
    64  			require.NotContains(t, output, tc.expectedPluginLog)
    65  		}
    66  	}
    67  }