本文整理汇总了Golang中github.com/juju/names.NewPayloadTag函数的典型用法代码示例。如果您正苦于以下问题:Golang NewPayloadTag函数的具体用法?Golang NewPayloadTag怎么用?Golang NewPayloadTag使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewPayloadTag函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: TestSetStatus
func (s *suite) TestSetStatus(c *gc.C) {
id := "ce5bc2a7-65d8-4800-8199-a7c3356ab309"
s.state.stateIDs = []string{id}
s.state.stateIDs = []string{"ce5bc2a7-65d8-4800-8199-a7c3356ab309"}
a := UnitFacade{s.state}
args := internal.SetStatusArgs{
Args: []internal.SetStatusArg{{
Entity: params.Entity{
Tag: names.NewPayloadTag(id).String(),
},
Status: payload.StateRunning,
}},
}
res, err := a.SetStatus(args)
c.Assert(err, jc.ErrorIsNil)
c.Check(s.state.id, gc.Equals, id)
c.Assert(s.state.status, gc.Equals, payload.StateRunning)
expected := internal.PayloadResults{
Results: []internal.PayloadResult{{
Entity: params.Entity{
Tag: names.NewPayloadTag(id).String(),
},
Error: nil,
}},
}
c.Assert(res, gc.DeepEquals, expected)
}
示例2: TestUntrack
func (s *suite) TestUntrack(c *gc.C) {
id := "ce5bc2a7-65d8-4800-8199-a7c3356ab309"
s.state.stateIDs = []string{id}
a := UnitFacade{s.state}
args := params.Entities{
Entities: []params.Entity{{
Tag: names.NewPayloadTag(id).String(),
}},
}
res, err := a.Untrack(args)
c.Assert(err, jc.ErrorIsNil)
c.Assert(s.state.id, gc.Equals, id)
expected := internal.PayloadResults{
Results: []internal.PayloadResult{{
Entity: params.Entity{
Tag: names.NewPayloadTag(id).String(),
},
Error: nil,
}},
}
c.Assert(res, gc.DeepEquals, expected)
}
示例3: TestListOne
func (s *suite) TestListOne(c *gc.C) {
id := "ce5bc2a7-65d8-4800-8199-a7c3356ab309"
pl := payload.Payload{
PayloadClass: charm.PayloadClass{
Name: "foobar",
Type: "type",
},
ID: "idfoo",
Status: payload.StateRunning,
Unit: "a-service/0",
}
s.state.payloads = []payload.Result{{
ID: id,
Payload: &payload.FullPayloadInfo{
Payload: pl,
Machine: "1",
},
}}
a := UnitFacade{s.state}
args := params.Entities{
Entities: []params.Entity{{
Tag: names.NewPayloadTag(id).String(),
}},
}
results, err := a.List(args)
c.Assert(err, jc.ErrorIsNil)
expected := api.Payload{
Class: "foobar",
Type: "type",
ID: "idfoo",
Status: payload.StateRunning,
Labels: []string{},
Unit: "unit-a-service-0",
Machine: "machine-1",
}
c.Check(results, jc.DeepEquals, internal.PayloadResults{
Results: []internal.PayloadResult{{
Entity: params.Entity{
Tag: names.NewPayloadTag(id).String(),
},
Payload: &expected,
NotFound: false,
Error: nil,
}},
})
}
示例4: TestLookUpMixed
func (s *suite) TestLookUpMixed(c *gc.C) {
s.state.stateIDs = []string{
"ce5bc2a7-65d8-4800-8199-a7c3356ab309",
"",
"ce5bc2a7-65d8-4800-8199-a7c3356ab311",
}
notFound := errors.NotFoundf("payload")
s.stub.SetErrors(nil, notFound, nil)
a := UnitFacade{s.state}
args := internal.LookUpArgs{
Args: []internal.LookUpArg{{
Name: "fooID",
ID: "bar",
}, {
Name: "bazID",
ID: "bam",
}, {
Name: "spam",
ID: "eggs",
}},
}
res, err := a.LookUp(args)
c.Assert(err, jc.ErrorIsNil)
s.stub.CheckCallNames(c, "LookUp", "LookUp", "LookUp")
c.Check(res, jc.DeepEquals, internal.PayloadResults{
Results: []internal.PayloadResult{{
Entity: params.Entity{
Tag: names.NewPayloadTag("ce5bc2a7-65d8-4800-8199-a7c3356ab309").String(),
},
NotFound: false,
Error: nil,
}, {
Entity: params.Entity{
Tag: "",
},
NotFound: true,
Error: common.ServerError(notFound),
}, {
Entity: params.Entity{
Tag: names.NewPayloadTag("ce5bc2a7-65d8-4800-8199-a7c3356ab311").String(),
},
NotFound: false,
Error: nil,
}},
})
}
示例5: TestLookUpOkay
func (s *suite) TestLookUpOkay(c *gc.C) {
id := "ce5bc2a7-65d8-4800-8199-a7c3356ab309"
s.state.stateIDs = []string{id}
a := UnitFacade{s.state}
args := internal.LookUpArgs{
Args: []internal.LookUpArg{{
Name: "fooID",
ID: "bar",
}},
}
res, err := a.LookUp(args)
c.Assert(err, jc.ErrorIsNil)
s.stub.CheckCalls(c, []testing.StubCall{{
FuncName: "LookUp",
Args: []interface{}{"fooID", "bar"},
}})
c.Check(res, jc.DeepEquals, internal.PayloadResults{
Results: []internal.PayloadResult{{
Entity: params.Entity{
Tag: names.NewPayloadTag(id).String(),
},
NotFound: false,
Error: nil,
}},
})
}
示例6: TestTrack
func (s *clientSuite) TestTrack(c *gc.C) {
id := "ce5bc2a7-65d8-4800-8199-a7c3356ab309"
numStubCalls := 0
s.facade.FacadeCallFn = func(name string, args, response interface{}) error {
numStubCalls++
c.Check(name, gc.Equals, "Track")
typedResponse, ok := response.(*internal.PayloadResults)
c.Assert(ok, gc.Equals, true)
typedResponse.Results = []internal.PayloadResult{{
Entity: params.Entity{
Tag: names.NewPayloadTag(id).String(),
},
Payload: nil,
NotFound: false,
Error: nil,
}}
return nil
}
pclient := client.NewUnitFacadeClient(s.facade)
pl, err := api.API2Payload(s.payload)
c.Assert(err, jc.ErrorIsNil)
results, err := pclient.Track(pl.Payload)
c.Assert(err, jc.ErrorIsNil)
c.Check(numStubCalls, gc.Equals, 1)
c.Check(results, jc.DeepEquals, []payload.Result{{
ID: id,
Payload: nil,
NotFound: false,
Error: nil,
}})
}
示例7: ids2args
func ids2args(ids []string) params.Entities {
var args params.Entities
for _, id := range ids {
tag := names.NewPayloadTag(id).String()
args.Entities = append(args.Entities, params.Entity{
Tag: tag,
})
}
return args
}
示例8: IDs2SetStatusArgs
// IDs2SetStatusArgs converts the provided payload IDs into arguments
// for the SetStatus API endpoint.
func IDs2SetStatusArgs(ids []string, status string) SetStatusArgs {
var args SetStatusArgs
for _, id := range ids {
arg := SetStatusArg{
Status: status,
}
arg.Tag = names.NewPayloadTag(id).String()
args.Args = append(args.Args, arg)
}
return args
}
示例9: TestNewPayloadResultOkay
func (internalHelpersSuite) TestNewPayloadResultOkay(c *gc.C) {
id := "ce5bc2a7-65d8-4800-8199-a7c3356ab309"
result := private.NewPayloadResult(id, nil)
c.Check(result, jc.DeepEquals, private.PayloadResult{
Entity: params.Entity{
Tag: names.NewPayloadTag(id).String(),
},
Payload: nil,
NotFound: false,
Error: nil,
})
}
示例10: TestNewPayloadResultNotFound
func (internalHelpersSuite) TestNewPayloadResultNotFound(c *gc.C) {
id := "ce5bc2a7-65d8-4800-8199-a7c3356ab309"
err := errors.NotFoundf("payload %q", id)
result := private.NewPayloadResult(id, err)
c.Check(result, jc.DeepEquals, private.PayloadResult{
Entity: params.Entity{
Tag: names.NewPayloadTag(id).String(),
},
Payload: nil,
NotFound: true,
Error: common.ServerError(err),
})
}
示例11: TestResult2apiError
func (internalHelpersSuite) TestResult2apiError(c *gc.C) {
id := "ce5bc2a7-65d8-4800-8199-a7c3356ab309"
err := errors.New("<failure>")
result := private.Result2api(payload.Result{
ID: id,
Payload: nil,
NotFound: false,
Error: err,
})
c.Check(result, jc.DeepEquals, private.PayloadResult{
Entity: params.Entity{
Tag: names.NewPayloadTag(id).String(),
},
Payload: nil,
NotFound: false,
Error: common.ServerError(err),
})
}
示例12: Result2api
// Result2api converts the payload.Result into a PayloadResult.
func Result2api(result payload.Result) PayloadResult {
res := PayloadResult{
NotFound: result.NotFound,
}
if result.ID != "" {
res.Tag = names.NewPayloadTag(result.ID).String()
}
if result.Payload != nil {
pl := api.Payload2api(*result.Payload)
res.Payload = &pl
}
if result.Error != nil {
res.Error = common.ServerError(result.Error)
}
return res
}
示例13: TestAPI2ResultError
func (internalHelpersSuite) TestAPI2ResultError(c *gc.C) {
id := "ce5bc2a7-65d8-4800-8199-a7c3356ab309"
failure := errors.New("<failure>")
result, err := private.API2Result(private.PayloadResult{
Entity: params.Entity{
Tag: names.NewPayloadTag(id).String(),
},
Payload: nil,
NotFound: false,
Error: common.ServerError(failure),
})
c.Assert(err, jc.ErrorIsNil)
c.Check(result.Error.Error(), gc.Equals, failure.Error())
c.Check(result, jc.DeepEquals, payload.Result{
ID: id,
Payload: nil,
NotFound: false,
Error: result.Error, // The actual error is checked above.
})
}
示例14: TestAPI2ResultInfo
func (internalHelpersSuite) TestAPI2ResultInfo(c *gc.C) {
id := "ce5bc2a7-65d8-4800-8199-a7c3356ab309"
result, err := private.API2Result(private.PayloadResult{
Entity: params.Entity{
Tag: names.NewPayloadTag(id).String(),
},
NotFound: false,
Error: nil,
Payload: &api.Payload{
Class: "foobar",
Type: "type",
ID: "idfoo",
Status: payload.StateRunning,
Unit: "unit-a-service-0",
Machine: "machine-1",
},
})
c.Assert(err, jc.ErrorIsNil)
c.Check(result, jc.DeepEquals, payload.Result{
ID: id,
NotFound: false,
Error: nil,
Payload: &payload.FullPayloadInfo{
Payload: payload.Payload{
PayloadClass: charm.PayloadClass{
Name: "foobar",
Type: "type",
},
ID: "idfoo",
Status: payload.StateRunning,
Unit: "a-service/0",
},
Machine: "1",
},
})
}
示例15: TestLookUpMulti
func (s *clientSuite) TestLookUpMulti(c *gc.C) {
id1 := "ce5bc2a7-65d8-4800-8199-a7c3356ab309"
id2 := "ce5bc2a7-65d8-4800-8199-a7c3356ab311"
response := &internal.PayloadResults{
Results: []internal.PayloadResult{{
Entity: params.Entity{
Tag: names.NewPayloadTag(id1).String(),
},
Payload: nil,
NotFound: false,
Error: nil,
}, {
Entity: params.Entity{
Tag: "",
},
Payload: nil,
NotFound: true,
Error: common.ServerError(errors.NotFoundf("payload")),
}, {
Entity: params.Entity{
Tag: names.NewPayloadTag(id2).String(),
},
Payload: nil,
NotFound: false,
Error: nil,
}},
}
s.facade.responses = append(s.facade.responses, response)
pclient := client.NewUnitFacadeClient(s.facade)
results, err := pclient.LookUp("idfoo/bar", "idbaz/bam", "spam/eggs")
c.Assert(err, jc.ErrorIsNil)
c.Assert(results, gc.HasLen, 3)
c.Assert(results[1].Error, gc.NotNil)
results[1].Error = nil
c.Check(results, jc.DeepEquals, []payload.Result{{
ID: id1,
Payload: nil,
NotFound: false,
Error: nil,
}, {
ID: "",
Payload: nil,
NotFound: true,
Error: nil,
}, {
ID: id2,
Payload: nil,
NotFound: false,
Error: nil,
}})
s.stub.CheckCalls(c, []testing.StubCall{{
FuncName: "FacadeCall",
Args: []interface{}{
"LookUp",
&internal.LookUpArgs{
Args: []internal.LookUpArg{{
Name: "idfoo",
ID: "bar",
}, {
Name: "idbaz",
ID: "bam",
}, {
Name: "spam",
ID: "eggs",
}},
},
response,
},
}})
}