예제 #1
0
// Test getting a doc.
func TestGet(t *testing.T) {
	assert := asserts.NewTestingAsserts(t, true)
	u, _ := url.Parse("http://www.rssboard.org/files/sample-rss-2.xml")
	r, err := rss.Get(u)
	assert.Nil(err, "Getting the RSS document returns no error.")
	err = r.Validate()
	assert.Nil(err, "Validating returns no error.")
	b := &bytes.Buffer{}
	err = rss.Encode(b, r)
	assert.Nil(err, "Encoding returns no error.")
	applog.Infof("--- RSS ---\n%s", b)
}
예제 #2
0
// Test encoding and decoding a doc.
func TestEncodeDecode(t *testing.T) {
	assert := asserts.NewTestingAsserts(t, true)
	r1 := &rss.RSS{
		Version: rss.Version,
		Channel: rss.Channel{
			Title:       "Test Encode/Decode",
			Link:        "http://www.tidelan.biz/rss",
			Description: "A test document.",
			Categories: []*rss.Category{
				{"foo", ""},
				{"bar", "baz"},
			},
			Items: []*rss.Item{
				{
					Title:       "Item 1",
					Description: "This is item 1",
					GUID:        &rss.GUID{"http://www.tidelan.biz/rss/item-1", false},
				},
				{
					Title:       "Item 2",
					Description: "This is item 2",
					GUID:        &rss.GUID{"http://www.tidelan.biz/rss/item-2", true},
				},
			},
		},
	}
	b := &bytes.Buffer{}

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

	r2, err := rss.Decode(b)
	assert.Nil(err, "Decoding returns no error.")
	assert.Equal(r2.Channel.Title, "Test Encode/Decode", "Title has been decoded correctly.")
	assert.Length(r2.Channel.Items, 2, "Decoded document has the right number of items.")
}