예제 #1
0
func (s *headersSuite) TestAppendEntryOmitting(c *C) {
	buf := bytes.NewBufferString("start: .")

	asserts.AppendEntry(buf, "bar:", []interface{}{}, 0)

	m, err := asserts.ParseHeaders(buf.Bytes())
	c.Assert(err, IsNil)
	c.Check(m, DeepEquals, map[string]interface{}{
		"start": ".",
	})

	lst := []interface{}{nil, []interface{}{}, "z"}

	buf = bytes.NewBufferString("start: .")

	asserts.AppendEntry(buf, "bar:", lst, 0)

	m, err = asserts.ParseHeaders(buf.Bytes())
	c.Assert(err, IsNil)
	c.Check(m, DeepEquals, map[string]interface{}{
		"start": ".",
		"bar":   []interface{}{"z"},
	})

	buf = bytes.NewBufferString("start: .")

	asserts.AppendEntry(buf, "bar:", map[string]interface{}{}, 0)

	m, err = asserts.ParseHeaders(buf.Bytes())
	c.Assert(err, IsNil)
	c.Check(m, DeepEquals, map[string]interface{}{
		"start": ".",
	})
}
예제 #2
0
func (s *headersSuite) TestAppendEntrySimple(c *C) {
	buf := bytes.NewBufferString("start: .")

	asserts.AppendEntry(buf, "bar:", "baz", 0)

	m, err := asserts.ParseHeaders(buf.Bytes())
	c.Assert(err, IsNil)
	c.Check(m, DeepEquals, map[string]interface{}{
		"start": ".",
		"bar":   "baz",
	})
}
예제 #3
0
func (s *headersSuite) TestAppendEntryListNested(c *C) {
	lst := []interface{}{"x", "a\nb\n", "", []interface{}{"u1", []interface{}{"w1", "w2"}}}

	buf := bytes.NewBufferString("start: .")

	asserts.AppendEntry(buf, "bar:", lst, 0)

	m, err := asserts.ParseHeaders(buf.Bytes())
	c.Assert(err, IsNil)
	c.Check(m, DeepEquals, map[string]interface{}{
		"start": ".",
		"bar":   lst,
	})
}
예제 #4
0
func (s *headersSuite) TestAppendEntrySimpleMap(c *C) {
	mp := map[string]interface{}{
		"x":  "X",
		"yy": "YY",
		"z5": "",
	}

	buf := bytes.NewBufferString("start: .")

	asserts.AppendEntry(buf, "bar:", mp, 0)

	m, err := asserts.ParseHeaders(buf.Bytes())
	c.Assert(err, IsNil)
	c.Check(m, DeepEquals, map[string]interface{}{
		"start": ".",
		"bar":   mp,
	})
}
예제 #5
0
func (s *headersSuite) TestAppendEntryNestedMap(c *C) {
	mp := map[string]interface{}{
		"x":  "X",
		"u":  []interface{}{"u1", "u2"},
		"yy": "YY1\nYY2",
		"m":  map[string]interface{}{"a": "A", "b": map[string]interface{}{"x": "X", "y": "Y"}},
	}

	buf := bytes.NewBufferString("start: .")

	asserts.AppendEntry(buf, "bar:", mp, 0)

	m, err := asserts.ParseHeaders(buf.Bytes())
	c.Assert(err, IsNil)
	c.Check(m, DeepEquals, map[string]interface{}{
		"start": ".",
		"bar":   mp,
	})
}
예제 #6
0
func (s *headersSuite) TestAppendEntryMultiline(c *C) {
	multilines := []string{
		"a\n",
		"a\nb",
		"baz\n baz1\nbaz2",
		"baz\n baz1\nbaz2\n",
		"baz\n baz1\nbaz2\n\n",
	}

	for _, multiline := range multilines {
		buf := bytes.NewBufferString("start: .")

		asserts.AppendEntry(buf, "bar:", multiline, 0)

		m, err := asserts.ParseHeaders(buf.Bytes())
		c.Assert(err, IsNil)
		c.Check(m, DeepEquals, map[string]interface{}{
			"start": ".",
			"bar":   multiline,
		})
	}
}