本文整理汇总了Golang中github.com/juju/juju/worker/uniter/operation.NewFactory函数的典型用法代码示例。如果您正苦于以下问题:Golang NewFactory函数的具体用法?Golang NewFactory怎么用?Golang NewFactory使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewFactory函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: SetUpTest
func (s *runcommandsSuite) SetUpTest(c *gc.C) {
s.charmURL = charm.MustParseURL("cs:precise/mysql-2")
s.remoteState = remotestate.Snapshot{
CharmURL: s.charmURL,
}
s.mockRunner = mockRunner{runCommands: func(commands string) (*exec.ExecResponse, error) {
return s.runCommands(commands)
}}
s.callbacks = &mockCallbacks{}
s.opFactory = operation.NewFactory(operation.FactoryParams{
Callbacks: s.callbacks,
RunnerFactory: &mockRunnerFactory{
newCommandRunner: func(info runnercontext.CommandInfo) (runner.Runner, error) {
return &s.mockRunner, nil
},
},
})
s.commands = runcommands.NewCommands()
s.commandCompleted = nil
s.resolver = runcommands.NewCommandsResolver(
s.commands, func(id string) {
if s.commandCompleted != nil {
s.commandCompleted(id)
}
},
)
}
开发者ID:howbazaar,项目名称:juju,代码行数:28,代码来源:runcommands_test.go
示例2: testPrepareHookError
func (s *RunHookSuite) testPrepareHookError(
c *gc.C, newHook newHook, expectClearResolvedFlag, expectSkip bool,
) {
callbacks := &PrepareHookCallbacks{
MockPrepareHook: &MockPrepareHook{err: errors.New("pow")},
MockClearResolvedFlag: &MockNoArgs{},
}
factory := operation.NewFactory(operation.FactoryParams{
Callbacks: callbacks,
})
op, err := newHook(factory, hook.Info{Kind: hooks.ConfigChanged})
c.Assert(err, jc.ErrorIsNil)
newState, err := op.Prepare(operation.State{})
c.Check(newState, gc.IsNil)
c.Check(callbacks.MockClearResolvedFlag.called, gc.Equals, expectClearResolvedFlag)
if expectSkip {
c.Check(err, gc.Equals, operation.ErrSkipExecute)
c.Check(callbacks.MockPrepareHook.gotHook, gc.IsNil)
return
}
c.Check(err, gc.ErrorMatches, "pow")
c.Check(callbacks.MockPrepareHook.gotHook, gc.DeepEquals, &hook.Info{
Kind: hooks.ConfigChanged,
})
}
开发者ID:mhilton,项目名称:juju,代码行数:26,代码来源:runhook_test.go
示例3: TestSendingFails
func (s *MetricsOperationSuite) TestSendingFails(c *gc.C) {
apiSender := newTestAPIMetricSender()
factory := operation.NewFactory(operation.FactoryParams{
MetricSender: apiSender,
MetricSpoolDir: s.spoolDir,
})
sendOperation, err := factory.NewSendMetrics()
c.Assert(err, gc.IsNil)
_, err = sendOperation.Prepare(operation.State{})
c.Assert(err, jc.ErrorIsNil)
select {
case apiSender.sendError <- errors.New("something went wrong"):
default:
c.Fatalf("blocked error channel")
}
_, err = sendOperation.Execute(operation.State{})
c.Assert(err, jc.ErrorIsNil)
c.Assert(apiSender.batches, gc.HasLen, 1)
reader, err := metrics.NewJSONMetricReader(s.spoolDir)
c.Assert(err, gc.IsNil)
batches, err := reader.Read()
c.Assert(err, gc.IsNil)
c.Assert(batches, gc.HasLen, 1)
}
开发者ID:claudiu-coblis,项目名称:juju,代码行数:31,代码来源:metrics_test.go
示例4: TestPrepareHookCtxError
func (s *RunHookSuite) TestPrepareHookCtxError(c *gc.C) {
ctx := &MockContext{}
ctx.SetErrors(errors.New("ctx prepare error"))
callbacks := &PrepareHookCallbacks{
MockPrepareHook: &MockPrepareHook{},
}
runnerFactory := &MockRunnerFactory{
MockNewHookRunner: &MockNewHookRunner{
runner: &MockRunner{
context: ctx,
},
},
}
factory := operation.NewFactory(operation.FactoryParams{
RunnerFactory: runnerFactory,
Callbacks: callbacks,
})
op, err := factory.NewRunHook(hook.Info{Kind: hooks.ConfigChanged})
c.Assert(err, jc.ErrorIsNil)
newState, err := op.Prepare(operation.State{})
c.Check(newState, gc.IsNil)
c.Assert(err, gc.ErrorMatches, `ctx prepare error`)
ctx.CheckCall(c, 0, "Prepare")
}
开发者ID:howbazaar,项目名称:juju,代码行数:27,代码来源:runhook_test.go
示例5: TestSendingGetDuplicate
func (s *MetricsOperationSuite) TestSendingGetDuplicate(c *gc.C) {
apiSender := newTestAPIMetricSender()
factory := operation.NewFactory(operation.FactoryParams{
MetricSender: apiSender,
MetricSpoolDir: s.spoolDir,
})
sendOperation, err := factory.NewSendMetrics()
c.Assert(err, gc.IsNil)
_, err = sendOperation.Prepare(operation.State{})
c.Assert(err, jc.ErrorIsNil)
apiErr := ¶ms.Error{Message: "already exists", Code: params.CodeAlreadyExists}
select {
case apiSender.errors <- apiErr:
default:
c.Fatalf("blocked error channel")
}
_, err = sendOperation.Execute(operation.State{})
c.Assert(err, jc.ErrorIsNil)
c.Assert(apiSender.batches, gc.HasLen, 1)
reader, err := metrics.NewJSONMetricReader(s.spoolDir)
c.Assert(err, gc.IsNil)
batches, err := reader.Read()
c.Assert(err, gc.IsNil)
c.Assert(batches, gc.HasLen, 0)
}
开发者ID:claudiu-coblis,项目名称:juju,代码行数:32,代码来源:metrics_test.go
示例6: TestMetricSendingSuccess
func (s *MetricsOperationSuite) TestMetricSendingSuccess(c *gc.C) {
apiSender := newTestAPIMetricSender()
factory := operation.NewFactory(operation.FactoryParams{
MetricSender: apiSender,
MetricSpoolDir: s.spoolDir,
})
sendOperation, err := factory.NewSendMetrics()
c.Assert(err, gc.IsNil)
_, err = sendOperation.Prepare(operation.State{})
c.Assert(err, jc.ErrorIsNil)
_, err = sendOperation.Execute(operation.State{})
c.Assert(err, jc.ErrorIsNil)
c.Assert(apiSender.batches, gc.HasLen, 1)
reader, err := metrics.NewJSONMetricReader(s.spoolDir)
c.Assert(err, gc.IsNil)
batches, err := reader.Read()
c.Assert(err, gc.IsNil)
c.Assert(batches, gc.HasLen, 0)
}
开发者ID:claudiu-coblis,项目名称:juju,代码行数:25,代码来源:metrics_test.go
示例7: testNotifyDeployerError
func (s *DeploySuite) testNotifyDeployerError(
c *gc.C, newDeploy newDeploy, expectNotifyRevert bool,
) {
callbacks := &DeployCallbacks{
MockClearResolvedFlag: &MockNoArgs{},
}
deployer := &MockDeployer{}
expectCall := &MockNoArgs{err: errors.New("snh")}
if expectNotifyRevert {
deployer.MockNotifyRevert = expectCall
} else {
deployer.MockNotifyResolved = expectCall
}
factory := operation.NewFactory(operation.FactoryParams{
Callbacks: callbacks,
Deployer: deployer,
})
op, err := newDeploy(factory, curl("cs:quantal/hive-23"))
c.Assert(err, jc.ErrorIsNil)
newState, err := op.Prepare(operation.State{})
c.Check(newState, gc.IsNil)
c.Check(err, gc.ErrorMatches, "snh")
c.Check(expectCall.called, jc.IsTrue)
}
开发者ID:claudiu-coblis,项目名称:juju,代码行数:25,代码来源:deploy_test.go
示例8: SetUpTest
func (s *resolverSuite) SetUpTest(c *gc.C) {
s.stub = testing.Stub{}
s.charmURL = charm.MustParseURL("cs:precise/mysql-2")
s.remoteState = remotestate.Snapshot{
CharmModifiedVersion: s.charmModifiedVersion,
CharmURL: s.charmURL,
}
s.opFactory = operation.NewFactory(operation.FactoryParams{})
attachments, err := storage.NewAttachments(&dummyStorageAccessor{}, names.NewUnitTag("u/0"), c.MkDir(), nil)
c.Assert(err, jc.ErrorIsNil)
s.clearResolved = func() error {
return errors.New("unexpected resolved")
}
s.reportHookError = func(hook.Info) error {
return errors.New("unexpected report hook error")
}
s.resolverConfig = uniter.ResolverConfig{
ClearResolved: func() error { return s.clearResolved() },
ReportHookError: func(info hook.Info) error { return s.reportHookError(info) },
StartRetryHookTimer: func() { s.stub.AddCall("StartRetryHookTimer") },
StopRetryHookTimer: func() { s.stub.AddCall("StopRetryHookTimer") },
ShouldRetryHooks: true,
Leadership: leadership.NewResolver(),
Actions: uniteractions.NewResolver(),
Relations: relation.NewRelationsResolver(&dummyRelations{}),
Storage: storage.NewResolver(attachments),
Commands: nopResolver{},
}
s.resolver = uniter.NewUniterResolver(s.resolverConfig)
}
开发者ID:bac,项目名称:juju,代码行数:35,代码来源:resolver_test.go
示例9: TestPrepareHookCtxCalled
func (s *RunHookSuite) TestPrepareHookCtxCalled(c *gc.C) {
ctx := &MockContext{}
callbacks := &PrepareHookCallbacks{
MockPrepareHook: &MockPrepareHook{},
MockClearResolvedFlag: &MockNoArgs{},
}
runnerFactory := &MockRunnerFactory{
MockNewHookRunner: &MockNewHookRunner{
runner: &MockRunner{
context: ctx,
},
},
}
factory := operation.NewFactory(operation.FactoryParams{
RunnerFactory: runnerFactory,
Callbacks: callbacks,
})
op, err := factory.NewRunHook(hook.Info{Kind: hooks.ConfigChanged})
c.Assert(err, jc.ErrorIsNil)
newState, err := op.Prepare(operation.State{})
c.Check(newState, gc.NotNil)
c.Assert(err, jc.ErrorIsNil)
ctx.CheckCall(c, 0, "Prepare")
}
开发者ID:mhilton,项目名称:juju,代码行数:27,代码来源:runhook_test.go
示例10: TestPrepareSuccess
func (s *RunCommandsSuite) TestPrepareSuccess(c *gc.C) {
ctx := &MockContext{}
runnerFactory := &MockRunnerFactory{
MockNewCommandRunner: &MockNewCommandRunner{
runner: &MockRunner{
context: ctx,
},
},
}
factory := operation.NewFactory(operation.FactoryParams{
RunnerFactory: runnerFactory,
})
sendResponse := func(*utilexec.ExecResponse, error) { panic("not expected") }
op, err := factory.NewCommands(someCommandArgs, sendResponse)
c.Assert(err, jc.ErrorIsNil)
newState, err := op.Prepare(operation.State{})
c.Assert(err, jc.ErrorIsNil)
c.Assert(newState, gc.IsNil)
c.Assert(*runnerFactory.MockNewCommandRunner.gotInfo, gc.Equals, runner.CommandInfo{
RelationId: 123,
RemoteUnitName: "foo/456",
ForceRemoteUnit: true,
})
ctx.CheckCall(c, 0, "Prepare")
}
开发者ID:mhilton,项目名称:juju,代码行数:26,代码来源:runcommands_test.go
示例11: testPrepareStageError
func (s *DeploySuite) testPrepareStageError(c *gc.C, newDeploy newDeploy) {
callbacks := &DeployCallbacks{
MockClearResolvedFlag: &MockNoArgs{},
MockGetArchiveInfo: &MockGetArchiveInfo{info: &MockBundleInfo{}},
}
deployer := &MockDeployer{
MockNotifyRevert: &MockNoArgs{},
MockNotifyResolved: &MockNoArgs{},
MockStage: &MockStage{err: errors.New("squish")},
}
var abort <-chan struct{} = make(chan struct{})
factory := operation.NewFactory(operation.FactoryParams{
Deployer: deployer,
Callbacks: callbacks,
Abort: abort,
})
op, err := newDeploy(factory, curl("cs:quantal/hive-23"))
c.Assert(err, jc.ErrorIsNil)
newState, err := op.Prepare(operation.State{})
c.Check(newState, gc.IsNil)
c.Check(err, gc.ErrorMatches, "squish")
c.Check(*deployer.MockStage.gotInfo, gc.Equals, callbacks.MockGetArchiveInfo.info)
c.Check(*deployer.MockStage.gotAbort, gc.Equals, abort)
}
开发者ID:claudiu-coblis,项目名称:juju,代码行数:25,代码来源:deploy_test.go
示例12: testCommitSuccess_CollectMetricsTime
func (s *RunHookSuite) testCommitSuccess_CollectMetricsTime(c *gc.C, newHook newHook) {
callbacks := &CommitHookCallbacks{
MockCommitHook: &MockCommitHook{},
}
factory := operation.NewFactory(operation.FactoryParams{
Callbacks: callbacks,
})
op, err := newHook(factory, hook.Info{Kind: hooks.CollectMetrics})
c.Assert(err, jc.ErrorIsNil)
nowBefore := time.Now().Unix()
newState, err := op.Commit(overwriteState)
c.Assert(err, jc.ErrorIsNil)
nowAfter := time.Now().Unix()
nowWritten := newState.CollectMetricsTime
c.Logf("%d <= %d <= %d", nowBefore, nowWritten, nowAfter)
c.Check(nowBefore <= nowWritten, jc.IsTrue)
c.Check(nowWritten <= nowAfter, jc.IsTrue)
// Check the other fields match.
newState.CollectMetricsTime = 0
c.Check(newState, gc.DeepEquals, &operation.State{
Started: true,
Kind: operation.Continue,
Step: operation.Pending,
UpdateStatusTime: 1234567,
})
}
开发者ID:mhilton,项目名称:juju,代码行数:29,代码来源:runhook_test.go
示例13: testExecuteConflictError
func (s *DeploySuite) testExecuteConflictError(c *gc.C, newDeploy newDeploy) {
callbacks := NewDeployCallbacks()
deployer := &MockDeployer{
MockNotifyRevert: &MockNoArgs{},
MockNotifyResolved: &MockNoArgs{},
MockStage: &MockStage{},
MockDeploy: &MockNoArgs{err: charm.ErrConflict},
}
factory := operation.NewFactory(operation.FactoryParams{
Deployer: deployer,
Callbacks: callbacks,
})
charmURL := curl("cs:quantal/nyancat-4")
op, err := newDeploy(factory, charmURL)
c.Assert(err, jc.ErrorIsNil)
_, err = op.Prepare(operation.State{})
c.Assert(err, jc.ErrorIsNil)
newState, err := op.Execute(operation.State{})
c.Check(newState, gc.IsNil)
c.Check(err, gc.ErrorMatches, "cannot deploy charm cs:quantal/nyancat-4")
ok := operation.IsDeployConflictError(err)
c.Check(ok, jc.IsTrue)
c.Check(deployer.MockDeploy.called, jc.IsTrue)
}
开发者ID:imoapps,项目名称:juju,代码行数:25,代码来源:deploy_test.go
示例14: TestNeedsGlobalMachineLock
func (s *RunCommandsSuite) TestNeedsGlobalMachineLock(c *gc.C) {
factory := operation.NewFactory(operation.FactoryParams{})
sendResponse := &MockSendResponse{}
op, err := factory.NewCommands(someCommandArgs, sendResponse.Call)
c.Assert(err, jc.ErrorIsNil)
c.Assert(op.NeedsGlobalMachineLock(), jc.IsTrue)
}
开发者ID:mhilton,项目名称:juju,代码行数:7,代码来源:runcommands_test.go
示例15: TestPrepare
func (s *UpdateRelationsSuite) TestPrepare(c *gc.C) {
factory := operation.NewFactory(operation.FactoryParams{})
op, err := factory.NewUpdateRelations(nil)
c.Assert(err, jc.ErrorIsNil)
state, err := op.Prepare(operation.State{})
c.Check(err, jc.ErrorIsNil)
c.Check(state, gc.IsNil)
}
开发者ID:claudiu-coblis,项目名称:juju,代码行数:8,代码来源:relations_test.go
示例16: TestCommit
func (s *UpdateRelationsSuite) TestCommit(c *gc.C) {
factory := operation.NewFactory(nil, nil, nil, nil, nil)
op, err := factory.NewUpdateRelations(nil)
c.Assert(err, jc.ErrorIsNil)
state, err := op.Commit(operation.State{})
c.Check(err, jc.ErrorIsNil)
c.Check(state, gc.IsNil)
}
开发者ID:Pankov404,项目名称:juju,代码行数:8,代码来源:relations_test.go
示例17: TestPrepare
func (s *UpdateStorageSuite) TestPrepare(c *gc.C) {
factory := operation.NewFactory(nil, nil, nil, nil, nil)
op, err := factory.NewUpdateStorage(nil)
c.Assert(err, jc.ErrorIsNil)
state, err := op.Prepare(operation.State{})
c.Check(err, jc.ErrorIsNil)
c.Check(state, gc.IsNil)
}
开发者ID:Pankov404,项目名称:juju,代码行数:8,代码来源:storage_test.go
示例18: TestCommit
func (s *UpdateStorageSuite) TestCommit(c *gc.C) {
factory := operation.NewFactory(operation.FactoryParams{})
op, err := factory.NewUpdateStorage(nil)
c.Assert(err, jc.ErrorIsNil)
state, err := op.Commit(operation.State{})
c.Check(err, jc.ErrorIsNil)
c.Check(state, gc.IsNil)
}
开发者ID:imoapps,项目名称:juju,代码行数:8,代码来源:storage_test.go
示例19: SetUpTest
func (s *FactorySuite) SetUpTest(c *gc.C) {
s.IsolationSuite.SetUpTest(c)
// Yes, this factory will produce useless ops; this suite is just for
// verifying that inadequate args to the factory methods will produce
// the expected errors; and that the results of same get a string
// representation that does not depend on the factory attributes.
s.factory = operation.NewFactory(operation.FactoryParams{})
}
开发者ID:ktsakalozos,项目名称:juju,代码行数:8,代码来源:factory_test.go
示例20: TestResignLeadership_Prepare_Leader
func (s *LeaderSuite) TestResignLeadership_Prepare_Leader(c *gc.C) {
factory := operation.NewFactory(nil, nil, nil, nil, nil)
op, err := factory.NewResignLeadership()
c.Assert(err, jc.ErrorIsNil)
newState, err := op.Prepare(operation.State{Leader: true})
c.Check(newState, gc.IsNil)
c.Check(err, jc.ErrorIsNil)
}
开发者ID:Pankov404,项目名称:juju,代码行数:9,代码来源:leader_test.go
注:本文中的github.com/juju/juju/worker/uniter/operation.NewFactory函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论