Exemple #1
0
func (s *ResolverOpFactorySuite) TestNewHookError(c *gc.C) {
	s.opFactory.SetErrors(
		errors.New("NewRunHook fails"),
		errors.New("NewSkipHook fails"),
	)
	f := resolver.NewResolverOpFactory(s.opFactory)
	_, err := f.NewRunHook(hook.Info{Kind: hooks.ConfigChanged})
	c.Assert(err, gc.ErrorMatches, "NewRunHook fails")
	_, err = f.NewSkipHook(hook.Info{Kind: hooks.ConfigChanged})
	c.Assert(err, gc.ErrorMatches, "NewSkipHook fails")
}
Exemple #2
0
func (s *ResolverOpFactorySuite) TestActionsCommit(c *gc.C) {
	f := resolver.NewResolverOpFactory(s.opFactory)
	f.RemoteState.Actions = []string{"action 1", "action 2", "action 3"}
	f.LocalState.CompletedActions = map[string]struct{}{}
	op, err := f.NewAction("action 1")
	c.Assert(err, jc.ErrorIsNil)
	_, err = op.Commit(operation.State{})
	c.Assert(err, jc.ErrorIsNil)
	c.Assert(f.LocalState.CompletedActions, gc.DeepEquals, map[string]struct{}{
		"action 1": struct{}{},
	})
}
Exemple #3
0
func (s *ResolverOpFactorySuite) testUpgrade(
	c *gc.C, meth func(resolver.ResolverOpFactory, *charm.URL) (operation.Operation, error),
) {
	f := resolver.NewResolverOpFactory(s.opFactory)
	f.LocalState.Conflicted = true
	curl := charm.MustParseURL("cs:trusty/mysql")
	op, err := meth(f, curl)
	c.Assert(err, jc.ErrorIsNil)
	_, err = op.Commit(operation.State{})
	c.Assert(err, jc.ErrorIsNil)
	c.Assert(f.LocalState.CharmURL, jc.DeepEquals, curl)
	c.Assert(f.LocalState.Conflicted, jc.IsFalse)
}
Exemple #4
0
func (s *ResolverOpFactorySuite) TestCommitError(c *gc.C) {
	f := resolver.NewResolverOpFactory(s.opFactory)
	curl := charm.MustParseURL("cs:trusty/mysql")
	s.opFactory.op.commit = func(operation.State) (*operation.State, error) {
		return nil, errors.New("Commit fails")
	}
	op, err := f.NewUpgrade(curl)
	c.Assert(err, jc.ErrorIsNil)
	_, err = op.Commit(operation.State{})
	c.Assert(err, gc.ErrorMatches, "Commit fails")
	// Local state should not have been updated. We use the same code
	// internally for all operations, so it suffices to test just the
	// upgrade case.
	c.Assert(f.LocalState.CharmURL, gc.IsNil)
}
Exemple #5
0
func (s *ResolverOpFactorySuite) TestNewUpgradeError(c *gc.C) {
	curl := charm.MustParseURL("cs:trusty/mysql")
	s.opFactory.SetErrors(
		errors.New("NewUpgrade fails"),
		errors.New("NewRevertUpgrade fails"),
		errors.New("NewResolvedUpgrade fails"),
	)
	f := resolver.NewResolverOpFactory(s.opFactory)
	_, err := f.NewUpgrade(curl)
	c.Assert(err, gc.ErrorMatches, "NewUpgrade fails")
	_, err = f.NewRevertUpgrade(curl)
	c.Assert(err, gc.ErrorMatches, "NewRevertUpgrade fails")
	_, err = f.NewResolvedUpgrade(curl)
	c.Assert(err, gc.ErrorMatches, "NewResolvedUpgrade fails")
}
Exemple #6
0
func (s *ResolverOpFactorySuite) testUpdateStatusChanged(
	c *gc.C, meth func(resolver.ResolverOpFactory, hook.Info) (operation.Operation, error),
) {
	f := resolver.NewResolverOpFactory(s.opFactory)
	f.RemoteState.UpdateStatusVersion = 1

	op, err := f.NewRunHook(hook.Info{Kind: hooks.UpdateStatus})
	c.Assert(err, jc.ErrorIsNil)
	f.RemoteState.UpdateStatusVersion = 2

	_, err = op.Commit(operation.State{})
	c.Assert(err, jc.ErrorIsNil)

	// Local state's UpdateStatusVersion should be set to what
	// RemoteState's UpdateStatusVersion was when the operation
	// was constructed.
	c.Assert(f.LocalState.UpdateStatusVersion, gc.Equals, 1)
}
Exemple #7
0
func (s *ResolverOpFactorySuite) TestInitialState(c *gc.C) {
	f := resolver.NewResolverOpFactory(s.opFactory)
	c.Assert(f.LocalState, jc.DeepEquals, &resolver.LocalState{})
	c.Assert(f.RemoteState, jc.DeepEquals, remotestate.Snapshot{})
}