github.com/drone/runner-go@v1.12.0/pipeline/streamer/console/pretty_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 TestPretty(t *testing.T) {
    15  	buf := new(bytes.Buffer)
    16  
    17  	sess := New(true)
    18  	w := sess.Stream(nil, nil, "clone").(*pretty)
    19  	w.base = buf
    20  	w.Write([]byte("hello\nworld"))
    21  	w.Close()
    22  
    23  	got, want := buf.String(), "\x1b[33m[clone:1]\x1b[0m hello\n\x1b[33m[clone:2]\x1b[0m world\n"
    24  	if diff := cmp.Diff(got, want); diff != "" {
    25  		t.Errorf("Invalid plain text log output")
    26  		t.Log(diff)
    27  	}
    28  }