diff --git a/api/responses/.snapshots/responses-snapshotMatcher-Match-Responses AlbumList with data should match JSON b/api/responses/.snapshots/responses-snapshotMatcher-Match-Responses AlbumList with data should match JSON new file mode 100644 index 00000000..50eb05c0 --- /dev/null +++ b/api/responses/.snapshots/responses-snapshotMatcher-Match-Responses AlbumList with data should match JSON @@ -0,0 +1 @@ +{"status":"ok","version":"1.8.0","albumList":{"album":[{"id":"1","isDir":false,"title":"title"}]}} diff --git a/api/responses/.snapshots/responses-snapshotMatcher-Match-Responses AlbumList with data should match XML b/api/responses/.snapshots/responses-snapshotMatcher-Match-Responses AlbumList with data should match XML new file mode 100644 index 00000000..e9a9e284 --- /dev/null +++ b/api/responses/.snapshots/responses-snapshotMatcher-Match-Responses AlbumList with data should match XML @@ -0,0 +1 @@ + diff --git a/api/responses/.snapshots/responses-snapshotMatcher-Match-Responses AlbumList without data should match JSON b/api/responses/.snapshots/responses-snapshotMatcher-Match-Responses AlbumList without data should match JSON new file mode 100644 index 00000000..52933f99 --- /dev/null +++ b/api/responses/.snapshots/responses-snapshotMatcher-Match-Responses AlbumList without data should match JSON @@ -0,0 +1 @@ +{"status":"ok","version":"1.8.0","albumList":{}} diff --git a/api/responses/.snapshots/responses-snapshotMatcher-Match-Responses AlbumList without data should match XML b/api/responses/.snapshots/responses-snapshotMatcher-Match-Responses AlbumList without data should match XML new file mode 100644 index 00000000..66367095 --- /dev/null +++ b/api/responses/.snapshots/responses-snapshotMatcher-Match-Responses AlbumList without data should match XML @@ -0,0 +1 @@ + diff --git a/api/responses/.snapshots/responses-snapshotMatcher-Match-Responses Child with data should match JSON b/api/responses/.snapshots/responses-snapshotMatcher-Match-Responses Child with data should match JSON new file mode 100644 index 00000000..de1b4ab5 --- /dev/null +++ b/api/responses/.snapshots/responses-snapshotMatcher-Match-Responses Child with data should match JSON @@ -0,0 +1 @@ +{"status":"ok","version":"1.8.0","directory":{"child":[{"id":"1","isDir":true,"title":"title","album":"album","artist":"artist","track":1,"year":1985,"genre":"Rock","coverArt":"1","size":"8421341","contentType":"audio/flac","suffix":"flac","starred":"2016-03-02T20:30:00Z","transcodedContentType":"audio/mpeg","transcodedSuffix":"mp3","duration":146,"bitRate":320}],"id":"1","name":"N"}} diff --git a/api/responses/.snapshots/responses-snapshotMatcher-Match-Responses Child with data should match XML b/api/responses/.snapshots/responses-snapshotMatcher-Match-Responses Child with data should match XML new file mode 100644 index 00000000..08ce917a --- /dev/null +++ b/api/responses/.snapshots/responses-snapshotMatcher-Match-Responses Child with data should match XML @@ -0,0 +1 @@ + diff --git a/api/responses/.snapshots/responses-snapshotMatcher-Match-Responses Directory with data should match JSON b/api/responses/.snapshots/responses-snapshotMatcher-Match-Responses Directory with data should match JSON new file mode 100644 index 00000000..d2374a7b --- /dev/null +++ b/api/responses/.snapshots/responses-snapshotMatcher-Match-Responses Directory with data should match JSON @@ -0,0 +1 @@ +{"status":"ok","version":"1.8.0","directory":{"child":[{"id":"1","isDir":false,"title":"title"}],"id":"1","name":"N"}} diff --git a/api/responses/.snapshots/responses-snapshotMatcher-Match-Responses Directory with data should match XML b/api/responses/.snapshots/responses-snapshotMatcher-Match-Responses Directory with data should match XML new file mode 100644 index 00000000..37d5f05d --- /dev/null +++ b/api/responses/.snapshots/responses-snapshotMatcher-Match-Responses Directory with data should match XML @@ -0,0 +1 @@ + diff --git a/api/responses/.snapshots/responses-snapshotMatcher-Match-Responses Directory without data should match JSON b/api/responses/.snapshots/responses-snapshotMatcher-Match-Responses Directory without data should match JSON new file mode 100644 index 00000000..634b2ac9 --- /dev/null +++ b/api/responses/.snapshots/responses-snapshotMatcher-Match-Responses Directory without data should match JSON @@ -0,0 +1 @@ +{"status":"ok","version":"1.8.0","directory":{"id":"1","name":"N"}} diff --git a/api/responses/.snapshots/responses-snapshotMatcher-Match-Responses Directory without data should match XML b/api/responses/.snapshots/responses-snapshotMatcher-Match-Responses Directory without data should match XML new file mode 100644 index 00000000..7dc25197 --- /dev/null +++ b/api/responses/.snapshots/responses-snapshotMatcher-Match-Responses Directory without data should match XML @@ -0,0 +1 @@ + diff --git a/api/responses/.snapshots/responses-snapshotMatcher-Match-Responses EmptyResponse should match JSON b/api/responses/.snapshots/responses-snapshotMatcher-Match-Responses EmptyResponse should match JSON new file mode 100644 index 00000000..88a5af61 --- /dev/null +++ b/api/responses/.snapshots/responses-snapshotMatcher-Match-Responses EmptyResponse should match JSON @@ -0,0 +1 @@ +{"status":"ok","version":"1.8.0"} diff --git a/api/responses/.snapshots/responses-snapshotMatcher-Match-Responses EmptyResponse should match XML b/api/responses/.snapshots/responses-snapshotMatcher-Match-Responses EmptyResponse should match XML new file mode 100644 index 00000000..c392d4b8 --- /dev/null +++ b/api/responses/.snapshots/responses-snapshotMatcher-Match-Responses EmptyResponse should match XML @@ -0,0 +1 @@ + diff --git a/api/responses/.snapshots/responses-snapshotMatcher-Match-Responses Indexes with data should match JSON b/api/responses/.snapshots/responses-snapshotMatcher-Match-Responses Indexes with data should match JSON new file mode 100644 index 00000000..b1f56886 --- /dev/null +++ b/api/responses/.snapshots/responses-snapshotMatcher-Match-Responses Indexes with data should match JSON @@ -0,0 +1 @@ +{"status":"ok","version":"1.8.0","indexes":{"index":[{"name":"A","artist":[{"id":"111","name":"aaa"}]}],"lastModified":"1","ignoredArticles":"A"}} diff --git a/api/responses/.snapshots/responses-snapshotMatcher-Match-Responses Indexes with data should match XML b/api/responses/.snapshots/responses-snapshotMatcher-Match-Responses Indexes with data should match XML new file mode 100644 index 00000000..b5493f87 --- /dev/null +++ b/api/responses/.snapshots/responses-snapshotMatcher-Match-Responses Indexes with data should match XML @@ -0,0 +1 @@ + diff --git a/api/responses/.snapshots/responses-snapshotMatcher-Match-Responses Indexes without data should match JSON b/api/responses/.snapshots/responses-snapshotMatcher-Match-Responses Indexes without data should match JSON new file mode 100644 index 00000000..1354beca --- /dev/null +++ b/api/responses/.snapshots/responses-snapshotMatcher-Match-Responses Indexes without data should match JSON @@ -0,0 +1 @@ +{"status":"ok","version":"1.8.0","indexes":{"lastModified":"1","ignoredArticles":"A"}} diff --git a/api/responses/.snapshots/responses-snapshotMatcher-Match-Responses Indexes without data should match XML b/api/responses/.snapshots/responses-snapshotMatcher-Match-Responses Indexes without data should match XML new file mode 100644 index 00000000..a63f84ea --- /dev/null +++ b/api/responses/.snapshots/responses-snapshotMatcher-Match-Responses Indexes without data should match XML @@ -0,0 +1 @@ + diff --git a/api/responses/.snapshots/responses-snapshotMatcher-Match-Responses License should match JSON b/api/responses/.snapshots/responses-snapshotMatcher-Match-Responses License should match JSON new file mode 100644 index 00000000..81044ba9 --- /dev/null +++ b/api/responses/.snapshots/responses-snapshotMatcher-Match-Responses License should match JSON @@ -0,0 +1 @@ +{"status":"ok","version":"1.8.0","license":{"valid":true}} diff --git a/api/responses/.snapshots/responses-snapshotMatcher-Match-Responses License should match XML b/api/responses/.snapshots/responses-snapshotMatcher-Match-Responses License should match XML new file mode 100644 index 00000000..4ef4e2b6 --- /dev/null +++ b/api/responses/.snapshots/responses-snapshotMatcher-Match-Responses License should match XML @@ -0,0 +1 @@ + diff --git a/api/responses/.snapshots/responses-snapshotMatcher-Match-Responses MusicFolders with data should match JSON b/api/responses/.snapshots/responses-snapshotMatcher-Match-Responses MusicFolders with data should match JSON new file mode 100644 index 00000000..3aec470a --- /dev/null +++ b/api/responses/.snapshots/responses-snapshotMatcher-Match-Responses MusicFolders with data should match JSON @@ -0,0 +1 @@ +{"status":"ok","version":"1.8.0","musicFolders":{"musicFolder":[{"id":"111","name":"aaa"},{"id":"222","name":"bbb"}]}} diff --git a/api/responses/.snapshots/responses-snapshotMatcher-Match-Responses MusicFolders with data should match XML b/api/responses/.snapshots/responses-snapshotMatcher-Match-Responses MusicFolders with data should match XML new file mode 100644 index 00000000..e657891c --- /dev/null +++ b/api/responses/.snapshots/responses-snapshotMatcher-Match-Responses MusicFolders with data should match XML @@ -0,0 +1 @@ + diff --git a/api/responses/.snapshots/responses-snapshotMatcher-Match-Responses MusicFolders without data should match JSON b/api/responses/.snapshots/responses-snapshotMatcher-Match-Responses MusicFolders without data should match JSON new file mode 100644 index 00000000..fd722392 --- /dev/null +++ b/api/responses/.snapshots/responses-snapshotMatcher-Match-Responses MusicFolders without data should match JSON @@ -0,0 +1 @@ +{"status":"ok","version":"1.8.0","musicFolders":{}} diff --git a/api/responses/.snapshots/responses-snapshotMatcher-Match-Responses MusicFolders without data should match XML b/api/responses/.snapshots/responses-snapshotMatcher-Match-Responses MusicFolders without data should match XML new file mode 100644 index 00000000..a659b4cc --- /dev/null +++ b/api/responses/.snapshots/responses-snapshotMatcher-Match-Responses MusicFolders without data should match XML @@ -0,0 +1 @@ + diff --git a/api/responses/.snapshots/responses-snapshotMatcher-Match-Responses Playlists with data should match JSON b/api/responses/.snapshots/responses-snapshotMatcher-Match-Responses Playlists with data should match JSON new file mode 100644 index 00000000..851e598b --- /dev/null +++ b/api/responses/.snapshots/responses-snapshotMatcher-Match-Responses Playlists with data should match JSON @@ -0,0 +1 @@ +{"status":"ok","version":"1.8.0","playlists":{"playlist":[{"id":"111","name":"aaa"},{"id":"222","name":"bbb"}]}} diff --git a/api/responses/.snapshots/responses-snapshotMatcher-Match-Responses Playlists with data should match XML b/api/responses/.snapshots/responses-snapshotMatcher-Match-Responses Playlists with data should match XML new file mode 100644 index 00000000..6fbaf11a --- /dev/null +++ b/api/responses/.snapshots/responses-snapshotMatcher-Match-Responses Playlists with data should match XML @@ -0,0 +1 @@ + diff --git a/api/responses/.snapshots/responses-snapshotMatcher-Match-Responses Playlists without data should match JSON b/api/responses/.snapshots/responses-snapshotMatcher-Match-Responses Playlists without data should match JSON new file mode 100644 index 00000000..8f34d597 --- /dev/null +++ b/api/responses/.snapshots/responses-snapshotMatcher-Match-Responses Playlists without data should match JSON @@ -0,0 +1 @@ +{"status":"ok","version":"1.8.0","playlists":{}} diff --git a/api/responses/.snapshots/responses-snapshotMatcher-Match-Responses Playlists without data should match XML b/api/responses/.snapshots/responses-snapshotMatcher-Match-Responses Playlists without data should match XML new file mode 100644 index 00000000..7a3f391d --- /dev/null +++ b/api/responses/.snapshots/responses-snapshotMatcher-Match-Responses Playlists without data should match XML @@ -0,0 +1 @@ + diff --git a/api/responses/.snapshots/responses-snapshotMatcher-Match-Responses User with data should match JSON b/api/responses/.snapshots/responses-snapshotMatcher-Match-Responses User with data should match JSON new file mode 100644 index 00000000..3b60ed95 --- /dev/null +++ b/api/responses/.snapshots/responses-snapshotMatcher-Match-Responses User with data should match JSON @@ -0,0 +1 @@ +{"status":"ok","version":"1.8.0","user":{"username":"deluan","email":"cloudsonic@deluan.com","scrobblingEnabled":false,"adminRole":false,"settingsRole":false,"downloadRole":false,"uploadRole":false,"playlistRole":false,"coverArtRole":false,"commentRole":false,"podcastRole":false,"streamRole":false,"jukeboxRole":false,"shareRole":false,"videoConversionRole":false,"folder":[1]}} diff --git a/api/responses/.snapshots/responses-snapshotMatcher-Match-Responses User with data should match XML b/api/responses/.snapshots/responses-snapshotMatcher-Match-Responses User with data should match XML new file mode 100644 index 00000000..6ec872d1 --- /dev/null +++ b/api/responses/.snapshots/responses-snapshotMatcher-Match-Responses User with data should match XML @@ -0,0 +1 @@ +1 diff --git a/api/responses/.snapshots/responses-snapshotMatcher-Match-Responses User without data should match JSON b/api/responses/.snapshots/responses-snapshotMatcher-Match-Responses User without data should match JSON new file mode 100644 index 00000000..f348788a --- /dev/null +++ b/api/responses/.snapshots/responses-snapshotMatcher-Match-Responses User without data should match JSON @@ -0,0 +1 @@ +{"status":"ok","version":"1.8.0","user":{"username":"deluan","scrobblingEnabled":false,"adminRole":false,"settingsRole":false,"downloadRole":false,"uploadRole":false,"playlistRole":false,"coverArtRole":false,"commentRole":false,"podcastRole":false,"streamRole":false,"jukeboxRole":false,"shareRole":false,"videoConversionRole":false}} diff --git a/api/responses/.snapshots/responses-snapshotMatcher-Match-Responses User without data should match XML b/api/responses/.snapshots/responses-snapshotMatcher-Match-Responses User without data should match XML new file mode 100644 index 00000000..ec540d7c --- /dev/null +++ b/api/responses/.snapshots/responses-snapshotMatcher-Match-Responses User without data should match XML @@ -0,0 +1 @@ + diff --git a/api/responses/responses_suite_test.go b/api/responses/responses_suite_test.go new file mode 100644 index 00000000..d5e909fa --- /dev/null +++ b/api/responses/responses_suite_test.go @@ -0,0 +1,41 @@ +package responses + +import ( + "fmt" + "testing" + + "github.com/bradleyjkemp/cupaloy" + "github.com/cloudsonic/sonic-server/log" + "github.com/onsi/ginkgo" + "github.com/onsi/gomega" + "github.com/onsi/gomega/types" +) + +func TestSubsonicApiResponses(t *testing.T) { + log.SetLevel(log.LevelError) + gomega.RegisterFailHandler(ginkgo.Fail) + ginkgo.RunSpecs(t, "Subsonic API Responses Suite") +} + +func MatchSnapshot() types.GomegaMatcher { + c := cupaloy.New(cupaloy.FailOnUpdate(false)) + return &snapshotMatcher{c} +} + +type snapshotMatcher struct { + c *cupaloy.Config +} + +func (matcher snapshotMatcher) Match(actual interface{}) (success bool, err error) { + err = matcher.c.SnapshotMulti(ginkgo.CurrentGinkgoTestDescription().FullTestText, actual) + success = err == nil + return +} + +func (matcher snapshotMatcher) FailureMessage(actual interface{}) (message string) { + return fmt.Sprintf("Expected to match saved snapshot\n") +} + +func (matcher snapshotMatcher) NegatedFailureMessage(actual interface{}) (message string) { + return fmt.Sprintf("Expected to not match saved snapshot\n") +} diff --git a/api/responses/responses_test.go b/api/responses/responses_test.go index 50c26dea..4fb0ab81 100644 --- a/api/responses/responses_test.go +++ b/api/responses/responses_test.go @@ -1,93 +1,114 @@ +//+build linux darwin + +// TODO Fix snapshot tests in Windows +// Response Snapshot tests. Only run in Linux and macOS, as they fail in Windows +// Probably because of EOL char differences package responses_test import ( - "testing" + "encoding/json" + "encoding/xml" "time" . "github.com/cloudsonic/sonic-server/api/responses" - . "github.com/cloudsonic/sonic-server/tests" - . "github.com/smartystreets/goconvey/convey" + . "github.com/onsi/ginkgo" + . "github.com/onsi/gomega" ) -func TestSubsonicResponses(t *testing.T) { +var _ = Describe("Responses", func() { + var response *Subsonic + BeforeEach(func() { + response = &Subsonic{Status: "ok", Version: "1.8.0"} + }) - response := &Subsonic{Status: "ok", Version: "1.0.0"} - - Convey("Subject: Subsonic Responses", t, func() { - Convey("EmptyResponse", func() { - Convey("XML", func() { - So(response, ShouldMatchXML, ``) - }) - Convey("JSON", func() { - So(response, ShouldMatchJSON, `{"status":"ok","version":"1.0.0"}`) - }) + Describe("EmptyResponse", func() { + It("should match XML", func() { + Expect(xml.Marshal(response)).To(MatchSnapshot()) }) + It("should match JSON", func() { + Expect(json.Marshal(response)).To(MatchSnapshot()) + }) + }) - Convey("License", func() { + Describe("License", func() { + BeforeEach(func() { response.License = &License{Valid: true} - Convey("XML", func() { - So(response, ShouldMatchXML, ``) + }) + It("should match XML", func() { + Expect(xml.Marshal(response)).To(MatchSnapshot()) + }) + It("should match JSON", func() { + Expect(json.Marshal(response)).To(MatchSnapshot()) + }) + }) + + Describe("MusicFolders", func() { + BeforeEach(func() { + response.MusicFolders = &MusicFolders{} + }) + + Context("without data", func() { + It("should match XML", func() { + Expect(xml.Marshal(response)).To(MatchSnapshot()) }) - Convey("JSON", func() { - So(response, ShouldMatchJSON, `{"license":{"valid":true},"status":"ok","version":"1.0.0"}`) + It("should match JSON", func() { + Expect(json.Marshal(response)).To(MatchSnapshot()) }) }) - Convey("MusicFolders", func() { - response.MusicFolders = &MusicFolders{} - - Convey("With data", func() { + Context("with data", func() { + BeforeEach(func() { folders := make([]MusicFolder, 2) folders[0] = MusicFolder{Id: "111", Name: "aaa"} folders[1] = MusicFolder{Id: "222", Name: "bbb"} response.MusicFolders.Folders = folders - - Convey("XML", func() { - So(response, ShouldMatchXML, ``) - }) - Convey("JSON", func() { - So(response, ShouldMatchJSON, `{"musicFolders":{"musicFolder":[{"id":"111","name":"aaa"},{"id":"222","name":"bbb"}]},"status":"ok","version":"1.0.0"}`) - }) }) - Convey("Without data", func() { - Convey("XML", func() { - So(response, ShouldMatchXML, ``) - }) - Convey("JSON", func() { - So(response, ShouldMatchJSON, `{"musicFolders":{},"status":"ok","version":"1.0.0"}`) - }) + + It("should match XML", func() { + Expect(xml.Marshal(response)).To(MatchSnapshot()) + }) + It("should match JSON", func() { + Expect(json.Marshal(response)).To(MatchSnapshot()) + }) + }) + }) + + Describe("Indexes", func() { + BeforeEach(func() { + response.Indexes = &Indexes{LastModified: "1", IgnoredArticles: "A"} + }) + + Context("without data", func() { + It("should match XML", func() { + Expect(xml.Marshal(response)).To(MatchSnapshot()) + }) + It("should match JSON", func() { + Expect(json.Marshal(response)).To(MatchSnapshot()) }) }) - Convey("Indexes", func() { - artists := make([]Artist, 1) - artists[0] = Artist{Id: "111", Name: "aaa"} - response.Indexes = &Indexes{LastModified: "1", IgnoredArticles: "A"} - - Convey("With data", func() { + Context("with data", func() { + BeforeEach(func() { + artists := make([]Artist, 1) + artists[0] = Artist{Id: "111", Name: "aaa"} index := make([]Index, 1) index[0] = Index{Name: "A", Artists: artists} response.Indexes.Index = index - Convey("XML", func() { - So(response, ShouldMatchXML, ``) - }) - Convey("JSON", func() { - So(response, ShouldMatchJSON, `{"indexes":{"ignoredArticles":"A","index":[{"artist":[{"id":"111","name":"aaa"}],"name":"A"}],"lastModified":"1"},"status":"ok","version":"1.0.0"}`) - }) }) - Convey("Without data", func() { - Convey("XML", func() { - So(response, ShouldMatchXML, ``) - }) - Convey("JSON", func() { - So(response, ShouldMatchJSON, `{"indexes":{"ignoredArticles":"A","lastModified":"1"},"status":"ok","version":"1.0.0"}`) - }) + + It("should match XML", func() { + Expect(xml.Marshal(response)).To(MatchSnapshot()) + }) + It("should match JSON", func() { + Expect(json.Marshal(response)).To(MatchSnapshot()) }) }) + }) - Convey("Child", func() { - response.Directory = &Directory{Id: "1", Name: "N"} - Convey("With all data", func() { + Describe("Child", func() { + Context("with data", func() { + BeforeEach(func() { + response.Directory = &Directory{Id: "1", Name: "N"} child := make([]Child, 1) t := time.Date(2016, 03, 2, 20, 30, 0, 0, time.UTC) child[0] = Child{ @@ -97,135 +118,134 @@ func TestSubsonicResponses(t *testing.T) { Duration: 146, BitRate: 320, Starred: &t, } response.Directory.Child = child - Convey("XML", func() { - So(response, ShouldMatchXML, ``) - }) - Convey("JSON", func() { - So(response, ShouldMatchJSON, `{"directory":{"child":[{"album":"album","artist":"artist","bitRate":320,"contentType":"audio/flac","coverArt":"1","duration":146,"genre":"Rock","id":"1","isDir":true,"size":"8421341","starred":"2016-03-02T20:30:00Z","suffix":"flac","title":"title","track":1,"transcodedContentType":"audio/mpeg","transcodedSuffix":"mp3","year":1985}],"id":"1","name":"N"},"status":"ok","version":"1.0.0"}`) - }) + }) + + It("should match XML", func() { + Expect(xml.Marshal(response)).To(MatchSnapshot()) + }) + It("should match JSON", func() { + Expect(json.Marshal(response)).To(MatchSnapshot()) + }) + }) + }) + + Describe("Directory", func() { + BeforeEach(func() { + response.Directory = &Directory{Id: "1", Name: "N"} + }) + + Context("without data", func() { + It("should match XML", func() { + Expect(xml.Marshal(response)).To(MatchSnapshot()) + }) + It("should match JSON", func() { + Expect(json.Marshal(response)).To(MatchSnapshot()) }) }) - Convey("Directory", func() { - response.Directory = &Directory{Id: "1", Name: "N"} - Convey("Without data", func() { - Convey("XML", func() { - So(response, ShouldMatchXML, ``) - }) - Convey("JSON", func() { - So(response, ShouldMatchJSON, `{"directory":{"id":"1","name":"N"},"status":"ok","version":"1.0.0"}`) - }) - }) - Convey("With just required data", func() { + Context("with data", func() { + BeforeEach(func() { child := make([]Child, 1) child[0] = Child{Id: "1", Title: "title", IsDir: false} response.Directory.Child = child - Convey("XML", func() { - So(response, ShouldMatchXML, ``) - }) - Convey("JSON", func() { - So(response, ShouldMatchJSON, `{"directory":{"child":[{"id":"1","isDir":false,"title":"title"}],"id":"1","name":"N"},"status":"ok","version":"1.0.0"}`) - }) + }) + + It("should match XML", func() { + Expect(xml.Marshal(response)).To(MatchSnapshot()) + }) + It("should match JSON", func() { + Expect(json.Marshal(response)).To(MatchSnapshot()) + }) + }) + }) + + Describe("AlbumList", func() { + BeforeEach(func() { + response.AlbumList = &AlbumList{} + }) + + Context("without data", func() { + It("should match XML", func() { + Expect(xml.Marshal(response)).To(MatchSnapshot()) + }) + It("should match JSON", func() { + Expect(json.Marshal(response)).To(MatchSnapshot()) }) }) - Convey("AlbumList", func() { - response.AlbumList = &AlbumList{} - Convey("Without data", func() { - Convey("XML", func() { - So(response, ShouldMatchXML, ``) - }) - Convey("JSON", func() { - So(response, ShouldMatchJSON, `{"albumList":{},"status":"ok","version":"1.0.0"}`) - }) - }) - Convey("With just required data", func() { + Context("with data", func() { + BeforeEach(func() { child := make([]Child, 1) child[0] = Child{Id: "1", Title: "title", IsDir: false} response.AlbumList.Album = child - Convey("XML", func() { - So(response, ShouldMatchXML, ``) - }) - Convey("JSON", func() { - So(response, ShouldMatchJSON, `{"albumList":{"album":[{"id":"1","isDir":false,"title":"title"}]},"status":"ok","version":"1.0.0"}`) - }) + }) + + It("should match XML", func() { + Expect(xml.Marshal(response)).To(MatchSnapshot()) + }) + It("should match JSON", func() { + Expect(json.Marshal(response)).To(MatchSnapshot()) + }) + }) + }) + + Describe("User", func() { + BeforeEach(func() { + response.User = &User{Username: "deluan"} + }) + + Context("without data", func() { + It("should match XML", func() { + Expect(xml.Marshal(response)).To(MatchSnapshot()) + }) + It("should match JSON", func() { + Expect(json.Marshal(response)).To(MatchSnapshot()) }) }) - Convey("User", func() { - response.User = &User{Username: "deluan"} - Convey("Without optional fields", func() { - Convey("XML", func() { - So(response, ShouldMatchXML, ``) - }) - Convey("JSON", func() { - So(response, ShouldMatchJSON, `{"status":"ok","user":{"adminRole":false,"commentRole":false,"coverArtRole":false,"downloadRole":false,"jukeboxRole":false,"playlistRole":false,"podcastRole":false,"scrobblingEnabled":false,"settingsRole":false,"shareRole":false,"streamRole":false,"uploadRole":false,"username":"deluan","videoConversionRole":false},"version":"1.0.0"}`) - }) - }) - Convey("With optional fields", func() { + Context("with data", func() { + BeforeEach(func() { response.User.Email = "cloudsonic@deluan.com" response.User.Folder = []int{1} - Convey("XML", func() { - So(response, ShouldMatchXML, `1`) - }) - Convey("JSON", func() { - So(response, ShouldMatchJSON, `{"status":"ok","user":{"adminRole":false,"commentRole":false,"coverArtRole":false,"downloadRole":false,"email":"cloudsonic@deluan.com","folder":[1],"jukeboxRole":false,"playlistRole":false,"podcastRole":false,"scrobblingEnabled":false,"settingsRole":false,"shareRole":false,"streamRole":false,"uploadRole":false,"username":"deluan","videoConversionRole":false},"version":"1.0.0"}`) - }) + }) + + It("should match XML", func() { + Expect(xml.Marshal(response)).To(MatchSnapshot()) + }) + It("should match JSON", func() { + Expect(json.Marshal(response)).To(MatchSnapshot()) }) }) - Convey("Playlists", func() { - response.Playlists = &Playlists{} + }) - Convey("Without data", func() { - Convey("XML", func() { - So(response, ShouldMatchXML, ``) - }) - Convey("JSON", func() { - So(response, ShouldMatchJSON, `{"playlists":{},"status":"ok","version":"1.0.0"}`) - }) + Describe("Playlists", func() { + BeforeEach(func() { + response.Playlists = &Playlists{} + }) + + Context("without data", func() { + It("should match XML", func() { + Expect(xml.Marshal(response)).To(MatchSnapshot()) }) - Convey("With data", func() { + It("should match JSON", func() { + Expect(json.Marshal(response)).To(MatchSnapshot()) + }) + }) + + Context("with data", func() { + BeforeEach(func() { pls := make([]Playlist, 2) pls[0] = Playlist{Id: "111", Name: "aaa"} pls[1] = Playlist{Id: "222", Name: "bbb"} response.Playlists.Playlist = pls + }) - Convey("XML", func() { - So(response, ShouldMatchXML, ``) - }) - Convey("JSON", func() { - So(response, ShouldMatchJSON, `{"playlists":{"playlist":[{"id":"111","name":"aaa"},{"id":"222","name":"bbb"}]},"status":"ok","version":"1.0.0"}`) - }) + It("should match XML", func() { + Expect(xml.Marshal(response)).To(MatchSnapshot()) }) - }) - - Convey("Playlist", func() { - response.Playlist = &PlaylistWithSongs{} - response.Playlist.Id = "1" - response.Playlist.Name = "My Playlist" - Convey("Without data", func() { - Convey("XML", func() { - So(response, ShouldMatchXML, ``) - }) - Convey("JSON", func() { - So(response, ShouldMatchJSON, `{"playlist":{"id":"1","name":"My Playlist"},"status":"ok","version":"1.0.0"}`) - }) + It("should match JSON", func() { + Expect(json.Marshal(response)).To(MatchSnapshot()) }) - Convey("With just required data", func() { - entry := make([]Child, 1) - entry[0] = Child{Id: "1", Title: "title", IsDir: false} - response.Playlist.Entry = entry - Convey("XML", func() { - So(response, ShouldMatchXML, ``) - }) - Convey("JSON", func() { - So(response, ShouldMatchJSON, `{"playlist":{"entry":[{"id":"1","isDir":false,"title":"title"}],"id":"1","name":"My Playlist"},"status":"ok","version":"1.0.0"}`) - }) - }) - }) - Reset(func() { - response = &Subsonic{Status: "ok", Version: "1.0.0"} }) }) - -} +}) diff --git a/go.mod b/go.mod index 073cbadc..f1a4e196 100644 --- a/go.mod +++ b/go.mod @@ -4,6 +4,7 @@ go 1.13 require ( github.com/BurntSushi/toml v0.3.0 // indirect + github.com/bradleyjkemp/cupaloy v2.3.0+incompatible github.com/cupcake/rdb v0.0.0-20161107195141-43ba34106c76 // indirect github.com/deluan/gomate v0.0.0-20160327212459-3eb40643dd6f github.com/dhowden/itl v0.0.0-20170329215456-9fbe21093131 diff --git a/go.sum b/go.sum index 14ff0ce8..b47f7653 100644 --- a/go.sum +++ b/go.sum @@ -1,5 +1,7 @@ github.com/BurntSushi/toml v0.3.0 h1:e1/Ivsx3Z0FVTV0NSOv/aVgbUWyQuzj7DDnFblkRvsY= github.com/BurntSushi/toml v0.3.0/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= +github.com/bradleyjkemp/cupaloy v2.3.0+incompatible h1:UafIjBvWQmS9i/xRg+CamMrnLTKNzo+bdmT/oH34c2Y= +github.com/bradleyjkemp/cupaloy v2.3.0+incompatible/go.mod h1:Au1Xw1sgaJ5iSFktEhYsS0dbQiS1B0/XMXl+42y9Ilk= github.com/cupcake/rdb v0.0.0-20161107195141-43ba34106c76 h1:Lgdd/Qp96Qj8jqLpq2cI1I1X7BJnu06efS+XkhRoLUQ= github.com/cupcake/rdb v0.0.0-20161107195141-43ba34106c76/go.mod h1:vYwsqCOLxGiisLwp9rITslkFNpZD5rz43tf41QFkTWY= github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=