github.com/tsuyoshiwada/git-prout@v0.0.0-20170402150409-5c51421d4bdb/cli_test.go (about)

     1  package main
     2  
     3  import (
     4  	"bytes"
     5  	"strings"
     6  	"testing"
     7  )
     8  
     9  func newTestCLI() (*CLI, *bytes.Buffer, *bytes.Buffer) {
    10  	outStream, errStream := new(bytes.Buffer), new(bytes.Buffer)
    11  	terminate := func(status int) {}
    12  	cli := &CLI{outStream: outStream, errStream: errStream, terminate: terminate}
    13  	return cli, outStream, errStream
    14  }
    15  
    16  func prout(command string) []string {
    17  	return append([]string{"git-prout"}, strings.Split(command, " ")...)
    18  }
    19  
    20  // FIXME: fetch PR tests...
    21  
    22  func TestCLIRun_InvalidRemote(t *testing.T) {
    23  	reset := createTestRepo()
    24  	defer reset()
    25  
    26  	cli, _, errStream := newTestCLI()
    27  	cli.Run(prout("--remote foo 10"))
    28  
    29  	if got, want := errStream.String(), "'foo' is invalid"; !strings.Contains(got, want) {
    30  		t.Fatalf("Run output %q want %q", got, want)
    31  	}
    32  }
    33  
    34  func TestCLIRun_VersionFlag(t *testing.T) {
    35  	cli, _, errStream := newTestCLI()
    36  	cli.Run(prout("--version"))
    37  
    38  	if got, want := errStream.String(), Version; got == want {
    39  		t.Fatalf("Run output %q want %q", got, want)
    40  	}
    41  }