commit
dec1990865
@ -21,8 +21,6 @@ import (
|
|||||||
"strconv"
|
"strconv"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
|
||||||
|
|
||||||
"github.com/beego/beego/v2/server/web/context"
|
"github.com/beego/beego/v2/server/web/context"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -127,10 +125,9 @@ func TestGetUint64(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestAdditionalViewPaths(t *testing.T) {
|
func TestAdditionalViewPaths(t *testing.T) {
|
||||||
wkdir, err := os.Getwd()
|
tmpDir := os.TempDir()
|
||||||
assert.Nil(t, err)
|
dir1 := filepath.Join(tmpDir, "_beeTmp", "TestAdditionalViewPaths")
|
||||||
dir1 := filepath.Join(wkdir, "_beeTmp", "TestAdditionalViewPaths")
|
dir2 := filepath.Join(tmpDir, "_beeTmp2", "TestAdditionalViewPaths")
|
||||||
dir2 := filepath.Join(wkdir, "_beeTmp2", "TestAdditionalViewPaths")
|
|
||||||
defer os.RemoveAll(dir1)
|
defer os.RemoveAll(dir1)
|
||||||
defer os.RemoveAll(dir2)
|
defer os.RemoveAll(dir2)
|
||||||
|
|
||||||
|
|||||||
@ -584,17 +584,6 @@ func getpathTime(pkgRealpath string) (lastupdate int64, err error) {
|
|||||||
|
|
||||||
func getRouterDir(pkgRealpath string) string {
|
func getRouterDir(pkgRealpath string) string {
|
||||||
dir := filepath.Dir(pkgRealpath)
|
dir := filepath.Dir(pkgRealpath)
|
||||||
for {
|
|
||||||
routersDir := AppConfig.DefaultString("routersdir", "routers")
|
routersDir := AppConfig.DefaultString("routersdir", "routers")
|
||||||
d := filepath.Join(dir, routersDir)
|
return filepath.Join(dir, routersDir)
|
||||||
if utils.FileExists(d) {
|
|
||||||
return d
|
|
||||||
}
|
|
||||||
|
|
||||||
if r, _ := filepath.Rel(dir, AppPath); r == "." {
|
|
||||||
return d
|
|
||||||
}
|
|
||||||
// Parent dir.
|
|
||||||
dir = filepath.Dir(dir)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
34
server/web/parser_test.go
Normal file
34
server/web/parser_test.go
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
// Copyright 2020 beego
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
|
||||||
|
package web
|
||||||
|
|
||||||
|
import (
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
)
|
||||||
|
|
||||||
|
func Test_getRouterDir(t *testing.T) {
|
||||||
|
pkg := filepath.Dir(os.TempDir())
|
||||||
|
|
||||||
|
res := getRouterDir(pkg)
|
||||||
|
assert.Equal(t, filepath.Join(pkg, "routers"), res)
|
||||||
|
AppConfig.Set("routersdir", "cus_routers")
|
||||||
|
res = getRouterDir(pkg)
|
||||||
|
assert.Equal(t, filepath.Join(pkg, "cus_routers"), res)
|
||||||
|
|
||||||
|
}
|
||||||
@ -49,9 +49,8 @@ var block = `{{define "block"}}
|
|||||||
{{end}}`
|
{{end}}`
|
||||||
|
|
||||||
func TestTemplate(t *testing.T) {
|
func TestTemplate(t *testing.T) {
|
||||||
wkdir, err := os.Getwd()
|
tmpDir := os.TempDir()
|
||||||
assert.Nil(t, err)
|
dir := filepath.Join(tmpDir, "_beeTmp", "TestTemplate")
|
||||||
dir := filepath.Join(wkdir, "_beeTmp", "TestTemplate")
|
|
||||||
files := []string{
|
files := []string{
|
||||||
"header.tpl",
|
"header.tpl",
|
||||||
"index.tpl",
|
"index.tpl",
|
||||||
@ -113,9 +112,8 @@ var user = `<!DOCTYPE html>
|
|||||||
`
|
`
|
||||||
|
|
||||||
func TestRelativeTemplate(t *testing.T) {
|
func TestRelativeTemplate(t *testing.T) {
|
||||||
wkdir, err := os.Getwd()
|
tmpDir := os.TempDir()
|
||||||
assert.Nil(t, err)
|
dir := filepath.Join(tmpDir, "_beeTmp")
|
||||||
dir := filepath.Join(wkdir, "_beeTmp")
|
|
||||||
|
|
||||||
// Just add dir to known viewPaths
|
// Just add dir to known viewPaths
|
||||||
if err := AddViewPath(dir); err != nil {
|
if err := AddViewPath(dir); err != nil {
|
||||||
@ -226,10 +224,10 @@ var output = `<!DOCTYPE html>
|
|||||||
`
|
`
|
||||||
|
|
||||||
func TestTemplateLayout(t *testing.T) {
|
func TestTemplateLayout(t *testing.T) {
|
||||||
wkdir, err := os.Getwd()
|
tmpDir, err := os.Getwd()
|
||||||
assert.Nil(t, err)
|
assert.Nil(t, err)
|
||||||
|
|
||||||
dir := filepath.Join(wkdir, "_beeTmp", "TestTemplateLayout")
|
dir := filepath.Join(tmpDir, "_beeTmp", "TestTemplateLayout")
|
||||||
files := []string{
|
files := []string{
|
||||||
"add.tpl",
|
"add.tpl",
|
||||||
"layout_blog.tpl",
|
"layout_blog.tpl",
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user