github.com/drone/runner-go@v1.12.0/pipeline/streamer/console/plain_test.go (about) 1 // Copyright 2019 Drone.IO Inc. All rights reserved. 2 // Use of this source code is governed by the Polyform License 3 // that can be found in the LICENSE file. 4 5 package console 6 7 import ( 8 "bytes" 9 "testing" 10 11 "github.com/google/go-cmp/cmp" 12 ) 13 14 func TestPlain(t *testing.T) { 15 buf := new(bytes.Buffer) 16 17 sess := New(false) 18 w := sess.Stream(nil, nil, "clone").(*plain) 19 w.base = buf 20 w.Write([]byte("hello\nworld")) 21 w.Close() 22 23 got, want := buf.String(), "[clone:1] hello\n[clone:2] world\n" 24 if diff := cmp.Diff(got, want); diff != "" { 25 t.Errorf("Invalid plain text log output") 26 t.Log(diff) 27 } 28 } 29 30 func TestSplit(t *testing.T) { 31 tests := []struct { 32 before string 33 after []string 34 }{ 35 { 36 before: "hello world", 37 after: []string{"hello world"}, 38 }, 39 { 40 before: "hello world\n", 41 after: []string{"hello world"}, 42 }, 43 { 44 before: "hello\nworld\n", 45 after: []string{"hello", "world"}, 46 }, 47 { 48 before: "hello\n\nworld\n", 49 after: []string{"hello", "", "world"}, 50 }, 51 { 52 before: "\nhello\n\nworld\n", 53 after: []string{"", "hello", "", "world"}, 54 }, 55 { 56 before: "\n", 57 after: []string{""}, 58 }, 59 { 60 before: "\n\n", 61 after: []string{"", ""}, 62 }, 63 } 64 for _, test := range tests { 65 b := []byte(test.before) 66 got, want := split(b), test.after 67 if diff := cmp.Diff(got, want); diff != "" { 68 t.Errorf("Invalid split") 69 t.Log(diff) 70 } 71 } 72 }