github.com/engineyard/workflow-cli@v2.21.6+incompatible/parser/auth_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) Register(string, string, string, string, bool, bool) error {
    16  	return errors.New("auth:register")
    17  }
    18  
    19  func (d FakeDeisCmd) Login(string, string, string, bool) error {
    20  	return errors.New("auth:login")
    21  }
    22  
    23  func (d FakeDeisCmd) Logout() error {
    24  	return errors.New("auth:logout")
    25  }
    26  
    27  func (d FakeDeisCmd) Passwd(string, string, string) error {
    28  	return errors.New("auth:passwd")
    29  }
    30  
    31  func (d FakeDeisCmd) Cancel(string, string, bool) error {
    32  	return errors.New("auth:cancel")
    33  }
    34  
    35  func (d FakeDeisCmd) Whoami(bool) error {
    36  	return errors.New("auth:whoami")
    37  }
    38  
    39  func (d FakeDeisCmd) Regenerate(string, bool) error {
    40  	return errors.New("auth:regenerate")
    41  }
    42  
    43  func TestAuth(t *testing.T) {
    44  	t.Parallel()
    45  
    46  	cf, server, err := testutil.NewTestServerAndClient()
    47  	if err != nil {
    48  		t.Fatal(err)
    49  	}
    50  	defer server.Close()
    51  	var b bytes.Buffer
    52  	cmdr := FakeDeisCmd{WOut: &b, ConfigFile: cf}
    53  
    54  	// cases defines the arguments and expected return of the call.
    55  	// if expected is "", it defaults to args[0].
    56  	cases := []struct {
    57  		args     []string
    58  		expected string
    59  	}{
    60  		{
    61  			args:     []string{"auth:register", server.Server.URL},
    62  			expected: "",
    63  		},
    64  		{
    65  			args:     []string{"auth:register", server.Server.URL, "--ssl-verify=true"},
    66  			expected: "",
    67  		},
    68  		{
    69  			args:     []string{"auth:register", server.Server.URL, "--login=false"},
    70  			expected: "",
    71  		},
    72  		{
    73  			args:     []string{"auth:login", server.Server.URL},
    74  			expected: "",
    75  		},
    76  		{
    77  			args:     []string{"auth:login", server.Server.URL, "--ssl-verify=true"},
    78  			expected: "",
    79  		},
    80  		{
    81  			args:     []string{"auth:logout"},
    82  			expected: "",
    83  		},
    84  		{
    85  			args:     []string{"auth:passwd"},
    86  			expected: "",
    87  		},
    88  		{
    89  			args:     []string{"auth:whoami"},
    90  			expected: "",
    91  		},
    92  		{
    93  			args:     []string{"auth:cancel"},
    94  			expected: "",
    95  		},
    96  		{
    97  			args:     []string{"auth:regenerate"},
    98  			expected: "",
    99  		},
   100  	}
   101  
   102  	// For each case, check that calling the route with the arguments
   103  	// returns the expected error, which is args[0] if not provided.
   104  	for _, c := range cases {
   105  		var expected string
   106  		if c.expected == "" {
   107  			expected = c.args[0]
   108  		} else {
   109  			expected = c.expected
   110  		}
   111  		err = Auth(c.args, cmdr)
   112  		assert.Err(t, errors.New(expected), err)
   113  	}
   114  }