get.porter.sh/porter@v1.3.0/tests/integration/agent_integration_test.go (about) 1 //go:build integration 2 3 package integration 4 5 import ( 6 "bytes" 7 "os" 8 "path/filepath" 9 "runtime" 10 "testing" 11 12 "get.porter.sh/porter/pkg/agent" 13 "github.com/stretchr/testify/assert" 14 "github.com/stretchr/testify/require" 15 "github.com/uwu-tools/magex/shx" 16 ) 17 18 func TestExecute(t *testing.T) { 19 home := makeTestPorterHome(t) 20 defer os.RemoveAll(home) 21 cfg := "testdata" 22 23 stdoutBuff := &bytes.Buffer{} 24 stderrBuff := &bytes.Buffer{} 25 agent.Stdout = stdoutBuff 26 agent.Stderr = stderrBuff 27 28 err, run := agent.Execute([]string{"help"}, home, cfg) 29 require.NoError(t, err) 30 assert.True(t, run, "porter should have run") 31 gotStderr := stderrBuff.String() 32 assert.Contains(t, gotStderr, "porter version", "the agent should always print the porter CLI version") 33 assert.Contains(t, stdoutBuff.String(), "Usage:", "porter command output should be printed") 34 35 _, err = os.ReadFile(filepath.Join(home, "config.toml")) 36 require.NoError(t, err) 37 38 _, err = os.ReadFile(filepath.Join(home, "config.json")) 39 require.NoError(t, err) 40 41 _, err = os.ReadFile(filepath.Join(home, "a-binary")) 42 require.NoError(t, err) 43 44 _, err = os.Stat(filepath.Join(home, ".hidden")) 45 require.True(t, os.IsNotExist(err), "hidden files should not be copied") 46 } 47 48 func makeTestPorterHome(t *testing.T) string { 49 home, err := os.MkdirTemp("", "porter-home") 50 require.NoError(t, err) 51 porter_binary := "../../bin/porter" 52 if runtime.GOOS == "windows" { 53 porter_binary += ".exe" 54 } 55 require.NoError(t, shx.Copy(porter_binary, home)) 56 return home 57 }