github.com/engineyard/workflow-cli@v2.21.6+incompatible/parser/timeouts_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) TimeoutsList(string) error {
    16    return errors.New("timeouts:list")
    17  }
    18  
    19  func (d FakeDeisCmd) TimeoutsSet(string, []string) error {
    20    return errors.New("timeouts:set")
    21  }
    22  
    23  func (d FakeDeisCmd) TimeoutsUnset(string, []string) error {
    24    return errors.New("timeouts:unset")
    25  }
    26  
    27  func TestTimeouts(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{"timeouts:list"},
    46        expected: "",
    47      },
    48      {
    49        args:     []string{"timeouts:set", "web=100"},
    50        expected: "",
    51      },
    52      {
    53        args:     []string{"timeouts:set", "web=100 worker=200"},
    54        expected: "",
    55      },
    56      {
    57        args:     []string{"timeouts:unset", "web"},
    58        expected: "",
    59      },
    60      {
    61        args:     []string{"timeouts"},
    62        expected: "timeouts:list",
    63      },
    64    }
    65  
    66    // For each case, check that calling the route with the arguments
    67    // returns the expected error, which is args[0] if not provided.
    68    for _, c := range cases {
    69      var expected string
    70      if c.expected == "" {
    71        expected = c.args[0]
    72      } else {
    73        expected = c.expected
    74      }
    75      err = Timeouts(c.args, cmdr)
    76      assert.Err(t, errors.New(expected), err)
    77    }
    78  }