Ejemplo n.º 1
0
func TestTraceSetToFile(t *testing.T) {
	stdOut := bytes.NewBuffer([]byte{})
	trace.SetStdout(stdOut)

	fileutils.TempFile("trace_test", func(file *os.File, err error) {
		assert.NoError(t, err)
		file.Write([]byte("pre-existing content"))

		os.Setenv(trace.CF_TRACE, file.Name())

		logger := trace.NewLogger()
		logger.Print("hello world")

		file.Seek(0, os.SEEK_SET)
		result, err := ioutil.ReadAll(file)
		assert.NoError(t, err)

		byteString := string(result)
		assert.Contains(t, byteString, "pre-existing content")
		assert.Contains(t, byteString, "hello world")

		result, _ = ioutil.ReadAll(stdOut)
		assert.Equal(t, string(result), "")
	})
}
Ejemplo n.º 2
0
func TestTraceSetToTrue(t *testing.T) {
	stdOut := bytes.NewBuffer([]byte{})
	trace.SetStdout(stdOut)

	os.Setenv(trace.CF_TRACE, "true")

	logger := trace.NewLogger()
	logger.Print("hello world")

	result, _ := ioutil.ReadAll(stdOut)
	assert.Contains(t, string(result), "hello world")
}
Ejemplo n.º 3
0
func TestTraceSetToInvalidFile(t *testing.T) {
	stdOut := bytes.NewBuffer([]byte{})
	trace.SetStdout(stdOut)

	fileutils.TempFile("trace_test", func(file *os.File, err error) {
		assert.NoError(t, err)

		file.Chmod(0000)

		os.Setenv(trace.CF_TRACE, file.Name())

		logger := trace.NewLogger()
		logger.Print("hello world")

		result, _ := ioutil.ReadAll(file)
		assert.Equal(t, string(result), "")

		result, _ = ioutil.ReadAll(stdOut)
		assert.Contains(t, string(result), "hello world")
	})
}
Ejemplo n.º 4
0
	"github.com/cloudfoundry/gofileutils/fileutils"
	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
	"io/ioutil"
	"os"
	"runtime"
)

var _ = Describe("Testing with ginkgo", func() {
	It("TestTraceSetToFalse", func() {
		stdOut := bytes.NewBuffer([]byte{})
		trace.SetStdout(stdOut)

		os.Setenv(trace.CF_TRACE, "false")

		logger := trace.NewLogger()
		logger.Print("hello world")

		result, _ := ioutil.ReadAll(stdOut)
		Expect(string(result)).To(Equal(""))
	})

	It("TestTraceSetToTrue", func() {
		stdOut := bytes.NewBuffer([]byte{})
		trace.SetStdout(stdOut)

		os.Setenv(trace.CF_TRACE, "true")

		logger := trace.NewLogger()
		logger.Print("hello world")