github.com/engineyard/workflow-cli@v2.21.6+incompatible/parser/routing_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) RoutingInfo(string) error {
    16  	return errors.New("routing:info")
    17  }
    18  
    19  func (d FakeDeisCmd) RoutingEnable(string) error {
    20  	return errors.New("routing:enable")
    21  }
    22  
    23  func (d FakeDeisCmd) RoutingDisable(string) error {
    24  	return errors.New("routing:disable")
    25  }
    26  
    27  func TestRouting(t *testing.T) {
    28  	t.Parallel()
    29  
    30  	cf, server, err := testutil.NewTestServerAndClient()
    31  	if err != nil {
    32  		t.Fatal(err)
    33  	}
    34  	defer server.Close()
    35  	var b bytes.Buffer
    36  	cmdr := FakeDeisCmd{WOut: &b, ConfigFile: cf}
    37  
    38  	// cases defines the arguments and expected return of the call.
    39  	// if expected is "", it defaults to args[0].
    40  	cases := []struct {
    41  		args     []string
    42  		expected string
    43  	}{
    44  		{
    45  			args:     []string{"routing:info"},
    46  			expected: "",
    47  		},
    48  		{
    49  			args:     []string{"routing:enable"},
    50  			expected: "",
    51  		},
    52  		{
    53  			args:     []string{"routing:disable"},
    54  			expected: "",
    55  		},
    56  		{
    57  			args:     []string{"routing"},
    58  			expected: "routing:info",
    59  		},
    60  	}
    61  
    62  	// For each case, check that calling the route with the arguments
    63  	// returns the expected error, which is args[0] if not provided.
    64  	for _, c := range cases {
    65  		var expected string
    66  		if c.expected == "" {
    67  			expected = c.args[0]
    68  		} else {
    69  			expected = c.expected
    70  		}
    71  		err = Routing(c.args, cmdr)
    72  		assert.Err(t, errors.New(expected), err)
    73  	}
    74  }