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>
// Use of this source code is governed by MIT-style
// 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>
// Use of this source code is governed by MIT-style
// license that can be found in the LICENSE file.

View file

@ -11,51 +11,51 @@ import (
"testing"
)
func TestNewMiddlewares(t *testing.T) {
mw := NewMiddlewares()
if fmt.Sprintf("%T", mw) != "*core.Middlewares" {
t.Errorf("failed testing new middleware")
func TestNewHooks(t *testing.T) {
mw := NewHooks()
if fmt.Sprintf("%T", mw) != "*core.Hooks" {
t.Errorf("failed testing new hook")
}
}
func TestResloveMiddleWares(t *testing.T) {
NewMiddlewares()
mw := ResolveMiddlewares()
if fmt.Sprintf("%T", mw) != "*core.Middlewares" {
t.Errorf("failed resolve middlewares")
func TestResloveHooks(t *testing.T) {
NewHooks()
mw := ResolveHooks()
if fmt.Sprintf("%T", mw) != "*core.Hooks" {
t.Errorf("failed resolve hooks")
}
}
func TestAttach(t *testing.T) {
mw := NewMiddlewares()
tmw := Middleware(func(c *Context) {
mw := NewHooks()
tmw := Hook(func(c *Context) {
c.GetLogger().Info("Testing!")
})
mw.Attach(tmw)
mws := mw.getByIndex(0)
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) {
mw := NewMiddlewares()
t1 := Middleware(func(c *Context) {
func TestGetHooks(t *testing.T) {
mw := NewHooks()
t1 := Hook(func(c *Context) {
c.GetLogger().Info("testing1!")
})
t2 := Middleware(func(c *Context) {
t2 := Hook(func(c *Context) {
c.GetLogger().Info("testing2!")
})
mw.Attach(t1)
mw.Attach(t2)
if len(mw.GetMiddlewares()) != 2 {
t.Errorf("failed testing get middlewares")
if len(mw.GetHooks()) != 2 {
t.Errorf("failed testing get hooks")
}
}
func TestMiddlewareGetByIndex(t *testing.T) {
mw := NewMiddlewares()
t1 := Middleware(func(c *Context) {
func TestHookGetByIndex(t *testing.T) {
mw := NewHooks()
t1 := Hook(func(c *Context) {
c.GetLogger().Info("testing!")
})
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>
// Use of this source code is governed by MIT-style
// license that can be found in the LICENSE file.