get.porter.sh/porter@v1.3.0/pkg/exec/execute_test.go (about)

     1  package exec
     2  
     3  import (
     4  	"bytes"
     5  	"context"
     6  	"os"
     7  	"testing"
     8  
     9  	"get.porter.sh/porter/pkg"
    10  	"get.porter.sh/porter/pkg/test"
    11  	"github.com/stretchr/testify/assert"
    12  	"github.com/stretchr/testify/require"
    13  )
    14  
    15  func TestMixin_Execute(t *testing.T) {
    16  	ctx := context.Background()
    17  	m := NewTestMixin(t)
    18  
    19  	err := m.Config.FileSystem.WriteFile("config.txt", []byte("abc123"), pkg.FileModeWritable)
    20  	require.NoError(t, err)
    21  
    22  	stdin, err := os.ReadFile("testdata/outputs.yaml")
    23  	require.NoError(t, err)
    24  	m.Config.In = bytes.NewBuffer(stdin)
    25  
    26  	m.Config.Setenv(test.ExpectedCommandEnv, "foo")
    27  
    28  	err = m.Execute(ctx, ExecuteOptions{})
    29  	require.NoError(t, err, "Execute should not have returned an error")
    30  
    31  	exists, _ := m.Config.FileSystem.Exists("/cnab/app/porter/outputs/file")
    32  	assert.True(t, exists, "file output was not evaluated")
    33  
    34  	exists, _ = m.Config.FileSystem.Exists("/cnab/app/porter/outputs/regex")
    35  	assert.True(t, exists, "regex output was not evaluated")
    36  
    37  	exists, _ = m.Config.FileSystem.Exists("/cnab/app/porter/outputs/jsonpath")
    38  	assert.True(t, exists, "jsonpath output was not evaluated")
    39  }