Skip to content

Commit

Permalink
Merge pull request #136 from tinh-tinh/test/ren/add-unit-test-v1.4.0
Browse files Browse the repository at this point in the history
test: add unit test for v1.4.0
  • Loading branch information
Ren0503 authored Dec 3, 2024
2 parents 2e440fd + 920a6a5 commit 36eb8fd
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 13 deletions.
5 changes: 0 additions & 5 deletions core/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,11 +185,6 @@ func (c *DynamicController) free() {
runtime.GC()
}

// DEPRECATED
func (c *DynamicController) Inject(name Provide) interface{} {
return c.module.Ref(name)
}

func (c *DynamicController) Ref(name Provide, ctx ...Ctx) interface{} {
return c.module.Ref(name, ctx...)
}
4 changes: 4 additions & 0 deletions core/ctx.go
Original file line number Diff line number Diff line change
Expand Up @@ -512,3 +512,7 @@ func (ctx *Ctx) Redirect(uri string) error {
http.Redirect(ctx.Res(), ctx.Req(), fullUrl.String(), http.StatusFound)
return nil
}

func (ctx *Ctx) Ref(name Provide) interface{} {
return ctx.Get(name)
}
2 changes: 1 addition & 1 deletion core/module_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ func Test_Controller(t *testing.T) {
ctrl := module.NewController("sub")

ctrl.Get("", func(ctx core.Ctx) error {
data := ctrl.Inject(core.Provide("sub"))
data := ctrl.Ref(core.Provide("sub"))
return ctx.JSON(core.Map{
"data": data,
})
Expand Down
4 changes: 2 additions & 2 deletions core/provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func ChildModule(module *core.DynamicModule) *core.DynamicModule {
func AppController(module *core.DynamicModule) *core.DynamicController {
ctrl := module.NewController("test")
ctrl.Get("/", func(ctx core.Ctx) error {
name := ctrl.Inject("child")
name := ctrl.Ref("child")
return ctx.JSON(core.Map{
"data": name,
})
Expand Down Expand Up @@ -136,7 +136,7 @@ func tenantModule() *core.DynamicModule {
ctrl := module.NewController("test")

ctrl.Get("/", func(ctx core.Ctx) error {
service := ctx.Get(SERVICE).(*RequestProvider)
service := ctx.Ref(SERVICE).(*RequestProvider)
return ctx.JSON(core.Map{
"data": service.Name,
})
Expand Down
7 changes: 4 additions & 3 deletions middleware/session/session_test.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
package session
package session_test

import (
"testing"
"time"

"github.com/stretchr/testify/require"
"github.com/tinh-tinh/tinhtinh/middleware/session"
)

func Test_Session(t *testing.T) {
s := New(Options{
s := session.New(session.Options{
GeneratorID: func() string {
return time.Now().String()
},
Expand All @@ -19,7 +20,7 @@ func Test_Session(t *testing.T) {
}

func Test_Expiration(t *testing.T) {
s := New(Options{
s := session.New(session.Options{
ExpiresIn: 1 * time.Second,
})

Expand Down
5 changes: 3 additions & 2 deletions middleware/static/module_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package static
package static_test

import (
"net/http"
Expand All @@ -7,6 +7,7 @@ import (

"github.com/stretchr/testify/require"
"github.com/tinh-tinh/tinhtinh/core"
"github.com/tinh-tinh/tinhtinh/middleware/static"
)

func Test_Static(t *testing.T) {
Expand All @@ -24,7 +25,7 @@ func Test_Static(t *testing.T) {

appModule := func() *core.DynamicModule {
return core.NewModule(core.NewModuleOptions{
Imports: []core.Module{ForRoot("upload")},
Imports: []core.Module{static.ForRoot("upload")},
Controllers: []core.Controller{appController},
})
}
Expand Down

0 comments on commit 36eb8fd

Please sign in to comment.