🎧 Your Personal Streaming Service
Go airsonicmadsonicmedia-servermusicmusic-servernavidromeopensubsonicraspberry-piself-hostedstreamerstreaming-apistreaming-audiosubsonicsubsonic-server
Merging BaseRepository test files into one
Deluan6f60d02acb46
diff --git a/repositories/base_repository_integration_test.go b/repositories/base_repository_integration_test.godeleted file mode 100644index efd70574e..000000000--- a/repositories/base_repository_integration_test.go+++ /dev/null@@ -1,89 +0,0 @@-package repositories--import (- "testing"- . "github.com/smartystreets/goconvey/convey"- "github.com/deluan/gosonic/tests"- "fmt"-)--type TestEntity struct {- Id string- Name string-}--func shouldBeEqual(actualStruct interface{}, expectedStruct ...interface{}) string {- actual := fmt.Sprintf("%#v", actualStruct)- expected := fmt.Sprintf("%#v", expectedStruct[0])- return ShouldEqual(actual, expected)-}--func TestIntegrationBaseRepository(t *testing.T) {- tests.Init(t, true)- Convey("Subject: saveOrUpdate", t, func() {-- Convey("Given an empty DB", func() {- dropDb()- repo := &BaseRepository{table: "test"}-- Convey("When I save a new entity", func() {- entity := &TestEntity{"123", "My Name"}- err := repo.saveOrUpdate("123", entity)-- Convey("Then the method shouldn't return any errors", func() {- So(err, ShouldBeNil)- })-- Convey("Then the number of entities should be 1", func() {- count, _ := repo.CountAll()- So(count, ShouldEqual, 1)- })-- Convey("And this entity should be equal to the the saved one", func() {- actualEntity := &TestEntity{}- repo.loadEntity("123", actualEntity)- So(actualEntity, shouldBeEqual, entity)- })-- })-- })-- Convey("Given a table with one entity", func() {- dropDb()- repo := &BaseRepository{table: "test"}- entity := &TestEntity{"111", "One Name"}- repo.saveOrUpdate(entity.Id, entity)-- Convey("When I save an entity with a different Id", func() {- newEntity := &TestEntity{"222", "Another Name"}- repo.saveOrUpdate(newEntity.Id, newEntity)-- Convey("Then the number of entities should be 2", func() {- count, _ := repo.CountAll()- So(count, ShouldEqual, 2)- })-- })-- Convey("When I save an entity with the same Id", func() {- newEntity := &TestEntity{"111", "New Name"}- repo.saveOrUpdate(newEntity.Id, newEntity)-- Convey("Then the number of entities should be 1", func() {- count, _ := repo.CountAll()- So(count, ShouldEqual, 1)- })-- Convey("And the entity should be updated", func() {- actualEntity := &TestEntity{}- repo.loadEntity("111", actualEntity)- So(actualEntity.Name, ShouldEqual, newEntity.Name)- })-- })-- })-- })-}\ No newline at end of filediff --git a/repositories/base_repository_test.go b/repositories/base_repository_test.goindex bab82cff3..f5e060d36 100644--- a/repositories/base_repository_test.go+++ b/repositories/base_repository_test.go@@ -4,9 +4,21 @@ import ("testing". "github.com/smartystreets/goconvey/convey""github.com/deluan/gosonic/tests"+ "fmt")-func TestUnitBaseRepository(t *testing.T) {+type TestEntity struct {+ Id string+ Name string+}++func shouldBeEqual(actualStruct interface{}, expectedStruct ...interface{}) string {+ actual := fmt.Sprintf("%#v", actualStruct)+ expected := fmt.Sprintf("%#v", expectedStruct[0])+ return ShouldEqual(actual, expected)+}++func TestBaseRepository(t *testing.T) {tests.Init(t, false)Convey("Subject: NewId", t, func() {@@ -41,4 +53,71 @@ func TestUnitBaseRepository(t *testing.T) {})})++ Convey("Subject: saveOrUpdate/loadEntity/CountAll", t, func() {++ Convey("Given an empty DB", func() {+ dropDb()+ repo := &BaseRepository{table: "test"}++ Convey("When I save a new entity", func() {+ entity := &TestEntity{"123", "My Name"}+ err := repo.saveOrUpdate("123", entity)++ Convey("Then the method shouldn't return any errors", func() {+ So(err, ShouldBeNil)+ })++ Convey("Then the number of entities should be 1", func() {+ count, _ := repo.CountAll()+ So(count, ShouldEqual, 1)+ })++ Convey("And this entity should be equal to the the saved one", func() {+ actualEntity := &TestEntity{}+ repo.loadEntity("123", actualEntity)+ So(actualEntity, shouldBeEqual, entity)+ })++ })++ })++ Convey("Given a table with one entity", func() {+ dropDb()+ repo := &BaseRepository{table: "test"}+ entity := &TestEntity{"111", "One Name"}+ repo.saveOrUpdate(entity.Id, entity)++ Convey("When I save an entity with a different Id", func() {+ newEntity := &TestEntity{"222", "Another Name"}+ repo.saveOrUpdate(newEntity.Id, newEntity)++ Convey("Then the number of entities should be 2", func() {+ count, _ := repo.CountAll()+ So(count, ShouldEqual, 2)+ })++ })++ Convey("When I save an entity with the same Id", func() {+ newEntity := &TestEntity{"111", "New Name"}+ repo.saveOrUpdate(newEntity.Id, newEntity)++ Convey("Then the number of entities should be 1", func() {+ count, _ := repo.CountAll()+ So(count, ShouldEqual, 1)+ })++ Convey("And the entity should be updated", func() {+ actualEntity := &TestEntity{}+ repo.loadEntity("111", actualEntity)+ So(actualEntity.Name, ShouldEqual, newEntity.Name)+ })++ })++ })++ })}