From 6f6e20dd3953594cd869cf981fb806440685cd21 Mon Sep 17 00:00:00 2001 From: davy wybiral Date: Fri, 26 Jul 2019 18:58:42 -0500 Subject: [PATCH] fix JSONFeed Hubs (#74) * fix JSONFeed Hubs * Add JSONHub test * fixed test output --- feed_test.go | 31 +++++++++++++++++++++++++++++++ json.go | 2 +- 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/feed_test.go b/feed_test.go index ecc036b..7493bf1 100644 --- a/feed_test.go +++ b/feed_test.go @@ -481,3 +481,34 @@ func TestFeedSorted(t *testing.T) { t.Errorf("JSON not what was expected. Got:\n||%s||\n\nExpected:\n||%s||\n", got, jsonOutputSorted) } } + +var jsonOutputHub = `{ + "version": "https://jsonfeed.org/version/1", + "title": "feed title", + "hubs": [ + { + "type": "WebSub", + "url": "https://websub-hub.example" + } + ] +}` + +func TestJSONHub(t *testing.T) { + feed := &JSONFeed{ + Version: "https://jsonfeed.org/version/1", + Title: "feed title", + Hubs: []*JSONHub{ + &JSONHub{ + Type: "WebSub", + Url: "https://websub-hub.example", + }, + }, + } + json, err := feed.ToJSON() + if err != nil { + t.Errorf("unexpected error encoding JSON: %v", err) + } + if json != jsonOutputHub { + t.Errorf("JSON not what was expected. Got:\n%s\n\nExpected:\n%s\n", json, jsonOutputHub) + } +} diff --git a/json.go b/json.go index 75a82fd..0302c22 100644 --- a/json.go +++ b/json.go @@ -103,7 +103,7 @@ type JSONFeed struct { Favicon string `json:"favicon,omitempty"` Author *JSONAuthor `json:"author,omitempty"` Expired *bool `json:"expired,omitempty"` - Hubs []*JSONItem `json:"hubs,omitempty"` + Hubs []*JSONHub `json:"hubs,omitempty"` Items []*JSONItem `json:"items,omitempty"` } -- 2.45.2