get.porter.sh/porter@v1.3.0/cmd/porter/completion_test.go (about)

     1  package main
     2  
     3  import (
     4  	"bytes"
     5  	"os"
     6  	"testing"
     7  
     8  	"get.porter.sh/porter/pkg/porter"
     9  	"github.com/stretchr/testify/assert"
    10  	"github.com/stretchr/testify/require"
    11  )
    12  
    13  func TestCompletion(t *testing.T) {
    14  	p := buildRootCommand()
    15  
    16  	// Capture the output of the command.
    17  	var out bytes.Buffer
    18  	p.SetOut(&out)
    19  
    20  	// Run the initial completion command with a bash example.
    21  	os.Args = []string{"porter", "completion", "bash"}
    22  
    23  	err := p.Execute()
    24  	require.NoError(t, err)
    25  	// Test the output of the command contains a specific string for bash.
    26  	assert.Contains(t, out.String(), "bash completion for porter")
    27  }
    28  
    29  func TestCompletion_SkipConfig(t *testing.T) {
    30  	p := porter.NewTestPorter(t)
    31  	cmd := buildCompletionCommand(p.Porter)
    32  	shouldSkip := shouldSkipConfig(cmd)
    33  	require.True(t, shouldSkip, "expected that we skip loading configuration for the completion command")
    34  }