cpod

Yet another cron-friendly podcatcher

git clone https://git.8pit.net/cpod.git

  1// Copyright (C) 2013-2015 Sören Tempel
  2//
  3// This program is free software: you can redistribute it and/or modify
  4// it under the terms of the GNU General Public License as published by
  5// the Free Software Foundation, either version 3 of the License, or
  6// (at your option) any later version.
  7//
  8// This program is distributed in the hope that it will be useful,
  9// but WITHOUT ANY WARRANTY; without even the implied warranty of
 10// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 11// GNU General Public License for more details.
 12//
 13// You should have received a copy of the GNU General Public License
 14// along with this program. If not, see <http://www.gnu.org/licenses/>.
 15
 16package opml
 17
 18import (
 19	"os"
 20	"path/filepath"
 21	"testing"
 22)
 23
 24func TestCreate(t *testing.T) {
 25	o := Create("Test subscriptions")
 26	if o.Title != "Test subscriptions" {
 27		t.Fatalf("Expected %q - got %q", "Test subscriptions", o.Title)
 28	}
 29
 30	if o.Version != version {
 31		t.Fatalf("Expected %q - got %q", version, o.Version)
 32	}
 33}
 34
 35func TestLoad(t *testing.T) {
 36	outline := Outline{
 37		Text: "Chaosradio",
 38		Type: "rss",
 39		URL:  "http://chaosradio.ccc.de/chaosradio-latest.rss",
 40	}
 41
 42	o, err := Load("testdata/testLoad.opml")
 43	if err != nil {
 44		t.Fatal(err)
 45	}
 46
 47	if len(o.Outlines) != 1 {
 48		t.Fatalf("Expected %d - got %d", 1, len(o.Outlines))
 49	}
 50
 51	if o.Outlines[0] != outline {
 52		t.Fatalf("Expected %q - got %q", outline, o.Outlines[0])
 53	}
 54
 55	if o.Version != version {
 56		t.Fatalf("Expected %q - got %q", "2.0", o.Version)
 57	}
 58
 59	if o.Title != "Subscriptions" {
 60		t.Fatalf("Expected %q - got %q", "Subscriptions", o.Title)
 61	}
 62
 63	if o.Created != "Wed, 15 May 2013 19:30:58 +0200" {
 64		t.Fatalf("Expected %q - got %q", "Wed, 15 May 2013 19:30:58 +0200", o.Created)
 65	}
 66}
 67
 68func TestAdd(t *testing.T) {
 69	testOutline := Outline{
 70		Text: "Testcast",
 71		Type: "atom",
 72		URL:  "http://testcast.com/atom-feed.xml",
 73	}
 74
 75	o := new(OPML)
 76	o.Add("Testcast", "atom", "http://testcast.com/atom-feed.xml")
 77
 78	if o.Outlines[0] != testOutline {
 79		t.Fatalf("Expected %q - got %q", testOutline, o.Outlines[0])
 80	}
 81
 82	if len(o.Outlines) != 1 {
 83		t.Fatalf("Expected %d - got %d", 1, len(o.Outlines))
 84	}
 85}
 86
 87func TestSave(t *testing.T) {
 88	o := Create("Podcasts")
 89	o.Add("Somecast", "rss", "http://somecast.io/feed.rss")
 90
 91	testPath := filepath.Join(os.TempDir(), "testSave.opml")
 92	if err := o.Save(testPath); err != nil {
 93		t.Fatal(err)
 94	}
 95	defer os.Remove(testPath)
 96
 97	loaded, err := Load(testPath)
 98	if err != nil {
 99		t.Fatal(err)
100	}
101
102	if loaded.Title != "Podcasts" {
103		t.Fatal(err)
104	}
105}