Basic DI (dependency injection) working! Yay!!
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"github.com/astaxie/beego"
|
||||
"github.com/deluan/gosonic/repositories"
|
||||
"github.com/deluan/gosonic/utils"
|
||||
"github.com/karlkfi/inject"
|
||||
)
|
||||
|
||||
type GetIndexesController struct {
|
||||
beego.Controller
|
||||
repo repositories.ArtistIndex
|
||||
}
|
||||
|
||||
func (c *GetIndexesController) Prepare() {
|
||||
inject.ExtractAssignable(utils.Graph, &c.repo)
|
||||
}
|
||||
|
||||
func (c *GetIndexesController) Get() {
|
||||
if c.repo == nil {
|
||||
c.CustomAbort(500, "INJECTION NOT WORKING")
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package api_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
. "github.com/smartystreets/goconvey/convey"
|
||||
"github.com/deluan/gosonic/tests"
|
||||
)
|
||||
|
||||
func TestGetIndexes(t *testing.T) {
|
||||
tests.Init(t, false)
|
||||
|
||||
_, w := Get(AddParams("/rest/getIndexes.view"), "TestGetIndexes")
|
||||
|
||||
Convey("Subject: GetIndexes Endpoint", t, func() {
|
||||
Convey("Status code should be 200", func() {
|
||||
So(w.Code, ShouldEqual, 200)
|
||||
})
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user