forked from juju/juju
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclient_test.go
58 lines (47 loc) · 2 KB
/
client_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
// Copyright 2018 Canonical Ltd.
// Licensed under the AGPLv3, see LICENCE file for details.
package credentialmanager_test
import (
"github.com/juju/errors"
"github.com/juju/testing"
jc "github.com/juju/testing/checkers"
gc "gopkg.in/check.v1"
apitesting "github.com/juju/juju/api/base/testing"
"github.com/juju/juju/api/credentialmanager"
"github.com/juju/juju/apiserver/common"
"github.com/juju/juju/apiserver/params"
)
var _ = gc.Suite(&CredentialManagerSuite{})
type CredentialManagerSuite struct {
testing.IsolationSuite
}
func (s *CredentialManagerSuite) TestInvalidateModelCredential(c *gc.C) {
apiCaller := apitesting.APICallerFunc(func(objType string, version int, id, request string, arg, result interface{}) error {
c.Check(objType, gc.Equals, "CredentialManager")
c.Check(request, gc.Equals, "InvalidateModelCredential")
c.Assert(arg, gc.Equals, params.InvalidateCredentialArg{Reason: "auth fail"})
c.Assert(result, gc.FitsTypeOf, ¶ms.ErrorResult{})
*(result.(*params.ErrorResult)) = params.ErrorResult{}
return nil
})
client := credentialmanager.NewClient(apiCaller)
err := client.InvalidateModelCredential("auth fail")
c.Assert(err, jc.ErrorIsNil)
}
func (s *CredentialManagerSuite) TestInvalidateModelCredentialBackendFailure(c *gc.C) {
apiCaller := apitesting.APICallerFunc(func(objType string, version int, id, request string, arg, result interface{}) error {
*(result.(*params.ErrorResult)) = params.ErrorResult{Error: common.ServerError(errors.New("boom"))}
return nil
})
client := credentialmanager.NewClient(apiCaller)
err := client.InvalidateModelCredential("")
c.Assert(err, gc.ErrorMatches, "boom")
}
func (s *CredentialManagerSuite) TestInvalidateModelCredentialError(c *gc.C) {
apiCaller := apitesting.APICallerFunc(func(objType string, version int, id, request string, arg, result interface{}) error {
return errors.New("foo")
})
client := credentialmanager.NewClient(apiCaller)
err := client.InvalidateModelCredential("")
c.Assert(err, gc.ErrorMatches, "foo")
}