Skip to content

Commit

Permalink
Fix router test using current file
Browse files Browse the repository at this point in the history
  • Loading branch information
jamiefdhurst committed Jan 7, 2025
1 parent 2629571 commit 950279e
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion pkg/router/router_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ package router
import (
"net/http"
"net/url"
"os"
"path"
"runtime"
"testing"

"github.com/jamiefdhurst/journal/test/mocks/controller"
Expand All @@ -11,6 +14,15 @@ import (

type BlankContainer struct{}

func init() {
_, filename, _, _ := runtime.Caller(0)
dir := path.Join(path.Dir(filename), "../..")
err := os.Chdir(dir)
if err != nil {
panic(err)
}
}

func TestGet(t *testing.T) {
ctrl := &controller.MockController{}
router := Router{Container: &BlankContainer{}, Routes: []Route{}, ErrorController: ctrl}
Expand Down Expand Up @@ -68,7 +80,7 @@ func TestServeHTTP(t *testing.T) {
standardController := &controller.MockController{}
paramController := &controller.MockController{}
response := controller.NewMockResponse()
router := Router{Container: &BlankContainer{}, Routes: []Route{}, ErrorController: errorController, StaticPaths: []string{"../../test/data"}}
router := Router{Container: &BlankContainer{}, Routes: []Route{}, ErrorController: errorController, StaticPaths: []string{"test/data"}}
router.Get("/standard", standardController)
router.Get("/param/[%s]", paramController)
router.Get("/", indexController)
Expand Down

0 comments on commit 950279e

Please sign in to comment.