1
0
Fork 0
forked from goffee/core

change hooks

This commit is contained in:
Zeni Kim 2024-09-16 16:01:44 -05:00
parent c6006861cb
commit 1bfc72d6a3
4 changed files with 21 additions and 24 deletions

View file

@ -1,4 +1,3 @@
// Copyright 2021 Harran Ali <harran.m@gmail.com>. All rights reserved.
// Copyright (c) 2024 Zeni Kim <zenik@smarteching.com> // Copyright (c) 2024 Zeni Kim <zenik@smarteching.com>
// Use of this source code is governed by MIT-style // Use of this source code is governed by MIT-style
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.

View file

@ -1,4 +1,3 @@
// Copyright 2021 Harran Ali <harran.m@gmail.com>. All rights reserved.
// Copyright (c) 2024 Zeni Kim <zenik@smarteching.com> // Copyright (c) 2024 Zeni Kim <zenik@smarteching.com>
// Use of this source code is governed by MIT-style // Use of this source code is governed by MIT-style
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.

View file

@ -11,51 +11,51 @@ import (
"testing" "testing"
) )
func TestNewMiddlewares(t *testing.T) { func TestNewHooks(t *testing.T) {
mw := NewMiddlewares() mw := NewHooks()
if fmt.Sprintf("%T", mw) != "*core.Middlewares" { if fmt.Sprintf("%T", mw) != "*core.Hooks" {
t.Errorf("failed testing new middleware") t.Errorf("failed testing new hook")
} }
} }
func TestResloveMiddleWares(t *testing.T) { func TestResloveHooks(t *testing.T) {
NewMiddlewares() NewHooks()
mw := ResolveMiddlewares() mw := ResolveHooks()
if fmt.Sprintf("%T", mw) != "*core.Middlewares" { if fmt.Sprintf("%T", mw) != "*core.Hooks" {
t.Errorf("failed resolve middlewares") t.Errorf("failed resolve hooks")
} }
} }
func TestAttach(t *testing.T) { func TestAttach(t *testing.T) {
mw := NewMiddlewares() mw := NewHooks()
tmw := Middleware(func(c *Context) { tmw := Hook(func(c *Context) {
c.GetLogger().Info("Testing!") c.GetLogger().Info("Testing!")
}) })
mw.Attach(tmw) mw.Attach(tmw)
mws := mw.getByIndex(0) mws := mw.getByIndex(0)
if reflect.ValueOf(tmw).Pointer() != reflect.ValueOf(mws).Pointer() { if reflect.ValueOf(tmw).Pointer() != reflect.ValueOf(mws).Pointer() {
t.Errorf("Failed testing attach middleware") t.Errorf("Failed testing attach hook")
} }
} }
func TestGetMiddleWares(t *testing.T) { func TestGetHooks(t *testing.T) {
mw := NewMiddlewares() mw := NewHooks()
t1 := Middleware(func(c *Context) { t1 := Hook(func(c *Context) {
c.GetLogger().Info("testing1!") c.GetLogger().Info("testing1!")
}) })
t2 := Middleware(func(c *Context) { t2 := Hook(func(c *Context) {
c.GetLogger().Info("testing2!") c.GetLogger().Info("testing2!")
}) })
mw.Attach(t1) mw.Attach(t1)
mw.Attach(t2) mw.Attach(t2)
if len(mw.GetMiddlewares()) != 2 { if len(mw.GetHooks()) != 2 {
t.Errorf("failed testing get middlewares") t.Errorf("failed testing get hooks")
} }
} }
func TestMiddlewareGetByIndex(t *testing.T) { func TestHookGetByIndex(t *testing.T) {
mw := NewMiddlewares() mw := NewHooks()
t1 := Middleware(func(c *Context) { t1 := Hook(func(c *Context) {
c.GetLogger().Info("testing!") c.GetLogger().Info("testing!")
}) })
mw.Attach(t1) mw.Attach(t1)

View file

@ -1,4 +1,3 @@
// Copyright 2021 Harran Ali <harran.m@gmail.com>. All rights reserved.
// Copyright (c) 2024 Zeni Kim <zenik@smarteching.com> // Copyright (c) 2024 Zeni Kim <zenik@smarteching.com>
// Use of this source code is governed by MIT-style // Use of this source code is governed by MIT-style
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.