本文整理匯總了Golang中github.com/juju/names.NewIPAddressTag函數的典型用法代碼示例。如果您正苦於以下問題:Golang NewIPAddressTag函數的具體用法?Golang NewIPAddressTag怎麽用?Golang NewIPAddressTag使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了NewIPAddressTag函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: TestRemoveSuccess
func (s *AddresserSuite) TestRemoveSuccess(c *gc.C) {
tag1 := names.NewIPAddressTag("11111111-0000-0000-0000-000000000000")
tag2 := names.NewIPAddressTag("22222222-0000-0000-0000-000000000000")
tag3 := names.NewIPAddressTag("33333333-0000-0000-0000-000000000000")
var called int
args := params.Entities{
Entities: []params.Entity{
{Tag: tag1.String()},
{Tag: tag2.String()},
{Tag: tag3.String()},
},
}
results := params.ErrorResults{
Results: []params.ErrorResult{{nil}, {nil}, {nil}},
}
apiCaller := successAPICaller(c, "Remove", args, results, &called)
api := addresser.NewAPI(apiCaller)
ipAddress1 := addresser.NewIPAddress(api, tag1, params.Alive)
ipAddress2 := addresser.NewIPAddress(api, tag2, params.Dying)
ipAddress3 := addresser.NewIPAddress(api, tag3, params.Dead)
err := api.Remove(ipAddress1, ipAddress2, ipAddress3)
c.Assert(err, jc.ErrorIsNil)
c.Assert(called, gc.Equals, 1)
}
示例2: TestIPAddressesSuccess
func (s *AddresserSuite) TestIPAddressesSuccess(c *gc.C) {
tests := []struct {
tag names.IPAddressTag
life params.Life
}{
{names.NewIPAddressTag("11111111-0000-0000-0000-000000000000"), params.Alive},
{names.NewIPAddressTag("22222222-0000-0000-0000-000000000000"), params.Dying},
{names.NewIPAddressTag("33333333-0000-0000-0000-000000000000"), params.Dead},
}
for _, test := range tests {
var called int
args := params.Entities{
Entities: []params.Entity{{Tag: test.tag.String()}},
}
results := params.LifeResults{
Results: []params.LifeResult{{test.life, nil}},
}
apiCaller := successAPICaller(c, "Life", args, results, &called)
api := addresser.NewAPI(apiCaller)
ipAddress, err := api.IPAddress(test.tag)
c.Assert(err, jc.ErrorIsNil)
c.Assert(called, gc.Equals, 1)
c.Check(ipAddress.Tag(), gc.Equals, test.tag)
c.Check(ipAddress.Life(), gc.Equals, test.life)
}
}
示例3: TestIPAddressesSuccess
func (s *AddresserSuite) TestIPAddressesSuccess(c *gc.C) {
tag1 := names.NewIPAddressTag("11111111-0000-0000-0000-000000000000")
tag2 := names.NewIPAddressTag("22222222-0000-0000-0000-000000000000")
tag3 := names.NewIPAddressTag("33333333-0000-0000-0000-000000000000")
var called int
args := params.Entities{
Entities: []params.Entity{
{Tag: tag1.String()},
{Tag: tag2.String()},
{Tag: tag3.String()},
},
}
results := params.LifeResults{
Results: []params.LifeResult{
{Life: params.Alive},
{Life: params.Dying},
{Life: params.Dead},
},
}
apiCaller := successAPICaller(c, "Life", args, results, &called)
api := addresser.NewAPI(apiCaller)
ipAddresses, err := api.IPAddresses(tag1, tag2, tag3)
c.Assert(err, jc.ErrorIsNil)
c.Assert(called, gc.Equals, 1)
c.Assert(len(ipAddresses), gc.Equals, 3)
for i, ipAddress := range ipAddresses {
c.Check(ipAddress.Tag().String(), gc.Equals, args.Entities[i].Tag)
c.Check(ipAddress.Life(), gc.Equals, results.Results[i].Life)
}
}
示例4: TestIPAddressesServerError
func (s *AddresserSuite) TestIPAddressesServerError(c *gc.C) {
tag1 := names.NewIPAddressTag("11111111-0000-0000-0000-000000000000")
tag2 := names.NewIPAddressTag("22222222-0000-0000-0000-000000000000")
var called int
args := params.Entities{
Entities: []params.Entity{
{Tag: tag1.String()},
{Tag: tag2.String()},
},
}
results := params.LifeResults{
Results: []params.LifeResult{
{params.Alive, nil},
{"", apiservertesting.ServerError("server failure")},
},
}
apiCaller := successAPICaller(c, "Life", args, results, &called)
api := addresser.NewAPI(apiCaller)
ipAddresses, err := api.IPAddresses(tag1, tag2)
c.Assert(len(ipAddresses), gc.Equals, 2)
c.Assert(ipAddresses[0].Tag().String(), gc.Equals, tag1.String())
c.Assert(ipAddresses[1], gc.IsNil)
c.Assert(err, gc.Equals, common.ErrPartialResults)
c.Assert(called, gc.Equals, 1)
}
示例5: TestNewIPAddressTag
func (s *ipAddressSuite) TestNewIPAddressTag(c *gc.C) {
uuid := utils.MustNewUUID()
tag := names.NewIPAddressTag(uuid.String())
parsed, err := names.ParseIPAddressTag(tag.String())
c.Assert(err, gc.IsNil)
c.Assert(parsed.Kind(), gc.Equals, names.IPAddressTagKind)
c.Assert(parsed.Id(), gc.Equals, uuid.String())
c.Assert(parsed.String(), gc.Equals, names.IPAddressTagKind+"-"+uuid.String())
f := func() {
tag = names.NewIPAddressTag("42")
}
c.Assert(f, gc.PanicMatches, `invalid UUID: "42"`)
}
示例6: setUpState
func (mst *mockState) setUpState() {
mst.mu.Lock()
defer mst.mu.Unlock()
ips := []struct {
value string
uuid string
life state.Life
subnetId string
instanceId string
macaddr string
}{
{"0.1.2.3", "00000000-1111-2222-3333-0123456789ab", state.Alive, "a", "a3", "fff3"},
{"0.1.2.4", "00000000-1111-2222-4444-0123456789ab", state.Alive, "b", "b4", "fff4"},
{"0.1.2.5", "00000000-1111-2222-5555-0123456789ab", state.Alive, "b", "b5", "fff5"},
{"0.1.2.6", "00000000-1111-2222-6666-0123456789ab", state.Dead, "c", "c6", "fff6"},
{"0.1.2.7", "00000000-1111-2222-7777-0123456789ab", state.Dead, "c", "c7", "fff7"},
}
for _, ip := range ips {
mst.ipAddresses[ip.value] = &mockIPAddress{
stub: mst.stub,
st: mst,
value: ip.value,
tag: names.NewIPAddressTag(ip.uuid),
life: ip.life,
subnetId: ip.subnetId,
instanceId: instance.Id(ip.instanceId),
addr: network.NewAddress(ip.value),
macaddr: ip.macaddr,
}
}
}
示例7: TestIPAddressesClientError
func (s *AddresserSuite) TestIPAddressesClientError(c *gc.C) {
var called int
apiCaller := clientErrorAPICaller(c, "Life", nil, &called)
api := addresser.NewAPI(apiCaller)
ipAddress, err := api.IPAddress(names.NewIPAddressTag("00000000-0000-0000-0000-000000000000"))
c.Assert(err, gc.ErrorMatches, "client error!")
c.Assert(ipAddress, gc.IsNil)
c.Assert(called, gc.Equals, 1)
}
示例8: TestRemoveClientError
func (s *AddresserSuite) TestRemoveClientError(c *gc.C) {
var called int
tag := names.NewIPAddressTag("00000000-0000-0000-0000-000000000000")
apiCaller := clientErrorAPICaller(c, "Remove", nil, &called)
api := addresser.NewAPI(apiCaller)
ipAddress := addresser.NewIPAddress(api, tag, params.Alive)
err := ipAddress.Remove()
c.Assert(err, gc.ErrorMatches, "client error!")
c.Assert(called, gc.Equals, 1)
}
示例9: TestIPAddressByTag
func (s *IPAddressSuite) TestIPAddressByTag(c *gc.C) {
addr := network.NewScopedAddress("0.1.2.3", network.ScopePublic)
added, err := s.State.AddIPAddress(addr, "foobar")
c.Assert(err, jc.ErrorIsNil)
uuid, err := added.UUID()
c.Assert(err, jc.ErrorIsNil)
tag := names.NewIPAddressTag(uuid.String())
found, err := s.State.IPAddressByTag(tag)
c.Assert(err, jc.ErrorIsNil)
c.Assert(found.Id(), gc.Equals, added.Id())
}
示例10: TestNewAPISuccess
func (s *AddresserSuite) TestNewAPISuccess(c *gc.C) {
var called int
// IPAddress below uses common.Life for implementation.
apiCaller := clientErrorAPICaller(c, "Life", nil, &called)
api := addresser.NewAPI(apiCaller)
c.Check(api, gc.NotNil)
c.Check(called, gc.Equals, 0)
// Make a call so that an error will be returned.
addresses, err := api.IPAddress(names.NewIPAddressTag("00000000-0000-0000-0000-000000000000"))
c.Assert(err, gc.ErrorMatches, "client error!")
c.Assert(addresses, gc.IsNil)
c.Assert(called, gc.Equals, 1)
}
示例11: TestRemoveServerError
func (s *AddresserSuite) TestRemoveServerError(c *gc.C) {
var called int
tag := names.NewIPAddressTag("00000000-0000-0000-0000-000000000000")
args := params.Entities{
Entities: []params.Entity{{Tag: tag.String()}},
}
results := params.ErrorResults{
Results: []params.ErrorResult{{apiservertesting.ServerError("server boom!")}},
}
apiCaller := successAPICaller(c, "Remove", args, results, &called)
api := addresser.NewAPI(apiCaller)
ipAddress := addresser.NewIPAddress(api, tag, params.Alive)
err := ipAddress.Remove()
c.Assert(err, gc.ErrorMatches, "server boom!")
c.Assert(called, gc.Equals, 1)
}
示例12: TestIPAddressesServerError
func (s *AddresserSuite) TestIPAddressesServerError(c *gc.C) {
var called int
tag := names.NewIPAddressTag("00000000-0000-0000-0000-000000000000")
args := params.Entities{
Entities: []params.Entity{{Tag: tag.String()}},
}
results := params.LifeResults{
Results: []params.LifeResult{{"", apiservertesting.ServerError("server boom!")}},
}
apiCaller := successAPICaller(c, "Life", args, results, &called)
api := addresser.NewAPI(apiCaller)
ipAddress, err := api.IPAddress(tag)
c.Assert(ipAddress, gc.IsNil)
c.Assert(err, gc.ErrorMatches, "server boom!")
c.Assert(called, gc.Equals, 1)
}
示例13: setUpIPAddresses
func (mst *mockState) setUpIPAddresses() {
ips := []struct {
value string
uuid string
life state.Life
}{
{"0.1.2.3", "00000000-1111-2222-3333-0123456789ab", state.Alive},
{"0.1.2.4", "00000000-1111-2222-4444-0123456789ab", state.Alive},
{"0.1.2.5", "00000000-1111-2222-5555-0123456789ab", state.Alive},
{"0.1.2.6", "00000000-1111-2222-6666-0123456789ab", state.Dead},
{"0.1.2.7", "00000000-1111-2222-7777-0123456789ab", state.Dead},
}
for _, ip := range ips {
mst.ipAddresses[ip.value] = &mockIPAddress{
stub: mst.stub,
st: mst,
value: ip.value,
tag: names.NewIPAddressTag(ip.uuid),
life: ip.life,
}
}
}
示例14: TestParseIPAddressTag
c.Assert(parsed.Id(), gc.Equals, uuid.String())
c.Assert(parsed.String(), gc.Equals, names.IPAddressTagKind+"-"+uuid.String())
f := func() {
tag = names.NewIPAddressTag("42")
}
c.Assert(f, gc.PanicMatches, `invalid UUID: "42"`)
}
var parseIPAddressTagTests = []struct {
tag string
expected names.Tag
err error
}{
{tag: "", err: names.InvalidTagError("", "")},
{tag: "ipaddress-42424242-1111-2222-3333-0123456789ab", expected: names.NewIPAddressTag("42424242-1111-2222-3333-0123456789ab")},
{tag: "ipaddress-012345678", err: names.InvalidTagError("ipaddress-012345678", names.IPAddressTagKind)},
{tag: "ipaddress-42", err: names.InvalidTagError("ipaddress-42", names.IPAddressTagKind)},
{tag: "foobar", err: names.InvalidTagError("foobar", "")},
{tag: "space-yadda", err: names.InvalidTagError("space-yadda", names.IPAddressTagKind)}}
func (s *ipAddressSuite) TestParseIPAddressTag(c *gc.C) {
for i, t := range parseIPAddressTagTests {
c.Logf("test %d: %s", i, t.tag)
got, err := names.ParseIPAddressTag(t.tag)
if err != nil || t.err != nil {
c.Check(err, gc.DeepEquals, t.err)
continue
}
c.Check(got, gc.FitsTypeOf, t.expected)
c.Check(got, gc.Equals, t.expected)
示例15: TestIPAddressByTagNotFound
func (s *IPAddressSuite) TestIPAddressByTagNotFound(c *gc.C) {
tag := names.NewIPAddressTag("42424242-1111-2222-3333-0123456789ab")
_, err := s.State.IPAddressByTag(tag)
c.Assert(err, gc.ErrorMatches, `IP address "ipaddress-42424242-1111-2222-3333-0123456789ab" not found`)
}