1// Copyright (C) 2013-2015 Sören Tempel2//3// This program is free software: you can redistribute it and/or modify4// it under the terms of the GNU General Public License as published by5// the Free Software Foundation, either version 3 of the License, or6// (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 of10// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the11// GNU General Public License for more details.12//13// You should have received a copy of the GNU General Public License14// along with this program. If not, see <http://www.gnu.org/licenses/>.1516package opml1718import (19 "os"20 "path/filepath"21 "testing"22)2324func 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 }2930 if o.Version != version {31 t.Fatalf("Expected %q - got %q", version, o.Version)32 }33}3435func TestLoad(t *testing.T) {36 outline := Outline{37 Text: "Chaosradio",38 Type: "rss",39 URL: "http://chaosradio.ccc.de/chaosradio-latest.rss",40 }4142 o, err := Load("testdata/testLoad.opml")43 if err != nil {44 t.Fatal(err)45 }4647 if len(o.Outlines) != 1 {48 t.Fatalf("Expected %d - got %d", 1, len(o.Outlines))49 }5051 if o.Outlines[0] != outline {52 t.Fatalf("Expected %q - got %q", outline, o.Outlines[0])53 }5455 if o.Version != version {56 t.Fatalf("Expected %q - got %q", "2.0", o.Version)57 }5859 if o.Title != "Subscriptions" {60 t.Fatalf("Expected %q - got %q", "Subscriptions", o.Title)61 }6263 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}6768func TestAdd(t *testing.T) {69 testOutline := Outline{70 Text: "Testcast",71 Type: "atom",72 URL: "http://testcast.com/atom-feed.xml",73 }7475 o := new(OPML)76 o.Add("Testcast", "atom", "http://testcast.com/atom-feed.xml")7778 if o.Outlines[0] != testOutline {79 t.Fatalf("Expected %q - got %q", testOutline, o.Outlines[0])80 }8182 if len(o.Outlines) != 1 {83 t.Fatalf("Expected %d - got %d", 1, len(o.Outlines))84 }85}8687func TestSave(t *testing.T) {88 o := Create("Podcasts")89 o.Add("Somecast", "rss", "http://somecast.io/feed.rss")9091 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)9697 loaded, err := Load(testPath)98 if err != nil {99 t.Fatal(err)100 }101102 if loaded.Title != "Podcasts" {103 t.Fatal(err)104 }105}