Rewriting Response tests as snapshot tests

This commit is contained in:
Deluan 2020-01-09 17:09:05 -05:00 committed by Deluan Quintão
parent 6aa6c2d9a5
commit 0c3edc0279
34 changed files with 255 additions and 161 deletions

View File

@ -0,0 +1 @@
{"status":"ok","version":"1.8.0","albumList":{"album":[{"id":"1","isDir":false,"title":"title"}]}}

View File

@ -0,0 +1 @@
<subsonic-response xmlns="http://subsonic.org/restapi" status="ok" version="1.8.0"><albumList><album id="1" isDir="false" title="title"></album></albumList></subsonic-response>

View File

@ -0,0 +1 @@
{"status":"ok","version":"1.8.0","albumList":{}}

View File

@ -0,0 +1 @@
<subsonic-response xmlns="http://subsonic.org/restapi" status="ok" version="1.8.0"><albumList></albumList></subsonic-response>

View File

@ -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"}}

View File

@ -0,0 +1 @@
<subsonic-response xmlns="http://subsonic.org/restapi" status="ok" version="1.8.0"><directory id="1" name="N"><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"></child></directory></subsonic-response>

View File

@ -0,0 +1 @@
{"status":"ok","version":"1.8.0","directory":{"child":[{"id":"1","isDir":false,"title":"title"}],"id":"1","name":"N"}}

View File

@ -0,0 +1 @@
<subsonic-response xmlns="http://subsonic.org/restapi" status="ok" version="1.8.0"><directory id="1" name="N"><child id="1" isDir="false" title="title"></child></directory></subsonic-response>

View File

@ -0,0 +1 @@
{"status":"ok","version":"1.8.0","directory":{"id":"1","name":"N"}}

View File

@ -0,0 +1 @@
<subsonic-response xmlns="http://subsonic.org/restapi" status="ok" version="1.8.0"><directory id="1" name="N"></directory></subsonic-response>

View File

@ -0,0 +1 @@
{"status":"ok","version":"1.8.0"}

View File

@ -0,0 +1 @@
<subsonic-response xmlns="http://subsonic.org/restapi" status="ok" version="1.8.0"></subsonic-response>

View File

@ -0,0 +1 @@
{"status":"ok","version":"1.8.0","indexes":{"index":[{"name":"A","artist":[{"id":"111","name":"aaa"}]}],"lastModified":"1","ignoredArticles":"A"}}

View File

@ -0,0 +1 @@
<subsonic-response xmlns="http://subsonic.org/restapi" status="ok" version="1.8.0"><indexes lastModified="1" ignoredArticles="A"><index name="A"><artist id="111" name="aaa"></artist></index></indexes></subsonic-response>

View File

@ -0,0 +1 @@
{"status":"ok","version":"1.8.0","indexes":{"lastModified":"1","ignoredArticles":"A"}}

View File

@ -0,0 +1 @@
<subsonic-response xmlns="http://subsonic.org/restapi" status="ok" version="1.8.0"><indexes lastModified="1" ignoredArticles="A"></indexes></subsonic-response>

View File

@ -0,0 +1 @@
{"status":"ok","version":"1.8.0","license":{"valid":true}}

View File

@ -0,0 +1 @@
<subsonic-response xmlns="http://subsonic.org/restapi" status="ok" version="1.8.0"><license valid="true"></license></subsonic-response>

View File

@ -0,0 +1 @@
{"status":"ok","version":"1.8.0","musicFolders":{"musicFolder":[{"id":"111","name":"aaa"},{"id":"222","name":"bbb"}]}}

View File

@ -0,0 +1 @@
<subsonic-response xmlns="http://subsonic.org/restapi" status="ok" version="1.8.0"><musicFolders><musicFolder id="111" name="aaa"></musicFolder><musicFolder id="222" name="bbb"></musicFolder></musicFolders></subsonic-response>

View File

@ -0,0 +1 @@
{"status":"ok","version":"1.8.0","musicFolders":{}}

View File

@ -0,0 +1 @@
<subsonic-response xmlns="http://subsonic.org/restapi" status="ok" version="1.8.0"><musicFolders></musicFolders></subsonic-response>

View File

@ -0,0 +1 @@
{"status":"ok","version":"1.8.0","playlists":{"playlist":[{"id":"111","name":"aaa"},{"id":"222","name":"bbb"}]}}

View File

@ -0,0 +1 @@
<subsonic-response xmlns="http://subsonic.org/restapi" status="ok" version="1.8.0"><playlists><playlist id="111" name="aaa"></playlist><playlist id="222" name="bbb"></playlist></playlists></subsonic-response>

View File

@ -0,0 +1 @@
{"status":"ok","version":"1.8.0","playlists":{}}

View File

@ -0,0 +1 @@
<subsonic-response xmlns="http://subsonic.org/restapi" status="ok" version="1.8.0"><playlists></playlists></subsonic-response>

View File

@ -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]}}

View File

@ -0,0 +1 @@
<subsonic-response xmlns="http://subsonic.org/restapi" 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</folder></user></subsonic-response>

View File

@ -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}}

View File

@ -0,0 +1 @@
<subsonic-response xmlns="http://subsonic.org/restapi" 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"></user></subsonic-response>

View File

@ -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")
}

View File

@ -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, `<subsonic-response xmlns="http://subsonic.org/restapi" status="ok" version="1.0.0"></subsonic-response>`)
})
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, `<subsonic-response xmlns="http://subsonic.org/restapi" status="ok" version="1.0.0"><license valid="true"></license></subsonic-response>`)
})
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, `<subsonic-response xmlns="http://subsonic.org/restapi" status="ok" version="1.0.0"><musicFolders><musicFolder id="111" name="aaa"></musicFolder><musicFolder id="222" name="bbb"></musicFolder></musicFolders></subsonic-response>`)
})
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, `<subsonic-response xmlns="http://subsonic.org/restapi" status="ok" version="1.0.0"><musicFolders></musicFolders></subsonic-response>`)
})
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, `<subsonic-response xmlns="http://subsonic.org/restapi" status="ok" version="1.0.0"><indexes lastModified="1" ignoredArticles="A"><index name="A"><artist id="111" name="aaa"></artist></index></indexes></subsonic-response>`)
})
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, `<subsonic-response xmlns="http://subsonic.org/restapi" status="ok" version="1.0.0"><indexes lastModified="1" ignoredArticles="A"></indexes></subsonic-response>`)
})
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, `<subsonic-response xmlns="http://subsonic.org/restapi" status="ok" version="1.0.0"><directory id="1" name="N"><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"></child></directory></subsonic-response>`)
})
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, `<subsonic-response xmlns="http://subsonic.org/restapi" status="ok" version="1.0.0"><directory id="1" name="N"></directory></subsonic-response>`)
})
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, `<subsonic-response xmlns="http://subsonic.org/restapi" status="ok" version="1.0.0"><directory id="1" name="N"><child id="1" isDir="false" title="title"></child></directory></subsonic-response>`)
})
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, `<subsonic-response xmlns="http://subsonic.org/restapi" status="ok" version="1.0.0"><albumList></albumList></subsonic-response>`)
})
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, `<subsonic-response xmlns="http://subsonic.org/restapi" status="ok" version="1.0.0"><albumList><album id="1" isDir="false" title="title"></album></albumList></subsonic-response>`)
})
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, `<subsonic-response xmlns="http://subsonic.org/restapi" status="ok" version="1.0.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"></user></subsonic-response>`)
})
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, `<subsonic-response xmlns="http://subsonic.org/restapi" status="ok" version="1.0.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</folder></user></subsonic-response>`)
})
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, `<subsonic-response xmlns="http://subsonic.org/restapi" status="ok" version="1.0.0"><playlists></playlists></subsonic-response>`)
})
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, `<subsonic-response xmlns="http://subsonic.org/restapi" status="ok" version="1.0.0"><playlists><playlist id="111" name="aaa"></playlist><playlist id="222" name="bbb"></playlist></playlists></subsonic-response>`)
})
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, `<subsonic-response xmlns="http://subsonic.org/restapi" status="ok" version="1.0.0"><playlist id="1" name="My Playlist"></playlist></subsonic-response>`)
})
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, `<subsonic-response xmlns="http://subsonic.org/restapi" status="ok" version="1.0.0"><playlist id="1" name="My Playlist"><entry id="1" isDir="false" title="title"></entry></playlist></subsonic-response>`)
})
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"}
})
})
}
})

1
go.mod
View File

@ -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

2
go.sum
View File

@ -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=