github.com/dacamp/packer@v0.10.2/provisioner/shell/unix_reader_test.go (about) 1 package shell 2 3 import ( 4 "bytes" 5 "io" 6 "testing" 7 ) 8 9 func TestUnixReader_impl(t *testing.T) { 10 var raw interface{} 11 raw = new(UnixReader) 12 if _, ok := raw.(io.Reader); !ok { 13 t.Fatal("should be reader") 14 } 15 } 16 17 func TestUnixReader(t *testing.T) { 18 input := "one\r\ntwo\n\r\nthree\r\n" 19 expected := "one\ntwo\n\nthree\n" 20 21 unixReaderTest(t, input, expected) 22 } 23 24 func TestUnixReader_unixOnly(t *testing.T) { 25 input := "\none\n\ntwo\nthree\n\n" 26 expected := "\none\n\ntwo\nthree\n\n" 27 28 unixReaderTest(t, input, expected) 29 } 30 31 func TestUnixReader_readsLastLine(t *testing.T) { 32 input := "one\ntwo" 33 expected := "one\ntwo\n" 34 35 unixReaderTest(t, input, expected) 36 } 37 38 func unixReaderTest(t *testing.T, input string, expected string) { 39 r := &UnixReader{ 40 Reader: bytes.NewReader([]byte(input)), 41 } 42 43 result := new(bytes.Buffer) 44 if _, err := io.Copy(result, r); err != nil { 45 t.Fatalf("err: %s", err) 46 } 47 48 if result.String() != expected { 49 t.Fatalf("bad: %#v", result.String()) 50 } 51 }