本文整理汇总了Golang中github.com/juju/names.NewUnitTag函数的典型用法代码示例。如果您正苦于以下问题:Golang NewUnitTag函数的具体用法?Golang NewUnitTag怎么用?Golang NewUnitTag使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewUnitTag函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: TestUnitStorageAttachments
func (s *storageSuite) TestUnitStorageAttachments(c *gc.C) {
storageAttachmentIds := []params.StorageAttachmentId{{
StorageTag: "storage-whatever-0",
UnitTag: "unit-mysql-0",
}}
var called bool
apiCaller := testing.APICallerFunc(func(objType string, version int, id, request string, arg, result interface{}) error {
c.Check(objType, gc.Equals, "Uniter")
c.Check(version, gc.Equals, 2)
c.Check(id, gc.Equals, "")
c.Check(request, gc.Equals, "UnitStorageAttachments")
c.Check(arg, gc.DeepEquals, params.Entities{
Entities: []params.Entity{{Tag: "unit-mysql-0"}},
})
c.Assert(result, gc.FitsTypeOf, ¶ms.StorageAttachmentIdsResults{})
*(result.(*params.StorageAttachmentIdsResults)) = params.StorageAttachmentIdsResults{
Results: []params.StorageAttachmentIdsResult{{
Result: params.StorageAttachmentIds{storageAttachmentIds},
}},
}
called = true
return nil
})
st := uniter.NewState(apiCaller, names.NewUnitTag("mysql/0"))
attachmentIds, err := st.UnitStorageAttachments(names.NewUnitTag("mysql/0"))
c.Check(err, jc.ErrorIsNil)
c.Check(called, jc.IsTrue)
c.Assert(attachmentIds, gc.DeepEquals, storageAttachmentIds)
}
示例2: TestRemoveStorageAttachment
func (s *storageSuite) TestRemoveStorageAttachment(c *gc.C) {
apiCaller := testing.APICallerFunc(func(objType string, version int, id, request string, arg, result interface{}) error {
c.Check(objType, gc.Equals, "Uniter")
c.Check(version, gc.Equals, 2)
c.Check(id, gc.Equals, "")
c.Check(request, gc.Equals, "RemoveStorageAttachments")
c.Check(arg, gc.DeepEquals, params.StorageAttachmentIds{
Ids: []params.StorageAttachmentId{{
StorageTag: "storage-data-0",
UnitTag: "unit-mysql-0",
}},
})
c.Assert(result, gc.FitsTypeOf, ¶ms.ErrorResults{})
*(result.(*params.ErrorResults)) = params.ErrorResults{
Results: []params.ErrorResult{{
Error: ¶ms.Error{Message: "yoink"},
}},
}
return nil
})
st := uniter.NewState(apiCaller, names.NewUnitTag("mysql/0"))
err := st.RemoveStorageAttachment(names.NewStorageTag("data/0"), names.NewUnitTag("mysql/0"))
c.Check(err, gc.ErrorMatches, "yoink")
}
示例3: TestWatchStorageAttachments
func (s *storageSuite) TestWatchStorageAttachments(c *gc.C) {
var called bool
apiCaller := testing.APICallerFunc(func(objType string, version int, id, request string, arg, result interface{}) error {
c.Check(objType, gc.Equals, "Uniter")
c.Check(version, gc.Equals, 2)
c.Check(id, gc.Equals, "")
c.Check(request, gc.Equals, "WatchStorageAttachments")
c.Check(arg, gc.DeepEquals, params.StorageAttachmentIds{
Ids: []params.StorageAttachmentId{{
StorageTag: "storage-data-0",
UnitTag: "unit-mysql-0",
}},
})
c.Assert(result, gc.FitsTypeOf, ¶ms.NotifyWatchResults{})
*(result.(*params.NotifyWatchResults)) = params.NotifyWatchResults{
Results: []params.NotifyWatchResult{{
Error: ¶ms.Error{Message: "FAIL"},
}},
}
called = true
return nil
})
st := uniter.NewState(apiCaller, names.NewUnitTag("mysql/0"))
_, err := st.WatchStorageAttachment(names.NewStorageTag("data/0"), names.NewUnitTag("mysql/0"))
c.Check(err, gc.ErrorMatches, "FAIL")
c.Check(called, jc.IsTrue)
}
示例4: TestAPIErrors
func (s *storageSuite) TestAPIErrors(c *gc.C) {
apiCaller := testing.APICallerFunc(func(objType string, version int, id, request string, arg, result interface{}) error {
return errors.New("bad")
})
st := uniter.NewState(apiCaller, names.NewUnitTag("mysql/0"))
_, err := st.UnitStorageAttachments(names.NewUnitTag("mysql/0"))
c.Check(err, gc.ErrorMatches, "bad")
}
示例5: TestRemoveStorageAttachments
func (s *storageSuite) TestRemoveStorageAttachments(c *gc.C) {
setMock := func(st *mockStorageState, f func(s names.StorageTag, u names.UnitTag) error) {
st.remove = f
}
unitTag0 := names.NewUnitTag("mysql/0")
unitTag1 := names.NewUnitTag("mysql/1")
storageTag0 := names.NewStorageTag("data/0")
storageTag1 := names.NewStorageTag("data/1")
resources := common.NewResources()
getCanAccess := func() (common.AuthFunc, error) {
return func(tag names.Tag) bool {
return tag == unitTag0
}, nil
}
state := &mockStorageState{}
setMock(state, func(s names.StorageTag, u names.UnitTag) error {
c.Assert(u, gc.DeepEquals, unitTag0)
if s == storageTag1 {
return errors.New("badness")
}
return nil
})
storage, err := uniter.NewStorageAPI(state, resources, getCanAccess)
c.Assert(err, jc.ErrorIsNil)
errors, err := storage.RemoveStorageAttachments(params.StorageAttachmentIds{
Ids: []params.StorageAttachmentId{{
StorageTag: storageTag0.String(),
UnitTag: unitTag0.String(),
}, {
StorageTag: storageTag1.String(),
UnitTag: unitTag0.String(),
}, {
StorageTag: storageTag0.String(),
UnitTag: unitTag1.String(),
}, {
StorageTag: unitTag0.String(), // oops
UnitTag: unitTag0.String(),
}, {
StorageTag: storageTag0.String(),
UnitTag: storageTag0.String(), // oops
}},
})
c.Assert(err, jc.ErrorIsNil)
c.Assert(errors, jc.DeepEquals, params.ErrorResults{
Results: []params.ErrorResult{
{nil},
{¶ms.Error{Message: "badness"}},
{¶ms.Error{Code: params.CodeUnauthorized, Message: "permission denied"}},
{¶ms.Error{Message: `"unit-mysql-0" is not a valid storage tag`}},
{¶ms.Error{Message: `"storage-data-0" is not a valid unit tag`}},
},
})
}
示例6: TestUnit
func (s *unitSuite) TestUnit(c *gc.C) {
apiUnitFoo, err := s.firewaller.Unit(names.NewUnitTag("foo/42"))
c.Assert(err, gc.ErrorMatches, `unit "foo/42" not found`)
c.Assert(err, jc.Satisfies, params.IsCodeNotFound)
c.Assert(apiUnitFoo, gc.IsNil)
apiUnit0, err := s.firewaller.Unit(s.units[0].Tag().(names.UnitTag))
c.Assert(err, jc.ErrorIsNil)
c.Assert(apiUnit0, gc.NotNil)
c.Assert(apiUnit0.Name(), gc.Equals, s.units[0].Name())
c.Assert(apiUnit0.Tag(), gc.Equals, names.NewUnitTag(s.units[0].Name()))
}
示例7: TestStorageAttachmentResultCountMismatch
func (s *storageSuite) TestStorageAttachmentResultCountMismatch(c *gc.C) {
apiCaller := testing.APICallerFunc(func(objType string, version int, id, request string, arg, result interface{}) error {
*(result.(*params.StorageAttachmentIdsResults)) = params.StorageAttachmentIdsResults{
[]params.StorageAttachmentIdsResult{{}, {}},
}
return nil
})
st := uniter.NewState(apiCaller, names.NewUnitTag("mysql/0"))
c.Assert(func() {
st.UnitStorageAttachments(names.NewUnitTag("mysql/0"))
}, gc.PanicMatches, "expected 1 result, got 2")
}
示例8: TestNamespace
func (s *RsyslogSuite) TestNamespace(c *gc.C) {
st := s.st
// set the rsyslog cert
err := s.APIState.Client().EnvironmentSet(map[string]interface{}{"rsyslog-ca-cert": coretesting.CACert})
c.Assert(err, jc.ErrorIsNil)
// namespace only takes effect in filenames
// for machine-0; all others assume isolation.
s.testNamespace(c, st, names.NewMachineTag("0"), "", "25-juju.conf", *rsyslog.LogDir)
s.testNamespace(c, st, names.NewMachineTag("0"), "mynamespace", "25-juju-mynamespace.conf", *rsyslog.LogDir+"-mynamespace")
s.testNamespace(c, st, names.NewMachineTag("1"), "", "25-juju.conf", *rsyslog.LogDir)
s.testNamespace(c, st, names.NewMachineTag("1"), "mynamespace", "25-juju.conf", *rsyslog.LogDir)
s.testNamespace(c, st, names.NewUnitTag("myservice/0"), "", "26-juju-unit-myservice-0.conf", *rsyslog.LogDir)
s.testNamespace(c, st, names.NewUnitTag("myservice/0"), "mynamespace", "26-juju-unit-myservice-0.conf", *rsyslog.LogDir)
}
示例9: TestHandle
func (testsuite) TestHandle(c *gc.C) {
f := &fakeAPI{}
ua := unitAssignerHandler{api: f}
ids := []string{"foo/0", "bar/0"}
err := ua.Handle(nil, ids)
c.Assert(err, jc.ErrorIsNil)
c.Assert(f.assignTags, gc.DeepEquals, []names.UnitTag{
names.NewUnitTag("foo/0"),
names.NewUnitTag("bar/0"),
})
f.err = errors.New("boo")
err = ua.Handle(nil, ids)
c.Assert(err, gc.Equals, f.err)
}
示例10: TestWorkerPathsWindows
func (s *PathsSuite) TestWorkerPathsWindows(c *gc.C) {
s.PatchValue(&os.HostOS, func() os.OSType { return os.Windows })
dataDir := c.MkDir()
unitTag := names.NewUnitTag("some-service/323")
worker := "some-worker"
paths := uniter.NewWorkerPaths(dataDir, unitTag, worker)
relData := relPathFunc(dataDir)
relAgent := relPathFunc(relData("agents", "unit-some-service-323"))
c.Assert(paths, jc.DeepEquals, uniter.Paths{
ToolsDir: relData("tools/unit-some-service-323"),
Runtime: uniter.RuntimePaths{
JujuRunSocket: `\\.\pipe\unit-some-service-323-some-worker-run`,
JujucServerSocket: `\\.\pipe\unit-some-service-323-some-worker-agent`,
},
State: uniter.StatePaths{
BaseDir: relAgent(),
CharmDir: relAgent("charm"),
OperationsFile: relAgent("state", "uniter"),
RelationsDir: relAgent("state", "relations"),
BundlesDir: relAgent("state", "bundles"),
DeployerDir: relAgent("state", "deployer"),
StorageDir: relAgent("state", "storage"),
MetricsSpoolDir: relAgent("state", "spool", "metrics"),
},
})
}
示例11: ReadSettings
// ReadSettings returns a map holding the settings of the unit with the
// supplied name within this relation. An error will be returned if the
// relation no longer exists, or if the unit's service is not part of the
// relation, or the settings are invalid; but mere non-existence of the
// unit is not grounds for an error, because the unit settings are
// guaranteed to persist for the lifetime of the relation, regardless
// of the lifetime of the unit.
func (ru *RelationUnit) ReadSettings(uname string) (params.RelationSettings, error) {
if !names.IsValidUnit(uname) {
return nil, errors.Errorf("%q is not a valid unit", uname)
}
tag := names.NewUnitTag(uname)
var results params.RelationSettingsResults
args := params.RelationUnitPairs{
RelationUnitPairs: []params.RelationUnitPair{{
Relation: ru.relation.tag.String(),
LocalUnit: ru.unit.tag.String(),
RemoteUnit: tag.String(),
}},
}
err := ru.st.facade.FacadeCall("ReadRemoteSettings", args, &results)
if err != nil {
return nil, err
}
if len(results.Results) != 1 {
return nil, fmt.Errorf("expected 1 result, got %d", len(results.Results))
}
result := results.Results[0]
if result.Error != nil {
return nil, result.Error
}
return result.Settings, nil
}
示例12: TestAddMetricBatches
func (s *metricsAdderSuite) TestAddMetricBatches(c *gc.C) {
var called bool
var callParams params.MetricBatchParams
metricsadder.PatchFacadeCall(s, s.adder, func(request string, args, response interface{}) error {
p, ok := args.(params.MetricBatchParams)
c.Assert(ok, jc.IsTrue)
callParams = p
called = true
c.Assert(request, gc.Equals, "AddMetricBatches")
result := response.(*params.ErrorResults)
result.Results = make([]params.ErrorResult, 1)
return nil
})
batches := []params.MetricBatchParam{{
Tag: names.NewUnitTag("test-unit/0").String(),
Batch: params.MetricBatch{
UUID: utils.MustNewUUID().String(),
CharmURL: "test-charm-url",
Created: time.Now(),
Metrics: []params.Metric{{Key: "pings", Value: "5", Time: time.Now().UTC()}},
},
}}
_, err := s.adder.AddMetricBatches(batches)
c.Assert(err, jc.ErrorIsNil)
c.Assert(called, jc.IsTrue)
c.Assert(callParams.Batches, gc.DeepEquals, batches)
}
示例13: Subordinates
// Subordinates implements Unit.
func (u *unit) Subordinates() []names.UnitTag {
var subordinates []names.UnitTag
for _, s := range u.Subordinates_ {
subordinates = append(subordinates, names.NewUnitTag(s))
}
return subordinates
}
示例14: 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)
}
示例15: TestWatchUnitStorageAttachments
func (s *storageSuite) TestWatchUnitStorageAttachments(c *gc.C) {
resources := common.NewResources()
getCanAccess := func() (common.AuthFunc, error) {
return func(names.Tag) bool {
return true
}, nil
}
unitTag := names.NewUnitTag("mysql/0")
watcher := &mockStringsWatcher{
changes: make(chan []string, 1),
}
watcher.changes <- []string{"storage/0", "storage/1"}
state := &mockStorageState{
watchStorageAttachments: func(u names.UnitTag) state.StringsWatcher {
c.Assert(u, gc.DeepEquals, unitTag)
return watcher
},
}
storage, err := uniter.NewStorageAPI(state, resources, getCanAccess)
c.Assert(err, jc.ErrorIsNil)
watches, err := storage.WatchUnitStorageAttachments(params.Entities{
Entities: []params.Entity{{unitTag.String()}},
})
c.Assert(err, jc.ErrorIsNil)
c.Assert(watches, gc.DeepEquals, params.StringsWatchResults{
Results: []params.StringsWatchResult{{
StringsWatcherId: "1",
Changes: []string{"storage/0", "storage/1"},
}},
})
c.Assert(resources.Get("1"), gc.Equals, watcher)
}