mirror of
https://github.com/navidrome/navidrome.git
synced 2025-04-18 21:07:44 +03:00
Better tests organization
This commit is contained in:
parent
ecc0df9e7c
commit
ce240cfeff
@ -1,33 +1,20 @@
|
|||||||
package test
|
package api_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/astaxie/beego"
|
"github.com/astaxie/beego"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/http/httptest"
|
"net/http/httptest"
|
||||||
"os"
|
_ "github.com/deluan/gosonic/routers"
|
||||||
"path/filepath"
|
|
||||||
"runtime"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
testUser = "deluan"
|
testUser = "deluan"
|
||||||
testPassword = "wordpass"
|
testPassword = "wordpass"
|
||||||
testClient = "test"
|
testClient = "test"
|
||||||
testVersion = "1.0.0"
|
testVersion = "1.0.0"
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
|
||||||
_, file, _, _ := runtime.Caller(1)
|
|
||||||
appPath, _ := filepath.Abs(filepath.Dir(filepath.Join(file, ".."+string(filepath.Separator))))
|
|
||||||
beego.TestBeegoInit(appPath)
|
|
||||||
|
|
||||||
noLog := os.Getenv("NOLOG")
|
|
||||||
if noLog != "" {
|
|
||||||
beego.SetLevel(beego.LevelError)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func AddParams(url string) string {
|
func AddParams(url string) string {
|
||||||
return fmt.Sprintf("%s?u=%s&p=%s&c=%s&v=%s", url, testUser, testPassword, testClient, testVersion)
|
return fmt.Sprintf("%s?u=%s&p=%s&c=%s&v=%s", url, testUser, testPassword, testClient, testVersion)
|
||||||
}
|
}
|
@ -1,14 +1,15 @@
|
|||||||
package api
|
package api_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/xml"
|
"encoding/xml"
|
||||||
_ "github.com/deluan/gosonic/routers"
|
|
||||||
. "github.com/deluan/gosonic/tests"
|
|
||||||
. "github.com/smartystreets/goconvey/convey"
|
. "github.com/smartystreets/goconvey/convey"
|
||||||
"testing"
|
"testing"
|
||||||
|
"github.com/deluan/gosonic/tests"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestGetLicense(t *testing.T) {
|
func TestGetLicense(t *testing.T) {
|
||||||
|
tests.Init(t, false)
|
||||||
|
|
||||||
_, w := Get(AddParams("/rest/getLicense.view"), "TestGetLicense")
|
_, w := Get(AddParams("/rest/getLicense.view"), "TestGetLicense")
|
||||||
|
|
||||||
Convey("Subject: GetLicense Endpoint\n", t, func() {
|
Convey("Subject: GetLicense Endpoint\n", t, func() {
|
@ -1,15 +1,16 @@
|
|||||||
package api
|
package api_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
_ "github.com/deluan/gosonic/routers"
|
|
||||||
. "github.com/deluan/gosonic/tests"
|
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"encoding/xml"
|
"encoding/xml"
|
||||||
. "github.com/smartystreets/goconvey/convey"
|
. "github.com/smartystreets/goconvey/convey"
|
||||||
|
"github.com/deluan/gosonic/tests"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestGetMusicFolders(t *testing.T) {
|
func TestGetMusicFolders(t *testing.T) {
|
||||||
|
tests.Init(t, false)
|
||||||
|
|
||||||
_, w := Get(AddParams("/rest/getMusicFolders.view"), "TestGetMusicFolders")
|
_, w := Get(AddParams("/rest/getMusicFolders.view"), "TestGetMusicFolders")
|
||||||
|
|
||||||
Convey("Subject: GetMusicFolders Endpoint\n", t, func() {
|
Convey("Subject: GetMusicFolders Endpoint\n", t, func() {
|
@ -1,15 +1,16 @@
|
|||||||
package api
|
package api_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/xml"
|
"encoding/xml"
|
||||||
"github.com/deluan/gosonic/api/responses"
|
"github.com/deluan/gosonic/api/responses"
|
||||||
_ "github.com/deluan/gosonic/routers"
|
|
||||||
. "github.com/deluan/gosonic/tests"
|
|
||||||
. "github.com/smartystreets/goconvey/convey"
|
. "github.com/smartystreets/goconvey/convey"
|
||||||
"testing"
|
"testing"
|
||||||
|
"github.com/deluan/gosonic/tests"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestPing(t *testing.T) {
|
func TestPing(t *testing.T) {
|
||||||
|
tests.Init(t, false)
|
||||||
|
|
||||||
_, w := Get(AddParams("/rest/ping.view"), "TestPing")
|
_, w := Get(AddParams("/rest/ping.view"), "TestPing")
|
||||||
|
|
||||||
Convey("Subject: Ping Endpoint\n", t, func() {
|
Convey("Subject: Ping Endpoint\n", t, func() {
|
@ -1,15 +1,16 @@
|
|||||||
package api
|
package api_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/xml"
|
"encoding/xml"
|
||||||
"github.com/deluan/gosonic/api/responses"
|
"github.com/deluan/gosonic/api/responses"
|
||||||
_ "github.com/deluan/gosonic/routers"
|
|
||||||
. "github.com/deluan/gosonic/tests"
|
|
||||||
. "github.com/smartystreets/goconvey/convey"
|
. "github.com/smartystreets/goconvey/convey"
|
||||||
"testing"
|
"testing"
|
||||||
|
"github.com/deluan/gosonic/tests"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestCheckParams(t *testing.T) {
|
func TestCheckParams(t *testing.T) {
|
||||||
|
tests.Init(t, false)
|
||||||
|
|
||||||
_, w := Get("/rest/ping.view", "TestCheckParams")
|
_, w := Get("/rest/ping.view", "TestCheckParams")
|
||||||
|
|
||||||
Convey("Subject: CheckParams\n", t, func() {
|
Convey("Subject: CheckParams\n", t, func() {
|
1
repositories/.goconvey.goconvey
Normal file
1
repositories/.goconvey.goconvey
Normal file
@ -0,0 +1 @@
|
|||||||
|
-short
|
@ -4,6 +4,7 @@ import (
|
|||||||
. "github.com/smartystreets/goconvey/convey"
|
. "github.com/smartystreets/goconvey/convey"
|
||||||
_ "github.com/deluan/gosonic/tests"
|
_ "github.com/deluan/gosonic/tests"
|
||||||
"testing"
|
"testing"
|
||||||
|
"github.com/deluan/gosonic/tests"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@ -11,11 +12,7 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func TestCreateCollection(t *testing.T) {
|
func TestCreateCollection(t *testing.T) {
|
||||||
if testing.Short() {
|
tests.Init(t, true)
|
||||||
t.Skip("skipping test in short mode.")
|
|
||||||
}
|
|
||||||
|
|
||||||
dbInstance().Drop(testCollectionName)
|
|
||||||
|
|
||||||
Convey("Given an empty DB", t, func() {
|
Convey("Given an empty DB", t, func() {
|
||||||
|
|
||||||
@ -50,5 +47,10 @@ func TestCreateCollection(t *testing.T) {
|
|||||||
So(allPaths, ShouldContainKey, "Name")
|
So(allPaths, ShouldContainKey, "Name")
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
Reset(func() {
|
||||||
|
dbInstance().Drop(testCollectionName)
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
}
|
}
|
25
tests/init_tests.go
Normal file
25
tests/init_tests.go
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
package tests
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/astaxie/beego"
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
"runtime"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func Init(t *testing.T, skipOnShort bool) {
|
||||||
|
if skipOnShort && testing.Short() {
|
||||||
|
t.Skip("skipping test in short mode.")
|
||||||
|
}
|
||||||
|
|
||||||
|
_, file, _, _ := runtime.Caller(0)
|
||||||
|
appPath, _ := filepath.Abs(filepath.Join(filepath.Dir(file), ".."))
|
||||||
|
beego.TestBeegoInit(appPath)
|
||||||
|
|
||||||
|
noLog := os.Getenv("NOLOG")
|
||||||
|
if noLog != "" {
|
||||||
|
beego.SetLevel(beego.LevelError)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
x
Reference in New Issue
Block a user