Esempio n. 1
0
// Test encoding and decoding a doc.
func TestEncodeDecode(t *testing.T) {
	assert := audit.NewTestingAssertion(t, true)
	a1 := &atom.Feed{
		XMLNS:   atom.XMLNS,
		Id:      "http://tideland.biz/feed/atom",
		Title:   &atom.Text{"Test Encode/Decode", "", "text"},
		Updated: atom.ComposeTime(time.Now()),
		Entries: []*atom.Entry{
			{
				Id:      "http://tideland.biz/feed/atom/1",
				Title:   &atom.Text{"Entry 1", "", "text"},
				Updated: atom.ComposeTime(time.Now()),
			},
			{
				Id:      "http://tideland.biz/feed/atom/2",
				Title:   &atom.Text{"Entry 2", "", "text"},
				Updated: atom.ComposeTime(time.Now()),
			},
		},
	}
	b := &bytes.Buffer{}

	err := atom.Encode(b, a1)
	assert.Nil(err, "Encoding returns no error.")
	assert.Substring(`<title type="text">Test Encode/Decode</title>`, b.String(), "Title has been encoded correctly.")

	a2, err := atom.Decode(b)
	assert.Nil(err, "Decoding returns no error.")
	assert.Equal(a2.Title.Text, "Test Encode/Decode", "Title has been decoded correctly.")
	assert.Length(a2.Entries, 2, "Decoded feed has the right number of items.")
}
Esempio n. 2
0
// Test getting a feed.
func TestGet(t *testing.T) {
	assert := audit.NewTestingAssertion(t, true)
	u, _ := url.Parse("http://rss.golem.de/rss.php?feed=ATOM1.0")
	f, err := atom.Get(u)
	assert.Nil(err, "Getting the Atom document returns no error.")
	err = f.Validate()
	assert.Nil(err, "Validating returns no error.")
	b := &bytes.Buffer{}
	err = atom.Encode(b, f)
	assert.Nil(err, "Encoding returns no error.")
	assert.Logf("--- Atom ---\n%s", b)
}