serializer_test.go 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. // Copyright 2017 Frédéric Guillot. All rights reserved.
  2. // Use of this source code is governed by the Apache 2.0
  3. // license that can be found in the LICENSE file.
  4. package opml // import "miniflux.app/reader/opml"
  5. import (
  6. "bytes"
  7. "fmt"
  8. "testing"
  9. )
  10. func TestSerialize(t *testing.T) {
  11. var subscriptions SubcriptionList
  12. subscriptions = append(subscriptions, &Subcription{Title: "Feed 1", FeedURL: "http://example.org/feed/1", SiteURL: "http://example.org/1", CategoryName: "Category 1"})
  13. subscriptions = append(subscriptions, &Subcription{Title: "Feed 2", FeedURL: "http://example.org/feed/2", SiteURL: "http://example.org/2", CategoryName: "Category 1"})
  14. subscriptions = append(subscriptions, &Subcription{Title: "Feed 3", FeedURL: "http://example.org/feed/3", SiteURL: "http://example.org/3", CategoryName: "Category 2"})
  15. output := Serialize(subscriptions)
  16. fmt.Println(output)
  17. feeds, err := Parse(bytes.NewBufferString(output))
  18. if err != nil {
  19. t.Error(err)
  20. }
  21. if len(feeds) != 3 {
  22. t.Errorf("Wrong number of subscriptions: %d instead of %d", len(feeds), 3)
  23. }
  24. found := false
  25. for _, feed := range feeds {
  26. if feed.Title == "Feed 1" && feed.CategoryName == "Category 1" &&
  27. feed.FeedURL == "http://example.org/feed/1" && feed.SiteURL == "http://example.org/1" {
  28. found = true
  29. break
  30. }
  31. }
  32. if !found {
  33. t.Error("Serialized feed is incorrect")
  34. }
  35. }