Exemple #1
0
func (s *actionSuite) TestParseActionResultTag(c *gc.C) {
	parseActionResultTagTests := []struct {
		tag      string
		expected names.Tag
		err      error
	}{
		{
			tag:      "",
			expected: nil,
			err:      names.InvalidTagError("", ""),
		}, {
			tag:      "actionresult-good" + names.ActionResultMarker + "123",
			expected: names.NewActionResultTag("good" + names.ActionResultMarker + "123"),
			err:      nil,
		}, {
			tag:      "actionresult-good/0" + names.ActionResultMarker + "123",
			expected: names.NewActionResultTag("good/0" + names.ActionResultMarker + "123"),
			err:      nil,
		}, {
			tag:      "actionresult-bad/00" + names.ActionResultMarker + "123",
			expected: nil,
			err:      names.InvalidTagError("actionresult-bad/00"+names.ActionResultMarker+"123", names.ActionResultTagKind),
		}, {
			tag:      "dave",
			expected: nil,
			err:      names.InvalidTagError("dave", ""),
		}, {
			tag:      "actionresult-dave/0",
			expected: nil,
			err:      names.InvalidTagError("actionresult-dave/0", names.ActionResultTagKind),
		}, {
			tag:      "action",
			expected: nil,
			err:      names.InvalidTagError("action", ""),
		}, {
			tag:      "user-dave",
			expected: nil,
			err:      names.InvalidTagError("user-dave", names.ActionResultTagKind),
		}}

	for i, t := range parseActionResultTagTests {
		c.Logf("test %d: %s", i, t.tag)
		got, err := names.ParseActionResultTag(t.tag)
		if err != nil || t.err != nil {
			c.Check(err, gc.DeepEquals, t.err)
			continue
		}
		c.Check(got, gc.FitsTypeOf, t.expected)
		c.Check(got, gc.Equals, t.expected)
	}
}
Exemple #2
0
func (s *actionSuite) TestPrefixSuffix(c *gc.C) {
	var tests = []struct {
		prefix string
		suffix int
	}{
		{prefix: "asdf", suffix: 0},
		{prefix: "qwer/0", suffix: 10},
		{prefix: "zxcv/3", suffix: 11},
	}

	for _, test := range tests {
		suf := fmt.Sprintf("%d", test.suffix)

		action := names.NewActionTag(test.prefix + names.ActionMarker + suf)
		c.Assert(action.Prefix(), gc.Equals, test.prefix)
		c.Assert(action.Sequence(), gc.Equals, test.suffix)

		result := names.NewActionResultTag(test.prefix + names.ActionResultMarker + suf)
		c.Assert(result.Prefix(), gc.Equals, test.prefix)
		c.Assert(result.Sequence(), gc.Equals, test.suffix)

		c.Assert(action.PrefixTag(), gc.Not(gc.IsNil))
		c.Assert(action.PrefixTag(), gc.DeepEquals, result.PrefixTag())
	}
}
Exemple #3
0
func (s *actionSuite) TestInvalidActionResultNamesPanic(c *gc.C) {
	invalidActionResultNameTests := []string{
		"",         // blank is not a valid action id
		"admin",    // probably a user name, which isn't a valid action id
		"blah_a_0", // accidentally use an actionId instead of actionResultId
	}

	for _, name := range invalidActionResultNameTests {
		expect := fmt.Sprintf("%q is not a valid action result id", name)
		testFunc := func() { names.NewActionResultTag(name) }
		c.Assert(testFunc, gc.PanicMatches, expect)
	}
}
Exemple #4
0
// ActionResultTag returns an ActionResultTag constructed from this
// actionResult's Prefix and Sequence
func (a *ActionResult) ActionResultTag() names.ActionResultTag {
	return names.NewActionResultTag(a.Id())
}