github.com/loggregator/cli@v6.33.1-0.20180224010324-82334f081791+incompatible/cf/trace/combined_printer_test.go (about)

     1  package trace_test
     2  
     3  import (
     4  	. "code.cloudfoundry.org/cli/cf/trace"
     5  
     6  	"code.cloudfoundry.org/cli/cf/trace/tracefakes"
     7  
     8  	. "github.com/onsi/ginkgo"
     9  	. "github.com/onsi/gomega"
    10  )
    11  
    12  var _ = Describe("CombinePrinters", func() {
    13  	var printer1, printer2 *tracefakes.FakePrinter
    14  	var printer Printer
    15  
    16  	BeforeEach(func() {
    17  		printer1 = new(tracefakes.FakePrinter)
    18  		printer2 = new(tracefakes.FakePrinter)
    19  
    20  		printer = CombinePrinters([]Printer{printer1, printer2})
    21  	})
    22  
    23  	It("returns a combined printer that Prints", func() {
    24  		printer.Print("foo", "bar")
    25  
    26  		Expect(printer1.PrintCallCount()).To(Equal(1))
    27  		Expect(printer2.PrintCallCount()).To(Equal(1))
    28  
    29  		expectedArgs := []interface{}{"foo", "bar"}
    30  
    31  		Expect(printer1.PrintArgsForCall(0)).To(Equal(expectedArgs))
    32  		Expect(printer2.PrintArgsForCall(0)).To(Equal(expectedArgs))
    33  	})
    34  
    35  	It("returns a combined printer that Printfs", func() {
    36  		printer.Printf("format %s %s", "arg1", "arg2")
    37  
    38  		Expect(printer1.PrintfCallCount()).To(Equal(1))
    39  		Expect(printer2.PrintfCallCount()).To(Equal(1))
    40  
    41  		expectedArgs := []interface{}{"arg1", "arg2"}
    42  
    43  		fmt1, args1 := printer1.PrintfArgsForCall(0)
    44  		fmt2, args2 := printer2.PrintfArgsForCall(0)
    45  
    46  		Expect(fmt1).To(Equal("format %s %s"))
    47  		Expect(fmt2).To(Equal("format %s %s"))
    48  
    49  		Expect(args1).To(Equal(expectedArgs))
    50  		Expect(args2).To(Equal(expectedArgs))
    51  	})
    52  
    53  	It("returns a combined printer that Printlns", func() {
    54  		printer.Println("foo", "bar")
    55  
    56  		Expect(printer1.PrintlnCallCount()).To(Equal(1))
    57  		Expect(printer2.PrintlnCallCount()).To(Equal(1))
    58  
    59  		expectedArgs := []interface{}{"foo", "bar"}
    60  
    61  		Expect(printer1.PrintlnArgsForCall(0)).To(Equal(expectedArgs))
    62  		Expect(printer2.PrintlnArgsForCall(0)).To(Equal(expectedArgs))
    63  	})
    64  })