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
+41
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")
}