parser_test.go 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. package atom_test
  2. import (
  3. "bytes"
  4. "encoding/json"
  5. "fmt"
  6. "io/ioutil"
  7. "path/filepath"
  8. "strings"
  9. "testing"
  10. "github.com/mmcdole/gofeed/atom"
  11. "github.com/stretchr/testify/assert"
  12. )
  13. // Tests
  14. func TestParser_Parse(t *testing.T) {
  15. files, _ := filepath.Glob("../testdata/parser/atom/*.xml")
  16. for _, f := range files {
  17. base := filepath.Base(f)
  18. name := strings.TrimSuffix(base, filepath.Ext(base))
  19. fmt.Printf("Testing %s... ", name)
  20. // Get actual source feed
  21. ff := fmt.Sprintf("../testdata/parser/atom/%s.xml", name)
  22. f, _ := ioutil.ReadFile(ff)
  23. // Parse actual feed
  24. fp := &atom.Parser{}
  25. actual, _ := fp.Parse(bytes.NewReader(f))
  26. // Get json encoded expected feed result
  27. ef := fmt.Sprintf("../testdata/parser/atom/%s.json", name)
  28. e, _ := ioutil.ReadFile(ef)
  29. // Unmarshal expected feed
  30. expected := &atom.Feed{}
  31. json.Unmarshal(e, &expected)
  32. if assert.Equal(t, actual, expected, "Feed file %s.xml did not match expected output %s.json", name, name) {
  33. fmt.Printf("OK\n")
  34. } else {
  35. fmt.Printf("Failed\n")
  36. }
  37. }
  38. }
  39. // TODO: Examples