mirror of https://github.com/pulumi/pulumi.git
57 lines
1.5 KiB
Go
57 lines
1.5 KiB
Go
// Copyright 2016-2017, Pulumi Corporation. All rights reserved.
|
|
|
|
package integration
|
|
|
|
import (
|
|
"bytes"
|
|
"io/ioutil"
|
|
"os"
|
|
"os/exec"
|
|
"path/filepath"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
"github.com/pulumi/pulumi/pkg/util/contract"
|
|
)
|
|
|
|
func TestPrefixer(t *testing.T) {
|
|
byts := make([]byte, 0, 1000)
|
|
buf := bytes.NewBuffer(byts)
|
|
prefixer := newPrefixer(buf, "OK: ")
|
|
_, err := prefixer.Write([]byte("\nsadsada\n\nasdsadsa\nasdsadsa\n"))
|
|
contract.AssertNoError(err)
|
|
assert.Equal(t, []byte("OK: \nOK: sadsada\nOK: \nOK: asdsadsa\nOK: asdsadsa\n"), buf.Bytes())
|
|
}
|
|
|
|
// Test that RunCommand writes the command's output to a log file.
|
|
func TestRunCommandLog(t *testing.T) {
|
|
// Try to find node on the path. We need a program to run, and node is probably
|
|
// available on all platforms where we're testing. If it's not found, skip the test.
|
|
node, err := exec.LookPath("node")
|
|
if err != nil {
|
|
t.Skip("Couldn't find Node on PATH")
|
|
}
|
|
|
|
opts := &ProgramTestOptions{
|
|
Stdout: os.Stdout,
|
|
Stderr: os.Stderr,
|
|
}
|
|
|
|
tempdir, err := ioutil.TempDir("", "test")
|
|
contract.AssertNoError(err)
|
|
defer os.RemoveAll(tempdir)
|
|
|
|
args := []string{node, "-e", "console.log('output from node');"}
|
|
err = RunCommand(nil, "node", args, tempdir, opts)
|
|
assert.Nil(t, err)
|
|
|
|
matches, err := filepath.Glob(filepath.Join(tempdir, "command-output", "node.*"))
|
|
assert.Nil(t, err)
|
|
assert.Equal(t, 1, len(matches))
|
|
|
|
output, err := ioutil.ReadFile(matches[0])
|
|
assert.Nil(t, err)
|
|
assert.Equal(t, "output from node\n", string(output))
|
|
}
|