packer.Ui tests
This commit is contained in:
parent
db1c11fff5
commit
ca93f645be
5
Makefile
5
Makefile
|
@ -3,4 +3,7 @@ all:
|
|||
go get -d
|
||||
go build -a -o bin/packer
|
||||
|
||||
.PHONY: all
|
||||
test:
|
||||
go test ./...
|
||||
|
||||
.PHONY: all test
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
package packer
|
||||
|
||||
|
|
@ -0,0 +1,29 @@
|
|||
package packer
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"testing"
|
||||
"cgl.tideland.biz/asserts"
|
||||
)
|
||||
|
||||
// Our test Ui that just writes to bytes.Buffers.
|
||||
var bufferUi = &ReaderWriterUi{ new(bytes.Buffer), new(bytes.Buffer) }
|
||||
|
||||
func TestReaderWriterUi_Say(t *testing.T) {
|
||||
assert := asserts.NewTestingAsserts(t, true)
|
||||
|
||||
bufferUi.Say("foo")
|
||||
assert.Equal(readWriter(bufferUi), "foo", "basic output")
|
||||
|
||||
bufferUi.Say("%d", 5)
|
||||
assert.Equal(readWriter(bufferUi), "5", "formatting")
|
||||
}
|
||||
|
||||
// This reads the output from the bytes.Buffer in our test object
|
||||
// and then resets the buffer.
|
||||
func readWriter(ui *ReaderWriterUi) (result string) {
|
||||
buffer := ui.Writer.(*bytes.Buffer)
|
||||
result = buffer.String()
|
||||
buffer.Reset()
|
||||
return
|
||||
}
|
Loading…
Reference in New Issue