forked from juju/juju
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathidentity_url_test.go
88 lines (76 loc) · 2.7 KB
/
identity_url_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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
// Copyright 2012-2019 Canonical Ltd.
// Licensed under the AGPLv3, see LICENCE file for details.
package controller_test
import (
"github.com/juju/errors"
jc "github.com/juju/testing/checkers"
gc "gopkg.in/check.v1"
apitesting "github.com/juju/juju/api/base/testing"
"github.com/juju/juju/api/controller"
"github.com/juju/juju/apiserver/common"
"github.com/juju/juju/apiserver/params"
)
func (s *Suite) TestIdentityProviderURLPriorV7(c *gc.C) {
called := false
apiCaller := apitesting.BestVersionCaller{
BestVersion: 6,
APICallerFunc: func(objType string, version int, id, request string, a, response interface{}) error {
called = true
c.Assert(request, gc.Equals, "IdentityProviderURL")
return nil
},
}
client := controller.NewClient(apiCaller)
_, err := client.IdentityProviderURL()
c.Assert(err, gc.ErrorMatches, "IdentityProviderURL not supported by this version of Juju not supported")
c.Assert(called, jc.IsFalse)
}
func (s *Suite) TestIdentityProviderURLCallError(c *gc.C) {
apiCaller := apitesting.BestVersionCaller{
BestVersion: 7,
APICallerFunc: func(string, int, string, string, interface{}, interface{}) error {
return errors.New("boom")
},
}
client := controller.NewClient(apiCaller)
result, err := client.IdentityProviderURL()
c.Check(result, gc.Equals, "")
c.Check(err, gc.ErrorMatches, "boom")
}
func (s *Suite) TestIdentityProviderURL(c *gc.C) {
expURL := "https://api.jujucharms.com/identity"
apiCaller := apitesting.BestVersionCaller{
BestVersion: 7,
APICallerFunc: func(objType string, version int, id, request string, arg, result interface{}) error {
c.Check(objType, gc.Equals, "Controller")
c.Check(id, gc.Equals, "")
c.Check(request, gc.Equals, "IdentityProviderURL")
c.Check(result, gc.FitsTypeOf, ¶ms.StringResult{})
out := result.(*params.StringResult)
out.Result = expURL
return nil
},
}
client := controller.NewClient(apiCaller)
result, err := client.IdentityProviderURL()
c.Assert(err, jc.ErrorIsNil)
c.Assert(result, gc.Equals, expURL)
}
func (s *Suite) TestIdentityProviderURLWithErrorResult(c *gc.C) {
apiCaller := apitesting.BestVersionCaller{
BestVersion: 7,
APICallerFunc: func(objType string, version int, id, request string, arg, result interface{}) error {
c.Check(objType, gc.Equals, "Controller")
c.Check(id, gc.Equals, "")
c.Check(request, gc.Equals, "IdentityProviderURL")
c.Check(result, gc.FitsTypeOf, ¶ms.StringResult{})
out := result.(*params.StringResult)
out.Result = "garbage"
out.Error = common.ServerError(errors.New("version error"))
return nil
},
}
client := controller.NewClient(apiCaller)
_, err := client.IdentityProviderURL()
c.Assert(err, gc.ErrorMatches, "version error")
}