本文整理汇总了Golang中github.com/juju/juju/testing/factory.NewFactory函数的典型用法代码示例。如果您正苦于以下问题:Golang NewFactory函数的具体用法?Golang NewFactory怎么用?Golang NewFactory使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewFactory函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: TestMachineLoginOtherModelNotProvisioned
func (s *loginSuite) TestMachineLoginOtherModelNotProvisioned(c *gc.C) {
info, cleanup := s.setupServer(c)
defer cleanup()
envOwner := s.Factory.MakeUser(c, nil)
envState := s.Factory.MakeModel(c, &factory.ModelParams{
Owner: envOwner.UserTag(),
ConfigAttrs: map[string]interface{}{
"controller": false,
},
})
defer envState.Close()
f2 := factory.NewFactory(envState)
machine, password := f2.MakeUnprovisionedMachineReturningPassword(c, &factory.MachineParams{})
info.ModelTag = envState.ModelTag()
st := s.openAPIWithoutLogin(c, info)
defer st.Close()
// If the agent attempts Login before the provisioner has recorded
// the machine's nonce in state, then the agent should get back an
// error with code "not provisioned".
err := st.Login(machine.Tag(), password, "nonce", nil)
c.Assert(err, gc.ErrorMatches, `machine 0 not provisioned \(not provisioned\)`)
c.Assert(err, jc.Satisfies, params.IsCodeNotProvisioned)
}
示例2: TestOtherEnvironmentFromControllerOtherNotProvisioned
func (s *loginSuite) TestOtherEnvironmentFromControllerOtherNotProvisioned(c *gc.C) {
info, cleanup := s.setupServer(c)
defer cleanup()
managerMachine, password := s.Factory.MakeMachineReturningPassword(c, &factory.MachineParams{
Jobs: []state.MachineJob{state.JobManageModel},
})
// Create a hosted model with an unprovisioned machine that has the
// same tag as the manager machine.
hostedModelState := s.Factory.MakeModel(c, nil)
defer hostedModelState.Close()
f2 := factory.NewFactory(hostedModelState)
workloadMachine, _ := f2.MakeUnprovisionedMachineReturningPassword(c, &factory.MachineParams{})
c.Assert(managerMachine.Tag(), gc.Equals, workloadMachine.Tag())
info.ModelTag = hostedModelState.ModelTag()
st := s.openAPIWithoutLogin(c, info)
defer st.Close()
// The fact that the machine with the same tag in the hosted
// model is unprovisioned should not cause the login to fail
// with "not provisioned", because the passwords don't match.
err := st.Login(managerMachine.Tag(), password, "nonce", nil)
c.Assert(err, jc.ErrorIsNil)
}
示例3: TestMachineLoginOtherModel
func (s *loginSuite) TestMachineLoginOtherModel(c *gc.C) {
// User credentials are checked against a global user list.
// Machine credentials are checked against environment specific
// machines, so this makes sure that the credential checking is
// using the correct state connection.
info, cleanup := s.setupServer(c)
defer cleanup()
envOwner := s.Factory.MakeUser(c, nil)
envState := s.Factory.MakeModel(c, &factory.ModelParams{
Owner: envOwner.UserTag(),
ConfigAttrs: map[string]interface{}{
"controller": false,
},
})
defer envState.Close()
f2 := factory.NewFactory(envState)
machine, password := f2.MakeMachineReturningPassword(c, &factory.MachineParams{
Nonce: "nonce",
})
info.ModelTag = envState.ModelTag()
st := s.openAPIWithoutLogin(c, info)
defer st.Close()
err := st.Login(machine.Tag(), password, "nonce", nil)
c.Assert(err, jc.ErrorIsNil)
}
示例4: TestCaseInsensitiveLookupInMultiEnvirons
func (s *EnvUserSuite) TestCaseInsensitiveLookupInMultiEnvirons(c *gc.C) {
assertIsolated := func(st1, st2 *state.State, usernames ...string) {
f := factory.NewFactory(st1)
expectedUser := f.MakeEnvUser(c, &factory.EnvUserParams{User: usernames[0]})
// assert case insensitive lookup for each username
for _, username := range usernames {
userTag := names.NewUserTag(username)
obtainedUser, err := st1.EnvironmentUser(userTag)
c.Assert(err, jc.ErrorIsNil)
c.Assert(obtainedUser, gc.DeepEquals, expectedUser)
_, err = st2.EnvironmentUser(userTag)
c.Assert(errors.IsNotFound(err), jc.IsTrue)
}
}
otherSt := s.Factory.MakeEnvironment(c, nil)
defer otherSt.Close()
assertIsolated(s.State, otherSt,
"[email protected]",
"[email protected]",
"[email protected]",
)
assertIsolated(otherSt, s.State,
"[email protected]",
"[email protected]",
"[email protected]",
)
}
示例5: TestCleanupControllerModels
func (s *CleanupSuite) TestCleanupControllerModels(c *gc.C) {
s.assertDoesNotNeedCleanup(c)
// Create a non-empty hosted model.
otherSt := s.Factory.MakeModel(c, nil)
defer otherSt.Close()
factory.NewFactory(otherSt).MakeService(c, nil)
otherEnv, err := otherSt.Model()
c.Assert(err, jc.ErrorIsNil)
s.assertDoesNotNeedCleanup(c)
// Destroy the controller and check the model is unaffected, but a
// cleanup for the model and services has been scheduled.
controllerEnv, err := s.State.Model()
c.Assert(err, jc.ErrorIsNil)
err = controllerEnv.DestroyIncludingHosted()
c.Assert(err, jc.ErrorIsNil)
// Two cleanups should be scheduled. One to destroy the hosted
// models, the other to destroy the controller model's
// services.
s.assertCleanupCount(c, 1)
err = otherEnv.Refresh()
c.Assert(err, jc.ErrorIsNil)
c.Assert(otherEnv.Life(), gc.Equals, state.Dying)
s.assertDoesNotNeedCleanup(c)
}
示例6: SetUpTest
func (s *metricsAdderIntegrationSuite) SetUpTest(c *gc.C) {
s.JujuConnSuite.SetUpTest(c)
f := factory.NewFactory(s.State)
machine0 := f.MakeMachine(c, &factory.MachineParams{
Series: "quantal",
Jobs: []state.MachineJob{state.JobHostUnits},
})
meteredCharm := f.MakeCharm(c, &factory.CharmParams{
Name: "metered",
URL: "cs:quantal/metered",
})
meteredService := f.MakeService(c, &factory.ServiceParams{
Charm: meteredCharm,
})
meteredUnit := f.MakeUnit(c, &factory.UnitParams{
Service: meteredService,
SetCharmURL: true,
Machine: machine0,
})
state, _ := s.OpenAPIAsNewMachine(c)
s.adder = metricsadder.NewClient(state)
s.unitTag = meteredUnit.Tag()
}
示例7: SetUpTest
func (s *destroyTwoEnvironmentsSuite) SetUpTest(c *gc.C) {
s.JujuConnSuite.SetUpTest(c)
_, err := s.State.AddUser("jess", "jess", "", "test")
c.Assert(err, jc.ErrorIsNil)
s.otherEnvOwner = names.NewUserTag("jess")
s.otherState = factory.NewFactory(s.State).MakeEnvironment(c, &factory.EnvParams{
Owner: s.otherEnvOwner,
Prepare: true,
ConfigAttrs: jujutesting.Attrs{
"state-server": false,
},
})
s.AddCleanup(func(*gc.C) { s.otherState.Close() })
// get the client for the other environment
auth := apiservertesting.FakeAuthorizer{
Tag: s.otherEnvOwner,
EnvironManager: false,
}
s.otherEnvClient, err = client.NewClient(s.otherState, common.NewResources(), auth)
c.Assert(err, jc.ErrorIsNil)
s.metricSender = &testMetricSender{}
s.PatchValue(common.SendMetrics, s.metricSender.SendMetrics)
}
示例8: TestDestroyControllerAndHostedModels
func (s *ModelSuite) TestDestroyControllerAndHostedModels(c *gc.C) {
st2 := s.Factory.MakeModel(c, nil)
defer st2.Close()
factory.NewFactory(st2).MakeService(c, nil)
controllerEnv, err := s.State.Model()
c.Assert(err, jc.ErrorIsNil)
c.Assert(controllerEnv.DestroyIncludingHosted(), jc.ErrorIsNil)
env, err := s.State.Model()
c.Assert(err, jc.ErrorIsNil)
c.Assert(env.Life(), gc.Equals, state.Dying)
assertNeedsCleanup(c, s.State)
assertCleanupRuns(c, s.State)
// Cleanups for hosted model enqueued by controller model cleanups.
assertNeedsCleanup(c, st2)
assertCleanupRuns(c, st2)
env2, err := st2.Model()
c.Assert(err, jc.ErrorIsNil)
c.Assert(env2.Life(), gc.Equals, state.Dying)
c.Assert(st2.ProcessDyingModel(), jc.ErrorIsNil)
c.Assert(env2.Refresh(), jc.ErrorIsNil)
c.Assert(env2.Life(), gc.Equals, state.Dead)
c.Assert(s.State.ProcessDyingModel(), jc.ErrorIsNil)
c.Assert(env.Refresh(), jc.ErrorIsNil)
c.Assert(env2.Life(), gc.Equals, state.Dead)
}
示例9: SetUpTest
func (s *JujuConnSuite) SetUpTest(c *gc.C) {
s.MgoSuite.SetUpTest(c)
s.FakeJujuXDGDataHomeSuite.SetUpTest(c)
s.ToolsFixture.SetUpTest(c)
s.setUpConn(c)
s.Factory = factory.NewFactory(s.State)
}
示例10: TestUserInfoUserExists
func (s *userManagerSuite) TestUserInfoUserExists(c *gc.C) {
foobar := "foobar"
fooTag := names.NewUserTag(foobar)
userFactory := factory.NewFactory(s.State, c)
userFactory.MakeUser(factory.UserParams{Username: foobar, DisplayName: "Foo Bar"})
args := params.Entities{
Entities: []params.Entity{{Tag: fooTag.String()}},
}
results, err := s.usermanager.UserInfo(args)
c.Assert(err, gc.IsNil)
expected := params.UserInfoResults{
Results: []params.UserInfoResult{
{
Result: ¶ms.UserInfo{
Username: "foobar",
DisplayName: "Foo Bar",
CreatedBy: "admin",
DateCreated: time.Time{},
LastConnection: time.Time{},
},
},
},
}
// set DateCreated to nil as we cannot know the exact time user was created
results.Results[0].Result.DateCreated = time.Time{}
c.Assert(results, gc.DeepEquals, expected)
}
示例11: TestMachineLoginOtherEnvironment
func (s *loginSuite) TestMachineLoginOtherEnvironment(c *gc.C) {
// User credentials are checked against a global user list.
// Machine credentials are checked against environment specific
// machines, so this makes sure that the credential checking is
// using the correct state connection.
info, cleanup := s.setupServerWithValidator(c, nil)
defer cleanup()
envOwner := s.Factory.MakeUser(c, nil)
envState := s.Factory.MakeEnvironment(c, &factory.EnvParams{
Owner: envOwner.UserTag(),
ConfigAttrs: map[string]interface{}{
"state-server": false,
},
Prepare: true,
})
defer envState.Close()
f2 := factory.NewFactory(envState)
machine, password := f2.MakeMachineReturningPassword(c, &factory.MachineParams{
Nonce: "nonce",
})
info.EnvironTag = envState.EnvironTag()
st, err := api.Open(info, fastDialOpts)
c.Assert(err, jc.ErrorIsNil)
defer st.Close()
err = st.Login(machine.Tag(), password, "nonce")
c.Assert(err, jc.ErrorIsNil)
}
示例12: SetUpTest
func (s *destroyControllerSuite) SetUpTest(c *gc.C) {
s.JujuConnSuite.SetUpTest(c)
s.BlockHelper = commontesting.NewBlockHelper(s.APIState)
s.AddCleanup(func(*gc.C) { s.BlockHelper.Close() })
resources := common.NewResources()
s.AddCleanup(func(_ *gc.C) { resources.StopAll() })
authoriser := apiservertesting.FakeAuthorizer{
Tag: s.AdminUserTag(c),
}
controller, err := controller.NewControllerAPI(s.State, resources, authoriser)
c.Assert(err, jc.ErrorIsNil)
s.controller = controller
s.otherEnvOwner = names.NewUserTag("[email protected]")
s.otherState = factory.NewFactory(s.State).MakeModel(c, &factory.ModelParams{
Name: "dummytoo",
Owner: s.otherEnvOwner,
Prepare: true,
ConfigAttrs: testing.Attrs{
"state-server": false,
},
})
s.AddCleanup(func(c *gc.C) { s.otherState.Close() })
s.otherModelUUID = s.otherState.ModelUUID()
}
示例13: assertDyingEnvironTransitionDyingToDead
func (s *ModelSuite) assertDyingEnvironTransitionDyingToDead(c *gc.C, st *state.State) {
// Add a service to prevent the model from transitioning directly to Dead.
// Add the service before getting the Model, otherwise we'll have to run
// the transaction twice, and hit the hook point too early.
svc := factory.NewFactory(st).MakeService(c, nil)
env, err := st.Model()
c.Assert(err, jc.ErrorIsNil)
// ProcessDyingModel is called by a worker after Destroy is called. To
// avoid a race, we jump the gun here and test immediately after the
// environement was set to dead.
defer state.SetAfterHooks(c, st, func() {
c.Assert(env.Refresh(), jc.ErrorIsNil)
c.Assert(env.Life(), gc.Equals, state.Dying)
err := svc.Destroy()
c.Assert(err, jc.ErrorIsNil)
c.Assert(st.ProcessDyingModel(), jc.ErrorIsNil)
c.Assert(env.Refresh(), jc.ErrorIsNil)
c.Assert(env.Life(), gc.Equals, state.Dead)
}).Check()
c.Assert(env.Destroy(), jc.ErrorIsNil)
}
示例14: TestDestroyControllerRemoveEmptyAddNonEmptyModel
func (s *ModelSuite) TestDestroyControllerRemoveEmptyAddNonEmptyModel(c *gc.C) {
st2 := s.Factory.MakeModel(c, nil)
defer st2.Close()
// Simulate an empty model being removed, and a new non-empty
// model being added, just before the remove txn is called.
defer state.SetBeforeHooks(c, s.State, func() {
// Destroy the empty model, which should move it right
// along to Dead, and then remove it.
model, err := st2.Model()
c.Assert(err, jc.ErrorIsNil)
c.Assert(model.Destroy(), jc.ErrorIsNil)
err = st2.RemoveAllModelDocs()
c.Assert(err, jc.ErrorIsNil)
// Add a new, non-empty model. This should still prevent
// the controller from being destroyed.
st3 := s.Factory.MakeModel(c, nil)
defer st3.Close()
factory.NewFactory(st3).MakeService(c, nil)
}).Check()
env, err := s.State.Model()
c.Assert(err, jc.ErrorIsNil)
c.Assert(env.Destroy(), gc.ErrorMatches, "failed to destroy model: hosting 1 other models")
}
示例15: TestMetricsAcrossEnvironments
func (s *MetricSuite) TestMetricsAcrossEnvironments(c *gc.C) {
now := state.NowToTheSecond().Add(-48 * time.Hour)
m := state.Metric{"pings", "5", now}
m1, err := s.State.AddMetrics(
state.BatchParam{
UUID: utils.MustNewUUID().String(),
Created: now,
CharmURL: s.meteredCharm.URL().String(),
Metrics: []state.Metric{m},
Unit: s.unit.UnitTag(),
},
)
c.Assert(err, jc.ErrorIsNil)
st := s.Factory.MakeEnvironment(c, nil)
defer st.Close()
f := factory.NewFactory(st)
meteredCharm := f.MakeCharm(c, &factory.CharmParams{Name: "metered", URL: "cs:quantal/metered"})
service := f.MakeService(c, &factory.ServiceParams{Charm: meteredCharm})
unit := f.MakeUnit(c, &factory.UnitParams{Service: service, SetCharmURL: true})
m2, err := s.State.AddMetrics(
state.BatchParam{
UUID: utils.MustNewUUID().String(),
Created: now,
CharmURL: s.meteredCharm.URL().String(),
Metrics: []state.Metric{m},
Unit: unit.UnitTag(),
},
)
c.Assert(err, jc.ErrorIsNil)
batches, err := s.State.MetricBatches()
c.Assert(err, jc.ErrorIsNil)
c.Assert(batches, gc.HasLen, 2)
unsent, err := s.State.CountOfUnsentMetrics()
c.Assert(err, jc.ErrorIsNil)
c.Assert(unsent, gc.Equals, 2)
toSend, err := s.State.MetricsToSend(10)
c.Assert(err, jc.ErrorIsNil)
c.Assert(toSend, gc.HasLen, 2)
err = m1.SetSent(time.Now().Add(-25 * time.Hour))
c.Assert(err, jc.ErrorIsNil)
err = m2.SetSent(time.Now().Add(-25 * time.Hour))
c.Assert(err, jc.ErrorIsNil)
sent, err := s.State.CountOfSentMetrics()
c.Assert(err, jc.ErrorIsNil)
c.Assert(sent, gc.Equals, 2)
err = s.State.CleanupOldMetrics()
c.Assert(err, jc.ErrorIsNil)
batches, err = s.State.MetricBatches()
c.Assert(err, jc.ErrorIsNil)
c.Assert(batches, gc.HasLen, 0)
}