コード例 #1
0
ファイル: headers_test.go プロジェクト: niemeyer/snapd
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
ファイル: headers_test.go プロジェクト: niemeyer/snapd
func (s *headersSuite) TestParseHeadersListNestedMultiline(c *C) {
	m, err := asserts.ParseHeaders([]byte(`foo:
  - x
  -
      y1
      y2
      
  - z
bar: baz`))
	c.Assert(err, IsNil)
	c.Check(m, DeepEquals, map[string]interface{}{
		"foo": []interface{}{"x", "y1\ny2\n", "z"},
		"bar": "baz",
	})

	m, err = asserts.ParseHeaders([]byte(`bar: baz
foo:
  -
    - u1
    - u2
  -
      y1
      y2
      `))
	c.Assert(err, IsNil)
	c.Check(m, DeepEquals, map[string]interface{}{
		"foo": []interface{}{[]interface{}{"u1", "u2"}, "y1\ny2\n"},
		"bar": "baz",
	})
}
コード例 #3
0
ファイル: headers_test.go プロジェクト: niemeyer/snapd
func (s *headersSuite) TestParseHeadersMapErrors(c *C) {
	_, err := asserts.ParseHeaders([]byte(`foo:
  x X
bar: baz`))
	c.Check(err, ErrorMatches, `map entry missing ':' separator: "x X"`)

	_, err = asserts.ParseHeaders([]byte(`foo:
  0x: X
bar: baz`))
	c.Check(err, ErrorMatches, `invalid map entry key: "0x"`)

	_, err = asserts.ParseHeaders([]byte(`foo:
  a: a
  a: b`))
	c.Check(err, ErrorMatches, `repeated map entry: "a"`)
}
コード例 #4
0
ファイル: headers_test.go プロジェクト: niemeyer/snapd
func (s *headersSuite) TestParseHeadersSimple(c *C) {
	m, err := asserts.ParseHeaders([]byte(`foo: 1
bar: baz`))
	c.Assert(err, IsNil)
	c.Check(m, DeepEquals, map[string]interface{}{
		"foo": "1",
		"bar": "baz",
	})
}
コード例 #5
0
ファイル: headers_test.go プロジェクト: niemeyer/snapd
func (s *headersSuite) TestParseHeadersErrors(c *C) {
	_, err := asserts.ParseHeaders([]byte(`foo: 1
bar:baz`))
	c.Check(err, ErrorMatches, `header entry should have a space or newline \(for multiline\) before value: "bar:baz"`)

	_, err = asserts.ParseHeaders([]byte(`foo:
 - x
  - y
  - z
bar: baz`))
	c.Check(err, ErrorMatches, `expected 4 chars nesting prefix after multiline introduction "foo:": " - x"`)

	_, err = asserts.ParseHeaders([]byte(`foo:
  - x
  - y
  - z
bar:`))
	c.Check(err, ErrorMatches, `expected 4 chars nesting prefix after multiline introduction "bar:": EOF`)
}
コード例 #6
0
ファイル: headers_test.go プロジェクト: niemeyer/snapd
func (s *headersSuite) TestParseHeadersMultiline(c *C) {
	m, err := asserts.ParseHeaders([]byte(`foo:
    abc
    
bar: baz`))
	c.Assert(err, IsNil)
	c.Check(m, DeepEquals, map[string]interface{}{
		"foo": "abc\n",
		"bar": "baz",
	})

	m, err = asserts.ParseHeaders([]byte(`foo: 1
bar:
    baz`))
	c.Assert(err, IsNil)
	c.Check(m, DeepEquals, map[string]interface{}{
		"foo": "1",
		"bar": "baz",
	})

	m, err = asserts.ParseHeaders([]byte(`foo: 1
bar:
    baz
    `))
	c.Assert(err, IsNil)
	c.Check(m, DeepEquals, map[string]interface{}{
		"foo": "1",
		"bar": "baz\n",
	})

	m, err = asserts.ParseHeaders([]byte(`foo: 1
bar:
    baz
    
    baz2`))
	c.Assert(err, IsNil)
	c.Check(m, DeepEquals, map[string]interface{}{
		"foo": "1",
		"bar": "baz\n\nbaz2",
	})
}
コード例 #7
0
ファイル: headers_test.go プロジェクト: niemeyer/snapd
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",
	})
}
コード例 #8
0
ファイル: headers_test.go プロジェクト: niemeyer/snapd
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,
	})
}
コード例 #9
0
ファイル: headers_test.go プロジェクト: niemeyer/snapd
func (s *headersSuite) TestParseHeadersSimpleMap(c *C) {
	m, err := asserts.ParseHeaders([]byte(`foo:
  x: X
  yy: YY
  z5: 
bar: baz`))
	c.Assert(err, IsNil)
	c.Check(m, DeepEquals, map[string]interface{}{
		"foo": map[string]interface{}{
			"x":  "X",
			"yy": "YY",
			"z5": "",
		},
		"bar": "baz",
	})
}
コード例 #10
0
ファイル: headers_test.go プロジェクト: niemeyer/snapd
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,
	})
}
コード例 #11
0
ファイル: headers_test.go プロジェクト: niemeyer/snapd
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,
	})
}
コード例 #12
0
ファイル: headers_test.go プロジェクト: niemeyer/snapd
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,
		})
	}
}
コード例 #13
0
ファイル: headers_test.go プロジェクト: niemeyer/snapd
func (s *headersSuite) TestParseHeadersMapNestedMultiline(c *C) {
	m, err := asserts.ParseHeaders([]byte(`foo:
  x: X
  yy:
      YY1
      YY2
  u:
    - u1
    - u2
bar: baz`))
	c.Assert(err, IsNil)
	c.Check(m, DeepEquals, map[string]interface{}{
		"foo": map[string]interface{}{
			"x":  "X",
			"yy": "YY1\nYY2",
			"u":  []interface{}{"u1", "u2"},
		},
		"bar": "baz",
	})

	m, err = asserts.ParseHeaders([]byte(`one:
  two:
    three: `))
	c.Assert(err, IsNil)
	c.Check(m, DeepEquals, map[string]interface{}{
		"one": map[string]interface{}{
			"two": map[string]interface{}{
				"three": "",
			},
		},
	})

	m, err = asserts.ParseHeaders([]byte(`one:
  two:
      three`))
	c.Assert(err, IsNil)
	c.Check(m, DeepEquals, map[string]interface{}{
		"one": map[string]interface{}{
			"two": "three",
		},
	})

	m, err = asserts.ParseHeaders([]byte(`map-within-map:
  lev1:
    lev2: x`))
	c.Assert(err, IsNil)
	c.Check(m, DeepEquals, map[string]interface{}{
		"map-within-map": map[string]interface{}{
			"lev1": map[string]interface{}{
				"lev2": "x",
			},
		},
	})

	m, err = asserts.ParseHeaders([]byte(`list-of-maps:
  -
    entry: foo
    bar: baz
  -
    entry: bar`))
	c.Assert(err, IsNil)
	c.Check(m, DeepEquals, map[string]interface{}{
		"list-of-maps": []interface{}{
			map[string]interface{}{
				"entry": "foo",
				"bar":   "baz",
			},
			map[string]interface{}{
				"entry": "bar",
			},
		},
	})
}