本文整理汇总了Golang中github.com/juju/names.NewServiceTag函数的典型用法代码示例。如果您正苦于以下问题:Golang NewServiceTag函数的具体用法?Golang NewServiceTag怎么用?Golang NewServiceTag使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewServiceTag函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: TestStreamCharmsTools
func (s *ImportSuite) TestStreamCharmsTools(c *gc.C) {
model := description.NewModel(description.ModelArgs{
Owner: names.NewUserTag("me"),
})
model.AddService(description.ServiceArgs{
Tag: names.NewServiceTag("magic"),
CharmURL: "local:trusty/magic",
})
model.AddService(description.ServiceArgs{
Tag: names.NewServiceTag("magic"),
CharmURL: "cs:trusty/postgresql-42",
})
uploader := &fakeUploader{charms: make(map[string]string)}
config := migration.UploadBinariesConfig{
State: &fakeStateStorage{},
Model: model,
Target: &fakeAPIConnection{},
GetCharmUploader: func(api.Connection) migration.CharmUploader { return uploader },
GetToolsUploader: func(target api.Connection) migration.ToolsUploader { return &noOpUploader{} },
GetStateStorage: func(migration.UploadBackend) storage.Storage { return &fakeCharmsStorage{} },
GetCharmStoragePath: func(_ migration.UploadBackend, u *charm.URL) (string, error) {
return "/path/for/" + u.String(), nil
},
}
err := migration.UploadBinaries(config)
c.Assert(err, jc.ErrorIsNil)
c.Assert(uploader.charms, jc.DeepEquals, map[string]string{
"local:trusty/magic": "fake file at /path/for/local:trusty/magic",
"cs:trusty/postgresql-42": "fake file at /path/for/cs:trusty/postgresql-42",
})
}
示例2: Rescale
// Rescale requests that all supplied service names be rescaled to
// their minimum configured sizes. It returns the first error it
// encounters.
func (api *API) Rescale(services []string) error {
args := params.Entities{
Entities: make([]params.Entity, len(services)),
}
for i, service := range services {
if !names.IsValidService(service) {
return errors.NotValidf("service name %q", service)
}
tag := names.NewServiceTag(service)
args.Entities[i].Tag = tag.String()
}
var results params.ErrorResults
err := api.caller.FacadeCall("Rescale", args, &results)
if err != nil {
return errors.Trace(err)
}
for _, result := range results.Results {
if result.Error != nil {
if err == nil {
err = result.Error
} else {
logger.Errorf("additional rescale error: %v", err)
}
}
}
return errors.Trace(err)
}
示例3: TestWriteSettings
func (s *settingsSuite) TestWriteSettings(c *gc.C) {
numWriteSettingCalls := 0
writeSettings := func(serviceId string, settings map[string]string) error {
numWriteSettingCalls++
c.Check(serviceId, gc.Equals, StubServiceNm)
return nil
}
numIsLeaderCalls := 0
isLeader := func(serviceId, unitId string) (bool, error) {
numIsLeaderCalls++
c.Check(serviceId, gc.Equals, StubServiceNm)
c.Check(unitId, gc.Equals, StubUnitNm)
return true, nil
}
accessor := NewLeadershipSettingsAccessor(&stubAuthorizer{}, nil, nil, writeSettings, isLeader)
results, err := accessor.Merge(params.MergeLeadershipSettingsBulkParams{
[]params.MergeLeadershipSettingsParam{
{
ServiceTag: names.NewServiceTag(StubServiceNm).String(),
Settings: map[string]string{"baz": "biz"},
},
},
})
c.Assert(err, gc.IsNil)
c.Assert(results.Results, gc.HasLen, 1)
c.Check(results.Results[0].Error, gc.IsNil)
c.Check(numWriteSettingCalls, gc.Equals, 1)
c.Check(numIsLeaderCalls, gc.Equals, 1)
}
示例4: TestWatchSuccess
func (*FacadeSuite) TestWatchSuccess(c *gc.C) {
caller := apiCaller(c, func(_ string, _, results interface{}) error {
typed, ok := results.(*params.NotifyWatchResults)
c.Assert(ok, jc.IsTrue)
*typed = params.NotifyWatchResults{
Results: []params.NotifyWatchResult{{
NotifyWatcherId: "123",
}},
}
return nil
})
expectWatcher := &struct{ watcher.NotifyWatcher }{}
newWatcher := func(apiCaller base.APICaller, result params.NotifyWatchResult) watcher.NotifyWatcher {
c.Check(apiCaller, gc.NotNil) // uncomparable
c.Check(result, jc.DeepEquals, params.NotifyWatchResult{
NotifyWatcherId: "123",
})
return expectWatcher
}
facade := lifeflag.NewFacade(caller, newWatcher)
watcher, err := facade.Watch(names.NewServiceTag("blah"))
c.Check(err, jc.ErrorIsNil)
c.Check(watcher, gc.Equals, expectWatcher)
}
示例5: TestEntityUnknownLife
func (*ScaryConnectSuite) TestEntityUnknownLife(c *gc.C) {
// "random" failure case
stub := &testing.Stub{}
expectConn := &mockConn{stub: stub}
apiOpen := func(info *api.Info, opts api.DialOpts) (api.Connection, error) {
return expectConn, nil
}
entity := names.NewServiceTag("omg")
connect := func() (api.Connection, error) {
return apicaller.ScaryConnect(&mockAgent{
stub: stub,
model: coretesting.ModelTag,
entity: entity,
}, apiOpen)
}
conn, err := lifeTest(c, stub, apiagent.Life("zombie"), connect)
c.Check(conn, gc.IsNil)
c.Check(err, gc.ErrorMatches, `unknown life value "zombie"`)
stub.CheckCalls(c, []testing.StubCall{{
FuncName: "Life",
Args: []interface{}{entity},
}, {
FuncName: "Close",
}})
}
示例6: TestClaimLeadershipTranslation
func (s *leadershipSuite) TestClaimLeadershipTranslation(c *gc.C) {
var ldrMgr stubLeadershipManager
ldrMgr.ClaimLeadershipFn = func(sid, uid string, duration time.Duration) error {
c.Check(sid, gc.Equals, StubServiceNm)
c.Check(uid, gc.Equals, StubUnitNm)
expectDuration := time.Duration(299.9 * float64(time.Second))
checkDurationEquals(c, duration, expectDuration)
return nil
}
ldrSvc := &leadershipService{LeadershipManager: &ldrMgr, authorizer: &stubAuthorizer{}}
results, err := ldrSvc.ClaimLeadership(params.ClaimLeadershipBulkParams{
Params: []params.ClaimLeadershipParams{
{
ServiceTag: names.NewServiceTag(StubServiceNm).String(),
UnitTag: names.NewUnitTag(StubUnitNm).String(),
DurationSeconds: 299.9,
},
},
})
c.Check(err, jc.ErrorIsNil)
c.Assert(results.Results, gc.HasLen, 1)
c.Check(results.Results[0].Error, gc.IsNil)
}
示例7: prepareClaimLeadership
// prepareClaimLeadership creates a single set of params in
// preperation for making a bulk call.
func (c *client) prepareClaimLeadership(serviceId, unitId string, duration time.Duration) params.ClaimLeadershipParams {
return params.ClaimLeadershipParams{
names.NewServiceTag(serviceId).String(),
names.NewUnitTag(unitId).String(),
duration.Seconds(),
}
}
示例8: testEntityFine
func testEntityFine(c *gc.C, life apiagent.Life) {
stub := &testing.Stub{}
expectConn := &mockConn{stub: stub}
apiOpen := func(info *api.Info, opts api.DialOpts) (api.Connection, error) {
// no apiOpen stub calls necessary in this suite; covered
// by RetrySuite, just an extra complication here.
return expectConn, nil
}
// to make the point that this code should be entity-agnostic,
// use an entity that doesn't correspond to an agent at all.
entity := names.NewServiceTag("omg")
connect := func() (api.Connection, error) {
return apicaller.ScaryConnect(&mockAgent{
stub: stub,
model: coretesting.ModelTag,
entity: entity,
}, apiOpen)
}
conn, err := lifeTest(c, stub, apiagent.Alive, connect)
c.Check(conn, gc.Equals, expectConn)
c.Check(err, jc.ErrorIsNil)
stub.CheckCalls(c, []testing.StubCall{{
FuncName: "Life",
Args: []interface{}{entity},
}, {
FuncName: "SetPassword",
Args: []interface{}{entity, "new"},
}})
}
示例9: NewAddPendingResourcesArgs
// NewAddPendingResourcesArgs returns the arguments for the
// AddPendingResources API endpoint.
func NewAddPendingResourcesArgs(serviceID string, chID charmstore.CharmID, csMac *macaroon.Macaroon, resources []charmresource.Resource) (AddPendingResourcesArgs, error) {
var args AddPendingResourcesArgs
if !names.IsValidService(serviceID) {
return args, errors.Errorf("invalid service %q", serviceID)
}
tag := names.NewServiceTag(serviceID).String()
var apiResources []CharmResource
for _, res := range resources {
if err := res.Validate(); err != nil {
return args, errors.Trace(err)
}
apiRes := CharmResource2API(res)
apiResources = append(apiResources, apiRes)
}
args.Tag = tag
args.Resources = apiResources
if chID.URL != nil {
args.URL = chID.URL.String()
args.Channel = string(chID.Channel)
args.CharmStoreMacaroon = csMac
}
return args, nil
}
示例10: TestClaimLeadershipDeniedError
func (s *leadershipSuite) TestClaimLeadershipDeniedError(c *gc.C) {
var ldrMgr stubLeadershipManager
ldrMgr.ClaimLeadershipFn = func(sid, uid string, duration time.Duration) error {
c.Check(sid, gc.Equals, StubServiceNm)
c.Check(uid, gc.Equals, StubUnitNm)
expectDuration := time.Duration(5.001 * float64(time.Second))
checkDurationEquals(c, duration, expectDuration)
return errors.Annotatef(leadership.ErrClaimDenied, "obfuscated")
}
ldrSvc := &leadershipService{LeadershipManager: &ldrMgr, authorizer: &stubAuthorizer{}}
results, err := ldrSvc.ClaimLeadership(params.ClaimLeadershipBulkParams{
Params: []params.ClaimLeadershipParams{
{
ServiceTag: names.NewServiceTag(StubServiceNm).String(),
UnitTag: names.NewUnitTag(StubUnitNm).String(),
DurationSeconds: 5.001,
},
},
})
c.Check(err, jc.ErrorIsNil)
c.Assert(results.Results, gc.HasLen, 1)
c.Check(results.Results[0].Error, jc.Satisfies, params.IsCodeLeadershipClaimDenied)
}
示例11: checkChangePassword
func checkChangePassword(c *gc.C, errs ...error) (*testing.Stub, error) {
// We prepend the unauth/success pair that triggers password
// change, and consume them in apiOpen below...
errUnauth := ¶ms.Error{Code: params.CodeUnauthorized}
allErrs := append([]error{errUnauth, nil}, errs...)
stub := &testing.Stub{}
stub.SetErrors(allErrs...)
expectConn := &mockConn{stub: stub}
apiOpen := func(info *api.Info, opts api.DialOpts) (api.Connection, error) {
// ...but we *don't* record the calls themselves; they
// are tested plenty elsewhere, and hiding them makes
// client code simpler.
if err := stub.NextErr(); err != nil {
return nil, err
}
return expectConn, nil
}
entity := names.NewServiceTag("omg")
connect := func() (api.Connection, error) {
return apicaller.ScaryConnect(&mockAgent{
stub: stub,
model: coretesting.ModelTag,
entity: entity,
}, apiOpen)
}
conn, err := lifeTest(c, stub, apiagent.Alive, connect)
c.Check(conn, gc.IsNil)
return stub, err
}
示例12: TestEntityDenied
func (*ScaryConnectSuite) TestEntityDenied(c *gc.C) {
// permanent failure case
stub := &testing.Stub{}
stub.SetErrors(apiagent.ErrDenied)
expectConn := &mockConn{stub: stub}
apiOpen := func(info *api.Info, opts api.DialOpts) (api.Connection, error) {
return expectConn, nil
}
entity := names.NewServiceTag("omg")
connect := func() (api.Connection, error) {
return apicaller.ScaryConnect(&mockAgent{
stub: stub,
model: coretesting.ModelTag,
entity: entity,
}, apiOpen)
}
conn, err := lifeTest(c, stub, apiagent.Dead, connect)
c.Check(conn, gc.IsNil)
c.Check(err, gc.Equals, apicaller.ErrConnectImpossible)
stub.CheckCalls(c, []testing.StubCall{{
FuncName: "Life",
Args: []interface{}{entity},
}, {
FuncName: "Close",
}})
}
示例13: TestNotSupportedTag
func (s *agentAuthenticatorSuite) TestNotSupportedTag(c *gc.C) {
srv := newServer(c, s.State)
defer srv.Stop()
authenticator, err := apiserver.ServerAuthenticatorForTag(srv, names.NewServiceTag("not-support"))
c.Assert(err, gc.ErrorMatches, "unexpected login entity tag: invalid request")
c.Assert(authenticator, gc.IsNil)
}
示例14: TestInit
func (s *DefinedSuite) TestInit(c *gc.C) {
tests := []struct {
should string
args []string
expectedSvc names.ServiceTag
expectedOutputSchema bool
expectedErr string
}{{
should: "fail with missing service name",
args: []string{},
expectedErr: "no service name specified",
}, {
should: "fail with invalid service name",
args: []string{invalidServiceId},
expectedErr: "invalid service name \"" + invalidServiceId + "\"",
}, {
should: "fail with too many args",
args: []string{"two", "things"},
expectedErr: "unrecognized args: \\[\"things\"\\]",
}, {
should: "init properly with valid service name",
args: []string{validServiceId},
expectedSvc: names.NewServiceTag(validServiceId),
}, {
should: "init properly with valid service name and --schema",
args: []string{"--schema", validServiceId},
expectedOutputSchema: true,
expectedSvc: names.NewServiceTag(validServiceId),
}}
for i, t := range tests {
for _, modelFlag := range s.modelFlags {
c.Logf("test %d should %s: juju actions defined %s", i,
t.should, strings.Join(t.args, " "))
s.wrappedCommand, s.command = action.NewDefinedCommand(s.store)
args := append([]string{modelFlag, "admin"}, t.args...)
err := testing.InitCommand(s.wrappedCommand, args)
if t.expectedErr == "" {
c.Check(s.command.ServiceTag(), gc.Equals, t.expectedSvc)
c.Check(s.command.FullSchema(), gc.Equals, t.expectedOutputSchema)
} else {
c.Check(err, gc.ErrorMatches, t.expectedErr)
}
}
}
}
示例15: TestUpgraderAPIRefusesNonUnitNonMachineAgent
func (s *rsyslogSuite) TestUpgraderAPIRefusesNonUnitNonMachineAgent(c *gc.C) {
anAuthorizer := s.authorizer
anAuthorizer.Tag = names.NewServiceTag("hadoop")
anUpgrader, err := rsyslog.NewRsyslogAPI(s.State, s.resources, anAuthorizer)
c.Check(err, gc.NotNil)
c.Check(anUpgrader, gc.IsNil)
c.Assert(err, gc.ErrorMatches, "permission denied")
}