github.com/makyo/juju@v0.0.0-20160425123129-2608902037e9/api/migrationtarget/client_test.go (about) 1 // Copyright 2016 Canonical Ltd. 2 // Licensed under the AGPLv3, see LICENCE file for details. 3 4 package migrationtarget_test 5 6 import ( 7 "github.com/juju/errors" 8 "github.com/juju/names" 9 jujutesting "github.com/juju/testing" 10 gc "gopkg.in/check.v1" 11 12 apitesting "github.com/juju/juju/api/base/testing" 13 "github.com/juju/juju/api/migrationtarget" 14 "github.com/juju/juju/apiserver/params" 15 ) 16 17 type ClientSuite struct { 18 jujutesting.IsolationSuite 19 } 20 21 var _ = gc.Suite(&ClientSuite{}) 22 23 func (s *ClientSuite) getClientAndStub(c *gc.C) (migrationtarget.Client, *jujutesting.Stub) { 24 var stub jujutesting.Stub 25 apiCaller := apitesting.APICallerFunc(func(objType string, version int, id, request string, arg, result interface{}) error { 26 stub.AddCall(objType+"."+request, id, arg) 27 return errors.New("boom") 28 }) 29 client := migrationtarget.NewClient(apiCaller) 30 return client, &stub 31 } 32 33 func (s *ClientSuite) TestImport(c *gc.C) { 34 client, stub := s.getClientAndStub(c) 35 36 err := client.Import([]byte("foo")) 37 38 expectedArg := params.SerializedModel{Bytes: []byte("foo")} 39 stub.CheckCalls(c, []jujutesting.StubCall{ 40 {"MigrationTarget.Import", []interface{}{"", expectedArg}}, 41 }) 42 c.Assert(err, gc.ErrorMatches, "boom") 43 } 44 45 func (s *ClientSuite) TestAbort(c *gc.C) { 46 client, stub := s.getClientAndStub(c) 47 48 uuid := "fake" 49 err := client.Abort(uuid) 50 s.AssertModelCall(c, stub, names.NewModelTag(uuid), "Abort", err) 51 } 52 53 func (s *ClientSuite) TestActivate(c *gc.C) { 54 client, stub := s.getClientAndStub(c) 55 56 uuid := "fake" 57 err := client.Activate(uuid) 58 s.AssertModelCall(c, stub, names.NewModelTag(uuid), "Activate", err) 59 } 60 61 func (s *ClientSuite) AssertModelCall(c *gc.C, stub *jujutesting.Stub, tag names.ModelTag, call string, err error) { 62 expectedArg := params.ModelArgs{ModelTag: tag.String()} 63 stub.CheckCalls(c, []jujutesting.StubCall{ 64 {"MigrationTarget." + call, []interface{}{"", expectedArg}}, 65 }) 66 c.Assert(err, gc.ErrorMatches, "boom") 67 }