go-feedparser

Simple RSS and ATOM feed parser

git clone https://git.8pit.net/go-feedparser.git

 1// This program is free software: you can redistribute it and/or modify
 2// it under the terms of the GNU General Public License as published by
 3// the Free Software Foundation, either version 3 of the License, or
 4// (at your option) any later version.
 5//
 6// This program is distributed in the hope that it will be useful,
 7// but WITHOUT ANY WARRANTY; without even the implied warranty of
 8// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 9// GNU General Public License for more details.
10//
11// You should have received a copy of the GNU General Public License
12// along with this program. If not, see <http://www.gnu.org/licenses/>.
13//
14// This is a slightly modified version of 'encoding/xml/read_test.go'.
15// Copyright 2009 The Go Authors. All rights reserved. Use of this
16// source code is governed by a BSD-style license that can be found in
17// the LICENSE file.
18
19package feedparser
20
21import (
22	"net/http"
23	"testing"
24)
25
26type testpair struct {
27	URL  string
28	Type string
29}
30
31func TestParse(t *testing.T) {
32	tests := []testpair{
33		{"http://cyber.law.harvard.edu/rss/examples/rss2sample.xml", "rss"},
34		{"http://www.heise.de/developer/rss/news-atom.xml", "atom"},
35		{"http://blog.case.edu/news/feed.atom", "atom"},
36	}
37
38	for _, test := range tests {
39		resp, err := http.Get(test.URL)
40		if err != nil {
41			t.Fatal(err)
42		}
43
44		reader := resp.Body
45		defer reader.Close()
46
47		feed, err := Parse(reader)
48		if err != nil {
49			t.Fatal(err)
50		}
51
52		if feed.Type != test.Type {
53			t.Fatalf("Expected %q - got %q", test.Type, feed.Type)
54		}
55	}
56}