github.com/engineyard/workflow-cli@v2.21.6+incompatible/parser/git_test.go (about)

     1  package parser
     2  
     3  import (
     4  	"bytes"
     5  	"errors"
     6  	"testing"
     7  
     8  	"github.com/arschles/assert"
     9  	"github.com/teamhephy/workflow-cli/pkg/testutil"
    10  )
    11  
    12  // Create fake implementations of each method that return the argument
    13  // we expect to have called the function (as an error to satisfy the interface).
    14  
    15  func (d FakeDeisCmd) GitRemote(string, string, bool) error {
    16  	return errors.New("git:remote")
    17  }
    18  
    19  func (d FakeDeisCmd) GitRemove(string) error {
    20  	return errors.New("git:remove")
    21  }
    22  
    23  func TestGit(t *testing.T) {
    24  	t.Parallel()
    25  
    26  	cf, server, err := testutil.NewTestServerAndClient()
    27  	if err != nil {
    28  		t.Fatal(err)
    29  	}
    30  	defer server.Close()
    31  	var b bytes.Buffer
    32  	cmdr := FakeDeisCmd{WOut: &b, ConfigFile: cf}
    33  
    34  	// cases defines the arguments and expected return of the call.
    35  	// if expected is "", it defaults to args[0].
    36  	cases := []struct {
    37  		args     []string
    38  		expected string
    39  	}{
    40  		{
    41  			args:     []string{"git:remote"},
    42  			expected: "",
    43  		},
    44  		{
    45  			args:     []string{"git:remove"},
    46  			expected: "",
    47  		},
    48  	}
    49  
    50  	// For each case, check that calling the route with the arguments
    51  	// returns the expected error, which is args[0] if not provided.
    52  	for _, c := range cases {
    53  		var expected string
    54  		if c.expected == "" {
    55  			expected = c.args[0]
    56  		} else {
    57  			expected = c.expected
    58  		}
    59  		err = Git(c.args, cmdr)
    60  		assert.Err(t, errors.New(expected), err)
    61  	}
    62  }