github.com/niedbalski/juju@v0.0.0-20190215020005-8ff100488e47/api/resumer/resumer_test.go (about) 1 // Copyright 2015 Canonical Ltd. 2 // Licensed under the AGPLv3, see LICENCE file for details. 3 4 package resumer_test 5 6 import ( 7 "errors" 8 9 jc "github.com/juju/testing/checkers" 10 gc "gopkg.in/check.v1" 11 12 apitesting "github.com/juju/juju/api/base/testing" 13 "github.com/juju/juju/api/resumer" 14 coretesting "github.com/juju/juju/testing" 15 ) 16 17 type ResumerSuite struct { 18 coretesting.BaseSuite 19 } 20 21 var _ = gc.Suite(&ResumerSuite{}) 22 23 func (s *ResumerSuite) TestResumeTransactionsSuccess(c *gc.C) { 24 var callCount int 25 apiCaller := apitesting.APICallerFunc( 26 func(objType string, version int, id, request string, args, results interface{}) error { 27 c.Check(objType, gc.Equals, "Resumer") 28 // Since we're not logging in and getting the supported 29 // facades and their versions, the client will always send 30 // version 0. 31 c.Check(version, gc.Equals, 0) 32 c.Check(id, gc.Equals, "") 33 c.Check(request, gc.Equals, "ResumeTransactions") 34 c.Check(args, gc.IsNil) 35 c.Check(results, gc.IsNil) 36 callCount++ 37 return nil 38 }, 39 ) 40 41 st := resumer.NewAPI(apiCaller) 42 err := st.ResumeTransactions() 43 c.Check(err, jc.ErrorIsNil) 44 c.Check(callCount, gc.Equals, 1) 45 } 46 47 func (s *ResumerSuite) TestResumeTransactionsFailure(c *gc.C) { 48 var callCount int 49 apiCaller := apitesting.APICallerFunc( 50 func(_ string, _ int, _, _ string, _, _ interface{}) error { 51 callCount++ 52 return errors.New("boom!") 53 }, 54 ) 55 56 st := resumer.NewAPI(apiCaller) 57 err := st.ResumeTransactions() 58 c.Check(err, gc.ErrorMatches, "boom!") 59 c.Check(callCount, gc.Equals, 1) 60 }