コード例 #1
0
ファイル: action_test.go プロジェクト: Pankov404/juju
func (s *ActionSuite) TestMergeIdsErrors(c *gc.C) {

	var tests = []struct {
		ok   bool
		name string
		key  interface{}
	}{
		{ok: false, name: "bool", key: true},
		{ok: false, name: "int", key: 0},
		{ok: false, name: "chan string", key: make(chan string)},

		{ok: true, name: "string", key: ""},
	}

	for _, test := range tests {
		changes, updates := []string{}, map[interface{}]bool{}

		updates[test.key] = true
		err := state.WatcherMergeIds(s.State, &changes, updates)

		if test.ok {
			c.Assert(err, jc.ErrorIsNil)
		} else {
			c.Assert(err, gc.ErrorMatches, "id is not of type string, got "+test.name)
		}
	}
}
コード例 #2
0
ファイル: action_test.go プロジェクト: makyo/juju
func (s *ActionSuite) TestMergeIds(c *gc.C) {
	var tests = []struct {
		changes  string
		adds     string
		removes  string
		expected string
	}{
		{changes: "", adds: "a0,a1", removes: "", expected: "a0,a1"},
		{changes: "a0,a1", adds: "", removes: "a0", expected: "a1"},
		{changes: "a0,a1", adds: "a2", removes: "a0", expected: "a1,a2"},

		{changes: "", adds: "a0,a1,a2", removes: "a0,a2", expected: "a1"},
		{changes: "", adds: "a0,a1,a2", removes: "a0,a1,a2", expected: ""},

		{changes: "a0", adds: "a0,a1,a2", removes: "a0,a2", expected: "a1"},
		{changes: "a1", adds: "a0,a1,a2", removes: "a0,a2", expected: "a1"},
		{changes: "a2", adds: "a0,a1,a2", removes: "a0,a2", expected: "a1"},

		{changes: "a3,a4", adds: "a1,a4,a5", removes: "a1,a3", expected: "a4,a5"},
		{changes: "a0,a1,a2", adds: "a1,a4,a5", removes: "a1,a3", expected: "a0,a2,a4,a5"},
	}

	prefix := state.DocID(s.State, "")

	for ix, test := range tests {
		updates := mapify(prefix, test.adds, test.removes)
		changes := sliceify("", test.changes)
		expected := sliceify("", test.expected)

		c.Log(fmt.Sprintf("test number %d %#v", ix, test))
		err := state.WatcherMergeIds(s.State, &changes, updates, state.ActionNotificationIdToActionId)
		c.Assert(err, jc.ErrorIsNil)
		c.Assert(changes, jc.SameContents, expected)
	}
}
コード例 #3
0
ファイル: action_test.go プロジェクト: kapilt/juju
func (s *ActionSuite) TestMergeIds(c *gc.C) {
	var tests = []struct {
		initial  string
		changes  string
		adds     string
		removes  string
		expected string
	}{
		{initial: "", changes: "", adds: "a0,a1", removes: "", expected: "a0,a1"},
		{initial: "", changes: "a0,a1", adds: "", removes: "a0", expected: "a1"},
		{initial: "", changes: "a0,a1", adds: "a2", removes: "a0", expected: "a1,a2"},

		{initial: "a0", changes: "", adds: "a0,a1,a2", removes: "a0,a2", expected: "a1"},
		{initial: "a0", changes: "", adds: "a0,a1,a2", removes: "a0,a1,a2", expected: ""},

		{initial: "a0", changes: "a0", adds: "a0,a1,a2", removes: "a0,a2", expected: "a1"},
		{initial: "a0", changes: "a1", adds: "a0,a1,a2", removes: "a0,a2", expected: "a1"},
		{initial: "a0", changes: "a2", adds: "a0,a1,a2", removes: "a0,a2", expected: "a1"},

		{initial: "a0,a1,a2", changes: "a3,a4", adds: "a1,a4,a5", removes: "a1,a3", expected: "a4,a5"},
		{initial: "a0,a1,a2", changes: "a0,a1,a2", adds: "a1,a4,a5", removes: "a1,a3", expected: "a0,a2,a4,a5"},
	}

	for ix, test := range tests {
		updates := mapify(test.adds, test.removes)
		changes := newSet(test.changes)
		initial := newSet(test.initial)
		expected := newSet(test.expected)

		c.Log(fmt.Sprintf("test number %d %+v", ix, test))
		err := state.WatcherMergeIds(changes, initial, updates)
		c.Assert(err, gc.IsNil)
		c.Assert(changes.SortedValues(), jc.DeepEquals, expected.SortedValues())
	}
}
コード例 #4
0
ファイル: action_test.go プロジェクト: makyo/juju
func (s *ActionSuite) TestMergeIdsErrors(c *gc.C) {

	var tests = []struct {
		name string
		key  interface{}
	}{
		{name: "bool", key: true},
		{name: "int", key: 0},
		{name: "chan string", key: make(chan string)},
	}

	for _, test := range tests {
		changes, updates := []string{}, map[interface{}]bool{}
		updates[test.key] = true
		err := state.WatcherMergeIds(s.State, &changes, updates, state.ActionNotificationIdToActionId)
		c.Assert(err, gc.ErrorMatches, "id is not of type string, got "+test.name)
	}
}