コード例 #1
0
ファイル: manifold_test.go プロジェクト: bac/juju
func (*ManifoldSuite) TestNewWorkerError(c *gc.C) {
	expectFacade := struct{ lifeflag.Facade }{}
	expectEntity := names.NewMachineTag("33")
	context := dt.StubContext(nil, map[string]interface{}{
		"api-caller": struct{ base.APICaller }{},
	})
	manifold := lifeflag.Manifold(lifeflag.ManifoldConfig{
		APICallerName: "api-caller",
		Entity:        expectEntity,
		Result:        life.IsNotAlive,
		NewFacade: func(_ base.APICaller) (lifeflag.Facade, error) {
			return expectFacade, nil
		},
		NewWorker: func(config lifeflag.Config) (worker.Worker, error) {
			c.Check(config.Facade, gc.Equals, expectFacade)
			c.Check(config.Entity, gc.Equals, expectEntity)
			c.Check(config.Result, gc.NotNil) // uncomparable
			return nil, errors.New("boof")
		},
	})

	worker, err := manifold.Start(context)
	c.Check(worker, gc.IsNil)
	c.Check(err, gc.ErrorMatches, "boof")
}
コード例 #2
0
ファイル: manifold_test.go プロジェクト: bac/juju
func (s *ManifoldSuite) TestStartNewWorkerError(c *gc.C) {
	expectFacade := &fakeFacade{}
	manifold := singular.Manifold(singular.ManifoldConfig{
		ClockName:     "clock",
		APICallerName: "api-caller",
		AgentName:     "agent",
		Duration:      time.Minute,
		NewFacade: func(_ base.APICaller, _ names.MachineTag) (singular.Facade, error) {
			return expectFacade, nil
		},
		NewWorker: func(config singular.FlagConfig) (worker.Worker, error) {
			c.Check(config.Facade, gc.Equals, expectFacade)
			err := config.Validate()
			c.Check(err, jc.ErrorIsNil)
			return nil, errors.New("blomp tik")
		},
	})
	context := dt.StubContext(nil, map[string]interface{}{
		"clock":      &fakeClock{},
		"api-caller": &fakeAPICaller{},
		"agent":      &mockAgent{},
	})

	worker, err := manifold.Start(context)
	c.Check(err, gc.ErrorMatches, "blomp tik")
	c.Check(worker, gc.IsNil)
}
コード例 #3
0
ファイル: servinginfo_setter_test.go プロジェクト: bac/juju
func (s *ServingInfoSetterSuite) startManifold(c *gc.C, a coreagent.Agent, mockAPIPort int) {
	apiCaller := basetesting.APICallerFunc(
		func(objType string, version int, id, request string, args, response interface{}) error {
			c.Assert(objType, gc.Equals, "Agent")
			switch request {
			case "GetEntities":
				c.Assert(args.(params.Entities).Entities, gc.HasLen, 1)
				result := response.(*params.AgentGetEntitiesResults)
				result.Entities = []params.AgentGetEntitiesResult{{
					Jobs: []multiwatcher.MachineJob{multiwatcher.JobManageModel},
				}}
			case "StateServingInfo":
				result := response.(*params.StateServingInfo)
				*result = params.StateServingInfo{
					Cert:       "cert",
					PrivateKey: "key",
					APIPort:    mockAPIPort,
				}
			default:
				c.Fatalf("not sure how to handle: %q", request)
			}
			return nil
		},
	)
	context := dt.StubContext(nil, map[string]interface{}{
		"agent":      a,
		"api-caller": apiCaller,
	})
	w, err := s.manifold.Start(context)
	c.Assert(w, gc.IsNil)
	c.Assert(err, gc.Equals, dependency.ErrUninstall)
}
コード例 #4
0
ファイル: manifold_test.go プロジェクト: makyo/juju
func (s *ManifoldSuite) SetUpSuite(c *gc.C) {
	s.IsolationSuite.SetUpSuite(c)
	s.fakeAgent = &fakeAgent{tag: fakeTag}
	s.fakeCaller = &fakeCaller{}

	s.context = dt.StubContext(nil, map[string]interface{}{
		"wut":     s.fakeAgent,
		"exactly": s.fakeCaller,
	})

	s.newFacade = func(facade machineactions.Facade) func(base.APICaller) machineactions.Facade {
		s.fakeFacade = facade
		return func(apiCaller base.APICaller) machineactions.Facade {
			c.Assert(apiCaller, gc.Equals, s.fakeCaller)
			return facade
		}
	}
	s.newWorker = func(w worker.Worker, err error) func(machineactions.WorkerConfig) (worker.Worker, error) {
		s.fakeWorker = w
		return func(wc machineactions.WorkerConfig) (worker.Worker, error) {
			c.Assert(wc.Facade, gc.Equals, s.fakeFacade)
			c.Assert(wc.MachineTag, gc.Equals, fakeTag)
			c.Assert(wc.HandleAction, gc.Equals, fakeHandleAction)
			return w, err
		}
	}
}
コード例 #5
0
ファイル: servinginfo_setter_test.go プロジェクト: bac/juju
func (s *ServingInfoSetterSuite) checkNotController(c *gc.C, job multiwatcher.MachineJob) {
	a := &mockAgent{}
	apiCaller := basetesting.APICallerFunc(
		func(objType string, version int, id, request string, args, response interface{}) error {
			c.Assert(objType, gc.Equals, "Agent")
			switch request {
			case "GetEntities":
				c.Assert(args.(params.Entities).Entities, gc.HasLen, 1)
				result := response.(*params.AgentGetEntitiesResults)
				result.Entities = []params.AgentGetEntitiesResult{{
					Jobs: []multiwatcher.MachineJob{job},
				}}
			default:
				c.Fatalf("not sure how to handle: %q", request)
			}
			return nil
		},
	)
	w, err := s.manifold.Start(dt.StubContext(nil, map[string]interface{}{
		"agent":      a,
		"api-caller": apiCaller,
	}))
	c.Assert(w, gc.IsNil)
	c.Assert(err, gc.Equals, dependency.ErrUninstall)

	// State serving info shouldn't have been set for this job type.
	c.Assert(a.conf.ssiSet, jc.IsFalse)
}
コード例 #6
0
ファイル: manifold_test.go プロジェクト: kat-co/juju
func (s *ManifoldSuite) TestWorkerFuncMissing(c *gc.C) {
	s.config.WorkerFunc = nil
	context := dt.StubContext(nil, nil)
	worker, err := s.manifold().Start(context)
	c.Check(worker, gc.IsNil)
	c.Check(err, gc.ErrorMatches, "missing WorkerFunc not valid")
}
コード例 #7
0
ファイル: manifold_test.go プロジェクト: bac/juju
func (*ManifoldSuite) TestAgentEntity_Error(c *gc.C) {
	manifold := resumer.Manifold(resumer.ManifoldConfig{
		AgentName:     "agent",
		APICallerName: "api-caller",
	})

	stub := &testing.Stub{}
	stub.SetErrors(errors.New("zap"))
	apiCaller := &fakeAPICaller{stub: stub}
	worker, err := manifold.Start(dt.StubContext(nil, map[string]interface{}{
		"agent":      &fakeAgent{},
		"api-caller": apiCaller,
	}))
	workertest.CheckNilOrKill(c, worker)
	c.Check(err, gc.ErrorMatches, "zap")

	stub.CheckCalls(c, []testing.StubCall{{
		FuncName: "Agent.GetEntities",
		Args: []interface{}{params.Entities{
			Entities: []params.Entity{{
				Tag: "machine-123",
			}},
		}},
	}})
}
コード例 #8
0
ファイル: util_test.go プロジェクト: makyo/juju
// checkManifoldNotValid checks that the supplied ManifoldConfig creates
// a manifold that cannot be started.
func checkManifoldNotValid(c *gc.C, config migrationflag.ManifoldConfig, expect string) {
	manifold := migrationflag.Manifold(config)
	worker, err := manifold.Start(dt.StubContext(nil, nil))
	c.Check(worker, gc.IsNil)
	c.Check(err, gc.ErrorMatches, expect)
	c.Check(err, jc.Satisfies, errors.IsNotValid)
}
コード例 #9
0
ファイル: manifold_test.go プロジェクト: makyo/juju
func (s *ManifoldSuite) TestNoAgent(c *gc.C) {
	context := dt.StubContext(nil, map[string]interface{}{
		"agent": dependency.ErrMissing,
	})
	_, err := s.manifold.Start(context)
	c.Assert(err, gc.Equals, dependency.ErrMissing)
}
コード例 #10
0
ファイル: apiworkers_test.go プロジェクト: makyo/juju
func (s *APIWorkersSuite) TestStartNoStartAPIWorkers(c *gc.C) {
	manifold := machine.APIWorkersManifold(machine.APIWorkersConfig{})
	worker, err := manifold.Start(dt.StubContext(nil, nil))
	c.Check(worker, gc.IsNil)
	c.Check(err, gc.ErrorMatches, "StartAPIWorkers not specified")
	c.Check(s.startCalled, jc.IsFalse)
}
コード例 #11
0
ファイル: housing_test.go プロジェクト: makyo/juju
func (*HousingSuite) TestOccupyLocked(c *gc.C) {
	manifold := util.Housing{
		Occupy: "fortress",
	}.Decorate(dependency.Manifold{})
	abort := make(chan struct{})
	context := dt.StubContext(abort, map[string]interface{}{
		"fortress": newGuest(false),
	})

	// start the start func
	started := make(chan struct{})
	go func() {
		defer close(started)
		worker, err := manifold.Start(context)
		c.Check(worker, gc.IsNil)
		c.Check(errors.Cause(err), gc.Equals, fortress.ErrAborted)
	}()

	// check it's blocked...
	select {
	case <-time.After(coretesting.ShortWait):
	case <-started:
		c.Errorf("Start finished early")
	}

	// ...until the context is aborted.
	close(abort)
	select {
	case <-started:
	case <-time.After(coretesting.LongWait):
		c.Fatalf("timed out")
	}
}
コード例 #12
0
ファイル: manifold_test.go プロジェクト: bac/juju
func (s *ManifoldSuite) TestNewWorkerError(c *gc.C) {
	fakeClock := &fakeClock{}
	fakeFacade := &fakeFacade{}
	fakeAPICaller := &fakeAPICaller{}

	stub := testing.Stub{}
	manifold := charmrevisionmanifold.Manifold(charmrevisionmanifold.ManifoldConfig{
		APICallerName: "api-caller",
		ClockName:     "clock",
		NewFacade: func(apiCaller base.APICaller) (charmrevisionmanifold.Facade, error) {
			stub.AddCall("NewFacade", apiCaller)
			return fakeFacade, nil
		},
		NewWorker: func(config charmrevision.Config) (worker.Worker, error) {
			stub.AddCall("NewWorker", config)
			return nil, errors.New("snrght")
		},
	})

	_, err := manifold.Start(dt.StubContext(nil, map[string]interface{}{
		"api-caller": fakeAPICaller,
		"clock":      fakeClock,
	}))
	c.Check(err, gc.ErrorMatches, "cannot create worker: snrght")
	stub.CheckCalls(c, []testing.StubCall{{
		"NewFacade", []interface{}{fakeAPICaller},
	}, {
		"NewWorker", []interface{}{charmrevision.Config{
			RevisionUpdater: fakeFacade,
			Clock:           fakeClock,
		}},
	}})
}
コード例 #13
0
ファイル: manifold_test.go プロジェクト: makyo/juju
func (s *ManifoldSuite) SetUpSuite(c *gc.C) {
	s.IsolationSuite.SetUpSuite(c)
	s.fakeAgent = &fakeAgent{}
	s.fakeCaller = &fakeCaller{}
	s.context = dt.StubContext(nil, map[string]interface{}{
		"agent":      s.fakeAgent,
		"api-caller": s.fakeCaller,
	})
	s.newFacade = func(facade retrystrategy.Facade) func(base.APICaller) retrystrategy.Facade {
		s.fakeFacade = facade
		return func(apiCaller base.APICaller) retrystrategy.Facade {
			c.Assert(apiCaller, gc.Equals, s.fakeCaller)
			return facade
		}
	}
	s.newWorker = func(w worker.Worker, err error) func(retrystrategy.WorkerConfig) (worker.Worker, error) {
		s.fakeWorker = w
		return func(wc retrystrategy.WorkerConfig) (worker.Worker, error) {
			c.Assert(wc.Facade, gc.Equals, s.fakeFacade)
			c.Assert(wc.AgentTag, gc.Equals, fakeTag)
			c.Assert(wc.RetryStrategy, gc.Equals, fakeStrategy)
			return w, err
		}
	}
}
コード例 #14
0
ファイル: manifold_test.go プロジェクト: bac/juju
func (s *ManifoldSuite) TestNewWorker_Error(c *gc.C) {
	clock := &fakeClock{}
	facade := &fakeFacade{}
	manifold := resumer.Manifold(resumer.ManifoldConfig{
		AgentName:     "agent",
		APICallerName: "api-caller",
		Clock:         clock,
		Interval:      time.Hour,
		NewFacade: func(base.APICaller) (resumer.Facade, error) {
			return facade, nil
		},
		NewWorker: func(actual resumer.Config) (worker.Worker, error) {
			c.Check(actual, jc.DeepEquals, resumer.Config{
				Facade:   facade,
				Clock:    clock,
				Interval: time.Hour,
			})
			return nil, errors.New("blam")
		},
	})

	worker, err := manifold.Start(dt.StubContext(nil, map[string]interface{}{
		"agent":      &fakeAgent{},
		"api-caller": newFakeAPICaller(multiwatcher.JobManageModel),
	}))
	workertest.CheckNilOrKill(c, worker)
	c.Check(err, gc.ErrorMatches, "blam")
}
コード例 #15
0
ファイル: servinginfo_setter_test.go プロジェクト: bac/juju
func (s *ServingInfoSetterSuite) TestEntityLookupFailure(c *gc.C) {
	// Set up a fake Agent and APICaller
	a := &mockAgent{}
	apiCaller := basetesting.APICallerFunc(
		func(objType string, version int, id, request string, args, response interface{}) error {
			c.Assert(objType, gc.Equals, "Agent")
			switch request {
			case "GetEntities":
				c.Assert(args.(params.Entities).Entities, gc.HasLen, 1)
				result := response.(*params.AgentGetEntitiesResults)
				result.Entities = []params.AgentGetEntitiesResult{{
					Error: &params.Error{Message: "boom"},
				}}
			default:
				c.Fatalf("not sure how to handle: %q", request)
			}
			return nil
		},
	)
	// Call the manifold's start func with a fake resource getter that
	// returns the fake Agent and APICaller
	context := dt.StubContext(nil, map[string]interface{}{
		"agent":      a,
		"api-caller": apiCaller,
	})
	w, err := s.manifold.Start(context)
	c.Assert(w, gc.IsNil)
	c.Assert(err, gc.ErrorMatches, "checking controller status: boom")
}
コード例 #16
0
ファイル: manifold_test.go プロジェクト: bac/juju
func (s *ManifoldSuite) TestStartMissingAgent(c *gc.C) {
	context := dt.StubContext(nil, map[string]interface{}{
		"agent-name": dependency.ErrMissing,
	})
	worker, err := s.manifold.Start(context)
	c.Check(worker, gc.IsNil)
	c.Check(err, gc.Equals, dependency.ErrMissing)
}
コード例 #17
0
ファイル: manifold_test.go プロジェクト: kat-co/juju
func (s *ManifoldSuite) TestStartClockMissing(c *gc.C) {
	manifold := leadership.Manifold(leadership.ManifoldConfig{})
	context := dt.StubContext(nil, nil)
	worker, err := manifold.Start(context)
	c.Check(worker, gc.IsNil)
	c.Check(err.Error(), gc.Equals, "missing Clock not valid")
	c.Check(err, jc.Satisfies, errors.IsNotValid)
}
コード例 #18
0
ファイル: manifold_test.go プロジェクト: bac/juju
func (*manifoldSuite) TestWorkerError(c *gc.C) {
	manifold := makeManifold(nil, errors.New("boglodite"))
	result, err := manifold.Start(dt.StubContext(nil, map[string]interface{}{
		"the-caller":  apitesting.APICallerFunc(nil),
		"the-environ": &fakeEnviron{},
	}))
	c.Assert(result, gc.IsNil)
	c.Assert(err, gc.ErrorMatches, "boglodite")
}
コード例 #19
0
ファイル: manifold_test.go プロジェクト: bac/juju
func (*manifoldSuite) TestAPIError(c *gc.C) {
	manifold := makeManifold(nil, nil)
	result, err := manifold.Start(dt.StubContext(nil, map[string]interface{}{
		"the-caller":  &fakeAPICaller{},
		"the-environ": &fakeEnviron{},
	}))
	c.Assert(result, gc.IsNil)
	c.Assert(err, gc.ErrorMatches, "machine undertaker client requires a model API connection")
}
コード例 #20
0
ファイル: manifold_test.go プロジェクト: bac/juju
func (*manifoldSuite) TestMissingEnviron(c *gc.C) {
	manifold := makeManifold(nil, nil)
	result, err := manifold.Start(dt.StubContext(nil, map[string]interface{}{
		"the-caller":  &fakeAPICaller{},
		"the-environ": dependency.ErrMissing,
	}))
	c.Assert(result, gc.IsNil)
	c.Assert(errors.Cause(err), gc.Equals, dependency.ErrMissing)
}
コード例 #21
0
ファイル: apiworkers_test.go プロジェクト: makyo/juju
func (s *APIWorkersSuite) TestStartSuccess(c *gc.C) {
	context := dt.StubContext(nil, map[string]interface{}{
		"api-caller": new(mockAPIConn),
	})
	worker, err := s.manifold.Start(context)
	c.Check(worker, gc.Not(gc.IsNil))
	c.Check(err, jc.ErrorIsNil)
	c.Check(s.startCalled, jc.IsTrue)
}
コード例 #22
0
ファイル: servinginfo_setter_test.go プロジェクト: bac/juju
func (s *ServingInfoSetterSuite) TestStartAPICallerMissing(c *gc.C) {
	context := dt.StubContext(nil, map[string]interface{}{
		"agent":      &mockAgent{},
		"api-caller": dependency.ErrMissing,
	})
	worker, err := s.manifold.Start(context)
	c.Check(worker, gc.IsNil)
	c.Check(err, gc.Equals, dependency.ErrMissing)
}
コード例 #23
0
ファイル: apiworkers_test.go プロジェクト: makyo/juju
func (s *APIWorkersSuite) TestStartAPIMissing(c *gc.C) {
	context := dt.StubContext(nil, map[string]interface{}{
		"api-caller": dependency.ErrMissing,
	})
	worker, err := s.manifold.Start(context)
	c.Check(worker, gc.IsNil)
	c.Check(err, gc.Equals, dependency.ErrMissing)
	c.Check(s.startCalled, jc.IsFalse)
}
コード例 #24
0
ファイル: manifold_test.go プロジェクト: bac/juju
func (s *ManifoldSuite) TestStartMissingAPICaller(c *gc.C) {
	context := dt.StubContext(nil, map[string]interface{}{
		"api-caller":   dependency.ErrMissing,
		"metric-spool": s.factory,
	})
	worker, err := s.manifold.Start(context)
	c.Check(worker, gc.IsNil)
	c.Check(err, gc.ErrorMatches, dependency.ErrMissing.Error())
}
コード例 #25
0
ファイル: manifold_test.go プロジェクト: kat-co/juju
func (s *ManifoldSuite) TestStartAPICallerMissing(c *gc.C) {
	context := dt.StubContext(nil, map[string]interface{}{
		"agent-name":      &dummyAgent{},
		"api-caller-name": dependency.ErrMissing,
	})

	worker, err := s.manifold().Start(context)
	c.Check(worker, gc.IsNil)
	c.Check(errors.Cause(err), gc.Equals, dependency.ErrMissing)
}
コード例 #26
0
ファイル: manifold_test.go プロジェクト: bac/juju
func (s *ManifoldSuite) TestMissingEnviron(c *gc.C) {
	manifold := s.makeManifold()
	w, err := manifold.Start(dt.StubContext(nil, map[string]interface{}{
		"agent":      struct{ agent.Agent }{},
		"api-caller": struct{ base.APICaller }{},
		"environ":    dependency.ErrMissing,
	}))
	c.Check(w, gc.IsNil)
	c.Check(errors.Cause(err), gc.Equals, dependency.ErrMissing)
}
コード例 #27
0
ファイル: manifold_test.go プロジェクト: bac/juju
func (*manifoldSuite) TestSuccess(c *gc.C) {
	w := fakeWorker{name: "Boris"}
	manifold := makeManifold(&w, nil)
	result, err := manifold.Start(dt.StubContext(nil, map[string]interface{}{
		"the-caller":  apitesting.APICallerFunc(nil),
		"the-environ": &fakeEnviron{},
	}))
	c.Assert(err, jc.ErrorIsNil)
	c.Assert(result, gc.DeepEquals, &w)
}
コード例 #28
0
ファイル: manifold_test.go プロジェクト: makyo/juju
func (*ManifoldSuite) TestStartMissingAPICaller(c *gc.C) {
	context := dt.StubContext(nil, map[string]interface{}{
		"api-caller": dependency.ErrMissing,
	})
	manifold := migrationflag.Manifold(validManifoldConfig())

	worker, err := manifold.Start(context)
	c.Check(worker, gc.IsNil)
	c.Check(errors.Cause(err), gc.Equals, dependency.ErrMissing)
}
コード例 #29
0
ファイル: manifold_test.go プロジェクト: kat-co/juju
func (s *ManifoldSuite) TestStartError(c *gc.C) {
	s.startErr = errors.New("boom")
	context := dt.StubContext(nil, map[string]interface{}{
		"agent-name":      &dummyAgent{},
		"api-caller-name": &dummyApiCaller{},
	})

	worker, err := s.manifold().Start(context)
	c.Check(worker, gc.IsNil)
	c.Check(err, gc.ErrorMatches, "boom")
}
コード例 #30
0
ファイル: flag_test.go プロジェクト: makyo/juju
func (*FlagSuite) TestManifoldStartGateMissing(c *gc.C) {
	context := dt.StubContext(nil, map[string]interface{}{
		"some-gate": dependency.ErrMissing,
	})
	manifold := gate.FlagManifold(gate.FlagManifoldConfig{
		GateName: "some-gate",
	})
	worker, err := manifold.Start(context)
	c.Check(worker, gc.IsNil)
	c.Check(errors.Cause(err), gc.Equals, dependency.ErrMissing)
}