github.com/engineyard/workflow-cli@v2.21.6+incompatible/parser/limits_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) LimitsList(string) error {
    16  	return errors.New("limits:list")
    17  }
    18  
    19  func (d FakeDeisCmd) LimitsSet(string, []string, string) error {
    20  	return errors.New("limits:set")
    21  }
    22  
    23  func (d FakeDeisCmd) LimitsUnset(string, []string, string) error {
    24  	return errors.New("limits:unset")
    25  }
    26  
    27  func TestLimits(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{"limits:list"},
    46  			expected: "",
    47  		},
    48  		{
    49  			args:     []string{"limits:set", "web=1G"},
    50  			expected: "",
    51  		},
    52  		{
    53  			args:     []string{"limits:set", "web=1G worker=2G"},
    54  			expected: "",
    55  		},
    56  		{
    57  			args:     []string{"limits:set", "web=1G/2G worker=2G/4G"},
    58  			expected: "",
    59  		},
    60  		{
    61  			args:     []string{"limits:set", "--cpu", "web=1"},
    62  			expected: "",
    63  		},
    64  		{
    65  			args:     []string{"limits:unset", "web"},
    66  			expected: "",
    67  		},
    68  		{
    69  			args:     []string{"limits:unset", "--cpu", "web"},
    70  			expected: "",
    71  		},
    72  		{
    73  			args:     []string{"limits"},
    74  			expected: "limits:list",
    75  		},
    76  	}
    77  
    78  	// For each case, check that calling the route with the arguments
    79  	// returns the expected error, which is args[0] if not provided.
    80  	for _, c := range cases {
    81  		var expected string
    82  		if c.expected == "" {
    83  			expected = c.args[0]
    84  		} else {
    85  			expected = c.expected
    86  		}
    87  		err = Limits(c.args, cmdr)
    88  		assert.Err(t, errors.New(expected), err)
    89  	}
    90  }