本文整理汇总了Golang中github.com/juju/juju/apiserver/testing.CheckMethodCalls函数的典型用法代码示例。如果您正苦于以下问题:Golang CheckMethodCalls函数的具体用法?Golang CheckMethodCalls怎么用?Golang CheckMethodCalls使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了CheckMethodCalls函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: checkAddSpaces
func (s *SpacesSuite) checkAddSpaces(c *gc.C, p checkAddSpacesParams) {
args := params.CreateSpaceParams{}
if p.Name != "" {
args.SpaceTag = "space-" + p.Name
}
if len(p.Subnets) > 0 {
for _, cidr := range p.Subnets {
args.SubnetTags = append(args.SubnetTags, "subnet-"+cidr)
}
}
args.Public = p.Public
spaces := params.CreateSpacesParams{}
spaces.Spaces = append(spaces.Spaces, args)
results, err := s.facade.CreateSpaces(spaces)
c.Assert(len(results.Results), gc.Equals, 1)
c.Assert(err, gc.IsNil)
if p.Error == "" {
c.Assert(results.Results[0].Error, gc.IsNil)
} else {
c.Assert(results.Results[0].Error, gc.NotNil)
c.Assert(results.Results[0].Error, gc.ErrorMatches, p.Error)
}
if p.Error == "" || p.MakesCall {
apiservertesting.CheckMethodCalls(c, apiservertesting.SharedStub,
apiservertesting.BackingCall("AddSpace", p.Name, p.Subnets, p.Public),
)
} else {
apiservertesting.CheckMethodCalls(c, apiservertesting.SharedStub)
}
}
示例2: TestAllZonesWithNoBackingZonesAndSetFails
func (s *SubnetsSuite) TestAllZonesWithNoBackingZonesAndSetFails(c *gc.C) {
apiservertesting.BackingInstance.SetUp(c, apiservertesting.StubZonedEnvironName, apiservertesting.WithoutZones, apiservertesting.WithSpaces, apiservertesting.WithSubnets)
apiservertesting.SharedStub.SetErrors(
nil, // Backing.AvailabilityZones
nil, // Backing.EnvironConfig
nil, // Provider.Open
nil, // ZonedEnviron.AvailabilityZones
errors.NotSupportedf("setting"), // Backing.SetAvailabilityZones
)
results, err := s.facade.AllZones()
c.Assert(err, gc.ErrorMatches,
`cannot update known zones: setting not supported`,
)
// Verify the cause is not obscured.
c.Assert(err, jc.Satisfies, errors.IsNotSupported)
c.Assert(results, jc.DeepEquals, params.ZoneResults{})
apiservertesting.CheckMethodCalls(c, apiservertesting.SharedStub,
apiservertesting.BackingCall("AvailabilityZones"),
apiservertesting.BackingCall("EnvironConfig"),
apiservertesting.ProviderCall("Open", apiservertesting.BackingInstance.EnvConfig),
apiservertesting.ZonedEnvironCall("AvailabilityZones"),
apiservertesting.BackingCall("SetAvailabilityZones", apiservertesting.ProviderInstance.Zones),
)
}
示例3: TestAllZonesWithNoBackingZonesAndOpenFails
func (s *SubnetsSuite) TestAllZonesWithNoBackingZonesAndOpenFails(c *gc.C) {
apiservertesting.BackingInstance.SetUp(
c,
apiservertesting.StubZonedEnvironName,
apiservertesting.WithoutZones,
apiservertesting.WithSpaces,
apiservertesting.WithSubnets)
apiservertesting.SharedStub.SetErrors(
nil, // Backing.AvailabilityZones
nil, // Backing.ModelConfig
nil, // Backing.CloudSpec
errors.NotValidf("config"), // Provider.Open
)
results, err := networkingcommon.AllZones(apiservertesting.BackingInstance)
c.Assert(err, gc.ErrorMatches,
`cannot update known zones: opening environment: config not valid`,
)
// Verify the cause is not obscured.
c.Assert(err, jc.Satisfies, errors.IsNotValid)
c.Assert(results, jc.DeepEquals, params.ZoneResults{})
apiservertesting.CheckMethodCalls(c, apiservertesting.SharedStub,
apiservertesting.BackingCall("AvailabilityZones"),
apiservertesting.BackingCall("ModelConfig"),
apiservertesting.BackingCall("CloudSpec"),
apiservertesting.ProviderCall("Open", apiservertesting.BackingInstance.EnvConfig),
)
}
示例4: TestAllZonesWithNoBackingZonesAndModelConfigFails
func (s *SubnetsSuite) TestAllZonesWithNoBackingZonesAndModelConfigFails(c *gc.C) {
apiservertesting.BackingInstance.SetUp(
c,
apiservertesting.StubZonedEnvironName,
apiservertesting.WithoutZones,
apiservertesting.WithSpaces,
apiservertesting.WithSubnets)
apiservertesting.SharedStub.SetErrors(
nil, // Backing.AvailabilityZones
errors.NotFoundf("config"), // Backing.ModelConfig
)
results, err := networkingcommon.AllZones(apiservertesting.BackingInstance)
c.Assert(err, gc.ErrorMatches,
`cannot update known zones: getting model config: config not found`,
)
// Verify the cause is not obscured.
c.Assert(err, jc.Satisfies, errors.IsNotFound)
c.Assert(results, jc.DeepEquals, params.ZoneResults{})
apiservertesting.CheckMethodCalls(c, apiservertesting.SharedStub,
apiservertesting.BackingCall("AvailabilityZones"),
apiservertesting.BackingCall("ModelConfig"),
)
}
示例5: TestAllZonesUsesBackingZonesWhenAvailable
func (s *SubnetsSuite) TestAllZonesUsesBackingZonesWhenAvailable(c *gc.C) {
results, err := s.facade.AllZones()
c.Assert(err, jc.ErrorIsNil)
s.AssertAllZonesResult(c, results, apiservertesting.BackingInstance.Zones)
apiservertesting.CheckMethodCalls(c, apiservertesting.SharedStub,
apiservertesting.BackingCall("AvailabilityZones"),
)
}
示例6: testAllSpacesSuccess
func (s *SubnetsSuite) testAllSpacesSuccess(c *gc.C, withBackingSpaces apiservertesting.SetUpFlag) {
apiservertesting.BackingInstance.SetUp(c, apiservertesting.StubZonedEnvironName, apiservertesting.WithZones, withBackingSpaces, apiservertesting.WithSubnets)
results, err := s.facade.AllSpaces()
c.Assert(err, jc.ErrorIsNil)
s.AssertAllSpacesResult(c, results, apiservertesting.BackingInstance.Spaces)
apiservertesting.CheckMethodCalls(c, apiservertesting.SharedStub,
apiservertesting.BackingCall("AllSpaces"),
)
}
示例7: checkCreateSpaces
func (s *SpacesSuite) checkCreateSpaces(c *gc.C, p checkCreateSpacesParams) {
args := params.CreateSpaceParams{}
if p.Name != "" {
args.SpaceTag = "space-" + p.Name
}
if len(p.Subnets) > 0 {
for _, cidr := range p.Subnets {
args.SubnetTags = append(args.SubnetTags, "subnet-"+cidr)
}
}
args.Public = p.Public
args.ProviderId = p.ProviderId
spaces := params.CreateSpacesParams{}
spaces.Spaces = append(spaces.Spaces, args)
results, err := networkingcommon.CreateSpaces(apiservertesting.BackingInstance, spaces)
c.Assert(len(results.Results), gc.Equals, 1)
c.Assert(err, gc.IsNil)
if p.Error == "" {
c.Assert(results.Results[0].Error, gc.IsNil)
} else {
c.Assert(results.Results[0].Error, gc.NotNil)
c.Assert(results.Results[0].Error, gc.ErrorMatches, p.Error)
}
baseCalls := []apiservertesting.StubMethodCall{
apiservertesting.BackingCall("ModelConfig"),
apiservertesting.BackingCall("CloudSpec"),
apiservertesting.ProviderCall("Open", apiservertesting.BackingInstance.EnvConfig),
apiservertesting.ZonedNetworkingEnvironCall("SupportsSpaces"),
}
addSpaceCalls := append(baseCalls, apiservertesting.BackingCall("AddSpace", p.Name, network.Id(p.ProviderId), p.Subnets, p.Public))
if p.Error == "" {
apiservertesting.CheckMethodCalls(c, apiservertesting.SharedStub, addSpaceCalls...)
} else {
apiservertesting.CheckMethodCalls(c, apiservertesting.SharedStub, baseCalls...)
}
}
示例8: TestNewAPIWithBacking
func (s *SpacesSuite) TestNewAPIWithBacking(c *gc.C) {
// Clients are allowed.
facade, err := spaces.NewAPIWithBacking(
apiservertesting.BackingInstance, s.resources, s.authorizer,
)
c.Assert(err, jc.ErrorIsNil)
c.Assert(facade, gc.NotNil)
// No calls so far.
apiservertesting.CheckMethodCalls(c, apiservertesting.SharedStub)
// Agents are not allowed
agentAuthorizer := s.authorizer
agentAuthorizer.Tag = names.NewMachineTag("42")
facade, err = spaces.NewAPIWithBacking(
apiservertesting.BackingInstance, s.resources, agentAuthorizer,
)
c.Assert(err, jc.DeepEquals, common.ErrPerm)
c.Assert(facade, gc.IsNil)
// No calls so far.
apiservertesting.CheckMethodCalls(c, apiservertesting.SharedStub)
}
示例9: TestAllSpacesFailure
func (s *SubnetsSuite) TestAllSpacesFailure(c *gc.C) {
apiservertesting.SharedStub.SetErrors(errors.NotFoundf("boom"))
results, err := s.facade.AllSpaces()
c.Assert(err, gc.ErrorMatches, "boom not found")
// Verify the cause is not obscured.
c.Assert(err, jc.Satisfies, errors.IsNotFound)
c.Assert(results, jc.DeepEquals, params.SpaceResults{})
apiservertesting.CheckMethodCalls(c, apiservertesting.SharedStub,
apiservertesting.BackingCall("AllSpaces"),
)
}
示例10: TestAllZonesWhenBackingAvailabilityZonesFails
func (s *SubnetsSuite) TestAllZonesWhenBackingAvailabilityZonesFails(c *gc.C) {
apiservertesting.SharedStub.SetErrors(errors.NotSupportedf("zones"))
results, err := s.facade.AllZones()
c.Assert(err, gc.ErrorMatches, "zones not supported")
// Verify the cause is not obscured.
c.Assert(err, jc.Satisfies, errors.IsNotSupported)
c.Assert(results, jc.DeepEquals, params.ZoneResults{})
apiservertesting.CheckMethodCalls(c, apiservertesting.SharedStub,
apiservertesting.BackingCall("AvailabilityZones"),
)
}
示例11: TestAllZonesWithNoBackingZonesUpdates
func (s *SubnetsSuite) TestAllZonesWithNoBackingZonesUpdates(c *gc.C) {
apiservertesting.BackingInstance.SetUp(c, apiservertesting.StubZonedEnvironName, apiservertesting.WithoutZones, apiservertesting.WithSpaces, apiservertesting.WithSubnets)
results, err := s.facade.AllZones()
c.Assert(err, jc.ErrorIsNil)
s.AssertAllZonesResult(c, results, apiservertesting.ProviderInstance.Zones)
apiservertesting.CheckMethodCalls(c, apiservertesting.SharedStub,
apiservertesting.BackingCall("AvailabilityZones"),
apiservertesting.BackingCall("EnvironConfig"),
apiservertesting.ProviderCall("Open", apiservertesting.BackingInstance.EnvConfig),
apiservertesting.ZonedEnvironCall("AvailabilityZones"),
apiservertesting.BackingCall("SetAvailabilityZones", apiservertesting.ProviderInstance.Zones),
)
}
示例12: TestAllZonesWithNoBackingZonesAndZonesNotSupported
func (s *SubnetsSuite) TestAllZonesWithNoBackingZonesAndZonesNotSupported(c *gc.C) {
apiservertesting.BackingInstance.SetUp(c, apiservertesting.StubEnvironName, apiservertesting.WithoutZones, apiservertesting.WithSpaces, apiservertesting.WithSubnets)
// ZonedEnviron not supported
results, err := s.facade.AllZones()
c.Assert(err, gc.ErrorMatches,
`cannot update known zones: availability zones not supported`,
)
// Verify the cause is not obscured.
c.Assert(err, jc.Satisfies, errors.IsNotSupported)
c.Assert(results, jc.DeepEquals, params.ZoneResults{})
apiservertesting.CheckMethodCalls(c, apiservertesting.SharedStub,
apiservertesting.BackingCall("AvailabilityZones"),
apiservertesting.BackingCall("ModelConfig"),
apiservertesting.ProviderCall("Open", apiservertesting.BackingInstance.EnvConfig),
)
}
示例13: SetUpTest
func (s *ProxyUpdaterSuite) SetUpTest(c *gc.C) {
s.BaseSuite.SetUpTest(c)
s.resources = common.NewResources()
s.AddCleanup(func(_ *gc.C) { s.resources.StopAll() })
s.authorizer = apiservertesting.FakeAuthorizer{
Tag: names.NewMachineTag("1"),
EnvironManager: false,
}
s.tag = names.NewMachineTag("1")
s.state = &stubBackend{}
s.state.SetUp(c)
s.AddCleanup(func(_ *gc.C) { s.state.Kill() })
var err error
s.facade, err = proxyupdater.NewAPIWithBacking(s.state, s.resources, s.authorizer)
c.Assert(err, jc.ErrorIsNil)
c.Assert(s.facade, gc.NotNil)
// Shouldn't have any calls yet
apiservertesting.CheckMethodCalls(c, s.state.Stub)
}
示例14: CheckAddSubnetsFails
//.........这里部分代码省略.........
)
}
if !withSubnets {
// Set provider subnets to empty for this test.
originalSubnets := make([]network.SubnetInfo, len(apiservertesting.ProviderInstance.Subnets))
copy(originalSubnets, apiservertesting.ProviderInstance.Subnets)
apiservertesting.ProviderInstance.Subnets = []network.SubnetInfo{}
defer func() {
apiservertesting.ProviderInstance.Subnets = make([]network.SubnetInfo, len(originalSubnets))
copy(apiservertesting.ProviderInstance.Subnets, originalSubnets)
}()
if envName == apiservertesting.StubEnvironName || envName == apiservertesting.StubNetworkingEnvironName {
// networking is either not supported or no subnets are
// defined, so expected the same calls for each of the two
// arguments to AddSubnets() below.
expectedCalls = append(expectedCalls, expectedCalls...)
}
} else {
// Having subnets implies spaces will be cached as well.
expectedCalls = append(expectedCalls, apiservertesting.BackingCall("AllSpaces"))
}
if withSpaces && withSubnets {
// Having both subnets and spaces means we'll also cache zones.
expectedCalls = append(expectedCalls, apiservertesting.BackingCall("AvailabilityZones"))
}
if !withZones && withSpaces {
// Set provider zones to empty for this test.
originalZones := make([]providercommon.AvailabilityZone, len(apiservertesting.ProviderInstance.Zones))
copy(originalZones, apiservertesting.ProviderInstance.Zones)
apiservertesting.ProviderInstance.Zones = []providercommon.AvailabilityZone{}
defer func() {
apiservertesting.ProviderInstance.Zones = make([]providercommon.AvailabilityZone, len(originalZones))
copy(apiservertesting.ProviderInstance.Zones, originalZones)
}()
// updateZones tries to constructs a ZonedEnviron with these calls.
zoneCalls := append([]apiservertesting.StubMethodCall{},
apiservertesting.BackingCall("EnvironConfig"),
apiservertesting.ProviderCall("Open", apiservertesting.BackingInstance.EnvConfig),
)
// Receiver can differ according to envName, but
// AvailabilityZones() will be called on either receiver.
switch envName {
case apiservertesting.StubZonedEnvironName:
zoneCalls = append(
zoneCalls,
apiservertesting.ZonedEnvironCall("AvailabilityZones"),
)
case apiservertesting.StubZonedNetworkingEnvironName:
zoneCalls = append(
zoneCalls,
apiservertesting.ZonedNetworkingEnvironCall("AvailabilityZones"),
)
}
// Finally after caching provider zones backing zones are
// updated.
zoneCalls = append(
zoneCalls,
apiservertesting.BackingCall("SetAvailabilityZones", apiservertesting.ProviderInstance.Zones),
)
// Now, because we have 2 arguments to AddSubnets() below, we
// need to expect the same zoneCalls twice, with a
// AvailabilityZones backing lookup between them.
expectedCalls = append(expectedCalls, zoneCalls...)
expectedCalls = append(expectedCalls, apiservertesting.BackingCall("AvailabilityZones"))
expectedCalls = append(expectedCalls, zoneCalls...)
}
// Pass 2 arguments covering all cases we need.
args := params.AddSubnetsParams{
Subnets: []params.AddSubnetParams{{
SubnetTag: "subnet-10.42.0.0/16",
SpaceTag: "space-dmz",
Zones: []string{"zone1"},
}, {
SubnetProviderId: "vlan-42",
SpaceTag: "space-private",
Zones: []string{"zone3"},
}},
}
results, err := s.facade.AddSubnets(args)
c.Assert(err, jc.ErrorIsNil)
c.Assert(results.Results, gc.HasLen, len(args.Subnets))
for _, result := range results.Results {
if !c.Check(result.Error, gc.NotNil) {
continue
}
c.Check(result.Error, gc.ErrorMatches, expectedError)
c.Check(result.Error.Code, gc.Equals, "")
}
apiservertesting.CheckMethodCalls(c, apiservertesting.SharedStub, expectedCalls...)
}
示例15: TestAddSubnetsParamsCombinations
//.........这里部分代码省略.........
{`Zones contain unknown zones: "missing"`, nil},
{`Zones contain unavailable zones: "zone2", "zone4"`, nil},
{`Zones contain unavailable zones: "zone4"`, nil},
{"state not found", params.IsCodeNotFound},
{`Zones contain unavailable zones: "zone2"`, nil},
{"", nil},
{"", nil},
{"", nil},
}
expectedBackingInfos := []common.BackingSubnetInfo{{
ProviderId: "sn-ipv6",
CIDR: "2001:db8::/32",
VLANTag: 0,
AllocatableIPHigh: "",
AllocatableIPLow: "",
AvailabilityZones: []string{"zone1"},
SpaceName: "dmz",
}, {
ProviderId: "vlan-42",
CIDR: "10.30.1.0/24",
VLANTag: 42,
AllocatableIPHigh: "",
AllocatableIPLow: "",
AvailabilityZones: []string{"zone3"},
SpaceName: "private",
}, {
ProviderId: "sn-zadf00d",
CIDR: "10.10.0.0/24",
VLANTag: 0,
AllocatableIPHigh: "10.10.0.100",
AllocatableIPLow: "10.10.0.10",
AvailabilityZones: []string{"zone1"},
SpaceName: "private",
}}
c.Check(expectedErrors, gc.HasLen, len(args.Subnets))
results, err := s.facade.AddSubnets(args)
c.Assert(err, jc.ErrorIsNil)
c.Assert(len(results.Results), gc.Equals, len(args.Subnets))
for i, result := range results.Results {
c.Logf("result #%d: expected: %q", i, expectedErrors[i].message)
if expectedErrors[i].message == "" {
if !c.Check(result.Error, gc.IsNil) {
c.Logf("unexpected error: %v; args: %#v", result.Error, args.Subnets[i])
}
continue
}
if !c.Check(result.Error, gc.NotNil) {
c.Logf("unexpected success; args: %#v", args.Subnets[i])
continue
}
c.Check(result.Error.Message, gc.Equals, expectedErrors[i].message)
if expectedErrors[i].satisfier != nil {
c.Check(result.Error, jc.Satisfies, expectedErrors[i].satisfier)
} else {
c.Check(result.Error.Code, gc.Equals, "")
}
}
apiservertesting.CheckMethodCalls(c, apiservertesting.SharedStub,
// caching subnets (1st attempt): fails
apiservertesting.BackingCall("EnvironConfig"),
// caching subnets (2nd attepmt): fails
apiservertesting.BackingCall("EnvironConfig"),
apiservertesting.ProviderCall("Open", apiservertesting.BackingInstance.EnvConfig),
// caching subnets (3rd attempt): fails
apiservertesting.BackingCall("EnvironConfig"),
apiservertesting.ProviderCall("Open", apiservertesting.BackingInstance.EnvConfig),
apiservertesting.NetworkingEnvironCall("Subnets", instance.UnknownId, []network.Id(nil)),
// caching subnets (4th attempt): succeeds
apiservertesting.BackingCall("EnvironConfig"),
apiservertesting.ProviderCall("Open", apiservertesting.BackingInstance.EnvConfig),
apiservertesting.NetworkingEnvironCall("Subnets", instance.UnknownId, []network.Id(nil)),
// caching spaces (1st and 2nd attempts)
apiservertesting.BackingCall("AllSpaces"),
apiservertesting.BackingCall("AllSpaces"),
// cacing zones (1st and 2nd attempts)
apiservertesting.BackingCall("AvailabilityZones"),
apiservertesting.BackingCall("AvailabilityZones"),
// validation done; adding subnets to backing store
apiservertesting.BackingCall("AddSubnet", expectedBackingInfos[0]),
apiservertesting.BackingCall("AddSubnet", expectedBackingInfos[0]),
apiservertesting.BackingCall("AddSubnet", expectedBackingInfos[1]),
apiservertesting.BackingCall("AddSubnet", expectedBackingInfos[2]),
)
apiservertesting.ResetStub(apiservertesting.SharedStub)
// Finally, check that no params yields no results.
results, err = s.facade.AddSubnets(params.AddSubnetsParams{})
c.Assert(err, jc.ErrorIsNil)
c.Assert(results.Results, gc.NotNil)
c.Assert(results.Results, gc.HasLen, 0)
apiservertesting.CheckMethodCalls(c, apiservertesting.SharedStub)
}