本文整理汇总了Golang中github.com/juju/juju/api.PatchClientFacadeCall函数的典型用法代码示例。如果您正苦于以下问题:Golang PatchClientFacadeCall函数的具体用法?Golang PatchClientFacadeCall怎么用?Golang PatchClientFacadeCall使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了PatchClientFacadeCall函数的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: TestClientModelUsers
func (s *clientSuite) TestClientModelUsers(c *gc.C) {
client := s.APIState.Client()
cleanup := api.PatchClientFacadeCall(client,
func(request string, paramsIn interface{}, response interface{}) error {
c.Assert(paramsIn, gc.IsNil)
if response, ok := response.(*params.ModelUserInfoResults); ok {
response.Results = []params.ModelUserInfoResult{
{Result: ¶ms.ModelUserInfo{UserName: "one"}},
{Result: ¶ms.ModelUserInfo{UserName: "two"}},
{Result: ¶ms.ModelUserInfo{UserName: "three"}},
}
} else {
c.Log("wrong output structure")
c.Fail()
}
return nil
},
)
defer cleanup()
obtained, err := client.ModelUserInfo()
c.Assert(err, jc.ErrorIsNil)
c.Assert(obtained, jc.DeepEquals, []params.ModelUserInfo{
{UserName: "one"},
{UserName: "two"},
{UserName: "three"},
})
}
示例2: TestShareEnvironmentExistingUser
func (s *clientSuite) TestShareEnvironmentExistingUser(c *gc.C) {
client := s.APIState.Client()
user := s.Factory.MakeEnvUser(c, nil)
cleanup := api.PatchClientFacadeCall(client,
func(request string, paramsIn interface{}, response interface{}) error {
if users, ok := paramsIn.(params.ModifyEnvironUsers); ok {
c.Assert(users.Changes, gc.HasLen, 1)
c.Logf(string(users.Changes[0].Action), gc.Equals, string(params.AddEnvUser))
c.Logf(users.Changes[0].UserTag, gc.Equals, user.UserTag().String())
} else {
c.Fatalf("wrong input structure")
}
if result, ok := response.(*params.ErrorResults); ok {
err := ¶ms.Error{Message: "failed to create environment user: env user already exists"}
*result = params.ErrorResults{Results: []params.ErrorResult{{Error: err}}}
} else {
c.Fatalf("wrong input structure")
}
return nil
},
)
defer cleanup()
result, err := client.ShareEnvironment([]names.UserTag{user.UserTag()})
c.Assert(err, gc.IsNil)
c.Assert(result.OneError().Error(), gc.Matches, "failed to create environment user: env user already exists")
c.Assert(result.Results, gc.HasLen, 1)
c.Assert(result.Results[0].Error, gc.ErrorMatches, `failed to create environment user: env user already exists`)
}
示例3: TestUnshareEnvironmentMissingUser
func (s *clientSuite) TestUnshareEnvironmentMissingUser(c *gc.C) {
client := s.APIState.Client()
user := names.NewUserTag("[email protected]")
cleanup := api.PatchClientFacadeCall(client,
func(request string, paramsIn interface{}, response interface{}) error {
if users, ok := paramsIn.(params.ModifyEnvironUsers); ok {
c.Assert(users.Changes, gc.HasLen, 1)
c.Logf(string(users.Changes[0].Action), gc.Equals, string(params.RemoveEnvUser))
c.Logf(users.Changes[0].UserTag, gc.Equals, user.String())
} else {
c.Fatalf("wrong input structure")
}
if result, ok := response.(*params.ErrorResults); ok {
err := ¶ms.Error{
Message: "error message",
Code: params.CodeNotFound,
}
*result = params.ErrorResults{Results: []params.ErrorResult{{Error: err}}}
} else {
c.Fatalf("wrong input structure")
}
return nil
},
)
defer cleanup()
err := client.UnshareEnvironment(user)
c.Assert(err, jc.ErrorIsNil)
logMsg := fmt.Sprintf("WARNING juju.api environment was not previously shared with user %s", user.Username())
c.Assert(c.GetTestLog(), jc.Contains, logMsg)
}
示例4: TestUnshareEnvironmentThreeUsers
func (s *clientSuite) TestUnshareEnvironmentThreeUsers(c *gc.C) {
client := s.APIState.Client()
missingUser := s.Factory.MakeEnvUser(c, nil)
localUser := s.Factory.MakeUser(c, nil)
newUserTag := names.NewUserTag("[email protected]")
cleanup := api.PatchClientFacadeCall(client,
func(request string, paramsIn interface{}, response interface{}) error {
if users, ok := paramsIn.(params.ModifyEnvironUsers); ok {
c.Assert(users.Changes, gc.HasLen, 3)
c.Assert(string(users.Changes[0].Action), gc.Equals, string(params.RemoveEnvUser))
c.Assert(users.Changes[0].UserTag, gc.Equals, missingUser.UserTag().String())
c.Assert(string(users.Changes[1].Action), gc.Equals, string(params.RemoveEnvUser))
c.Assert(users.Changes[1].UserTag, gc.Equals, localUser.UserTag().String())
c.Assert(string(users.Changes[2].Action), gc.Equals, string(params.RemoveEnvUser))
c.Assert(users.Changes[2].UserTag, gc.Equals, newUserTag.String())
} else {
c.Log("wrong input structure")
c.Fail()
}
if result, ok := response.(*params.ErrorResults); ok {
err := ¶ms.Error{Message: "error unsharing user"}
*result = params.ErrorResults{Results: []params.ErrorResult{{Error: err}, {Error: nil}, {Error: nil}}}
} else {
c.Log("wrong output structure")
c.Fail()
}
return nil
},
)
defer cleanup()
err := client.UnshareEnvironment(missingUser.UserTag(), localUser.UserTag(), newUserTag)
c.Assert(err, gc.ErrorMatches, "error unsharing user")
}
示例5: TestShareEnvironmentExistingUser
func (s *clientSuite) TestShareEnvironmentExistingUser(c *gc.C) {
client := s.APIState.Client()
user := s.Factory.MakeEnvUser(c, nil)
cleanup := api.PatchClientFacadeCall(client,
func(request string, paramsIn interface{}, response interface{}) error {
if users, ok := paramsIn.(params.ModifyEnvironUsers); ok {
c.Assert(users.Changes, gc.HasLen, 1)
c.Logf(string(users.Changes[0].Action), gc.Equals, string(params.AddEnvUser))
c.Logf(users.Changes[0].UserTag, gc.Equals, user.UserTag().String())
} else {
c.Fatalf("wrong input structure")
}
if result, ok := response.(*params.ErrorResults); ok {
err := ¶ms.Error{
Message: "error message",
Code: params.CodeAlreadyExists,
}
*result = params.ErrorResults{Results: []params.ErrorResult{{Error: err}}}
} else {
c.Fatalf("wrong input structure")
}
return nil
},
)
defer cleanup()
err := client.ShareEnvironment(user.UserTag())
c.Assert(err, jc.ErrorIsNil)
logMsg := fmt.Sprintf("WARNING juju.api environment is already shared with %s", user.UserName())
c.Assert(c.GetTestLog(), jc.Contains, logMsg)
}
示例6: TestDestroyEnvironment
func (s *clientSuite) TestDestroyEnvironment(c *gc.C) {
client := s.APIState.Client()
var called bool
cleanup := api.PatchClientFacadeCall(client,
func(req string, args interface{}, resp interface{}) error {
c.Assert(req, gc.Equals, "DestroyEnvironment")
called = true
return nil
})
defer cleanup()
err := client.DestroyEnvironment()
c.Assert(err, jc.ErrorIsNil)
c.Assert(called, jc.IsTrue)
}
示例7: TestAbortCurrentUpgrade
func (s *clientSuite) TestAbortCurrentUpgrade(c *gc.C) {
client := s.APIState.Client()
someErr := errors.New("random")
cleanup := api.PatchClientFacadeCall(client,
func(request string, args interface{}, response interface{}) error {
c.Assert(request, gc.Equals, "AbortCurrentUpgrade")
c.Assert(args, gc.IsNil)
c.Assert(response, gc.IsNil)
return someErr
},
)
defer cleanup()
err := client.AbortCurrentUpgrade()
c.Assert(err, gc.Equals, someErr) // Confirms that the correct facade was called
}
示例8: testMinVer
func testMinVer(client *api.Client, t minverTest, c *gc.C) {
charmMinVer := version.MustParse(t.charm)
jujuVer := version.MustParse(t.juju)
cleanup := api.PatchClientFacadeCall(client,
func(request string, paramsIn interface{}, response interface{}) error {
c.Assert(paramsIn, gc.IsNil)
if response, ok := response.(*params.AgentVersionResult); ok {
response.Version = jujuVer
} else {
c.Log("wrong output structure")
c.Fail()
}
return nil
},
)
defer cleanup()
charmArchive := testcharms.Repo.CharmArchive(c.MkDir(), "dummy")
curl := charm.MustParseURL(
fmt.Sprintf("local:quantal/%s-%d", charmArchive.Meta().Name, charmArchive.Revision()),
)
charmArchive.Meta().MinJujuVersion = charmMinVer
_, err := client.AddLocalCharm(curl, charmArchive)
if t.ok {
if err != nil {
c.Errorf("Unexpected non-nil error for jujuver %v, minver %v: %#v", t.juju, t.charm, err)
}
} else {
if err == nil {
c.Errorf("Unexpected nil error for jujuver %v, minver %v", t.juju, t.charm)
} else if !api.IsMinVersionError(err) {
c.Errorf("Wrong error for jujuver %v, minver %v: expected minVersionError, got: %#v", t.juju, t.charm, err)
}
}
}