github.com/makyo/juju@v0.0.0-20160425123129-2608902037e9/cmd/juju/user/user_test.go (about)

     1  // Copyright 2014 Canonical Ltd.
     2  // Licensed under the AGPLv3, see LICENCE file for details.
     3  
     4  package user_test
     5  
     6  import (
     7  	jc "github.com/juju/testing/checkers"
     8  	gc "gopkg.in/check.v1"
     9  	"gopkg.in/macaroon.v1"
    10  
    11  	"github.com/juju/juju/cmd/modelcmd"
    12  	"github.com/juju/juju/jujuclient"
    13  	"github.com/juju/juju/jujuclient/jujuclienttesting"
    14  	"github.com/juju/juju/testing"
    15  )
    16  
    17  type BaseSuite struct {
    18  	testing.FakeJujuXDGDataHomeSuite
    19  	store *jujuclienttesting.MemStore
    20  }
    21  
    22  func (s *BaseSuite) SetUpTest(c *gc.C) {
    23  	s.FakeJujuXDGDataHomeSuite.SetUpTest(c)
    24  	err := modelcmd.WriteCurrentController("testing")
    25  	c.Assert(err, jc.ErrorIsNil)
    26  
    27  	s.store = jujuclienttesting.NewMemStore()
    28  	s.store.Controllers["testing"] = jujuclient.ControllerDetails{
    29  		APIEndpoints:   []string{"127.0.0.1:12345"},
    30  		CACert:         testing.CACert,
    31  		ControllerUUID: testing.ModelTag.Id(),
    32  	}
    33  	s.store.Accounts["testing"] = &jujuclient.ControllerAccounts{
    34  		Accounts: map[string]jujuclient.AccountDetails{
    35  			"current-user@local": {
    36  				User:     "current-user@local",
    37  				Password: "old-password",
    38  			},
    39  		},
    40  		CurrentAccount: "current-user@local",
    41  	}
    42  }
    43  
    44  func (s *BaseSuite) assertStorePassword(c *gc.C, user, pass string) {
    45  	details, err := s.store.AccountByName("testing", user)
    46  	c.Assert(err, jc.ErrorIsNil)
    47  	c.Assert(details.Password, gc.Equals, pass)
    48  }
    49  
    50  func (s *BaseSuite) assertStoreMacaroon(c *gc.C, user string, mac *macaroon.Macaroon) {
    51  	details, err := s.store.AccountByName("testing", user)
    52  	c.Assert(err, jc.ErrorIsNil)
    53  	if mac == nil {
    54  		c.Assert(details.Macaroon, gc.Equals, "")
    55  		return
    56  	}
    57  	macaroonJSON, err := mac.MarshalJSON()
    58  	c.Assert(err, jc.ErrorIsNil)
    59  	c.Assert(details.Macaroon, gc.Equals, string(macaroonJSON))
    60  }