github.com/engineyard/workflow-cli@v2.21.6+incompatible/parser/version_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) Version(bool) error {
    16  	return errors.New("version")
    17  }
    18  
    19  func TestVersion(t *testing.T) {
    20  	t.Parallel()
    21  
    22  	cf, server, err := testutil.NewTestServerAndClient()
    23  	if err != nil {
    24  		t.Fatal(err)
    25  	}
    26  	defer server.Close()
    27  	var b bytes.Buffer
    28  	cmdr := FakeDeisCmd{WOut: &b, ConfigFile: cf}
    29  
    30  	// cases defines the arguments and expected return of the call.
    31  	// if expected is "", it defaults to args[0].
    32  	cases := []struct {
    33  		args     []string
    34  		expected string
    35  	}{
    36  		{
    37  			args:     []string{"version"},
    38  			expected: "",
    39  		},
    40  	}
    41  
    42  	// For each case, check that calling the route with the arguments
    43  	// returns the expected error, which is args[0] if not provided.
    44  	for _, c := range cases {
    45  		var expected string
    46  		if c.expected == "" {
    47  			expected = c.args[0]
    48  		} else {
    49  			expected = c.expected
    50  		}
    51  		err = Version(c.args, cmdr)
    52  		assert.Err(t, errors.New(expected), err)
    53  	}
    54  }