mirror of https://github.com/gin-gonic/gin.git
parent
1ae32f3a2c
commit
6159213462
|
@ -1117,7 +1117,7 @@ func main() {
|
||||||
router.SetFuncMap(template.FuncMap{
|
router.SetFuncMap(template.FuncMap{
|
||||||
"formatAsDate": formatAsDate,
|
"formatAsDate": formatAsDate,
|
||||||
})
|
})
|
||||||
router.LoadHTMLFiles("./fixtures/basic/raw.tmpl")
|
router.LoadHTMLFiles("./testdata/template/raw.tmpl")
|
||||||
|
|
||||||
router.GET("/raw", func(c *gin.Context) {
|
router.GET("/raw", func(c *gin.Context) {
|
||||||
c.HTML(http.StatusOK, "raw.tmpl", map[string]interface{}{
|
c.HTML(http.StatusOK, "raw.tmpl", map[string]interface{}{
|
||||||
|
|
|
@ -5,7 +5,7 @@ import (
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/gin-gonic/gin/binding/example"
|
"github.com/gin-gonic/gin/testdata/protoexample"
|
||||||
"github.com/golang/protobuf/proto"
|
"github.com/golang/protobuf/proto"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/ugorji/go/codec"
|
"github.com/ugorji/go/codec"
|
||||||
|
@ -55,12 +55,12 @@ func msgPackBody(t *testing.T) string {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestBindingBodyProto(t *testing.T) {
|
func TestBindingBodyProto(t *testing.T) {
|
||||||
test := example.Test{
|
test := protoexample.Test{
|
||||||
Label: proto.String("FOO"),
|
Label: proto.String("FOO"),
|
||||||
}
|
}
|
||||||
data, _ := proto.Marshal(&test)
|
data, _ := proto.Marshal(&test)
|
||||||
req := requestWithBody("POST", "/", string(data))
|
req := requestWithBody("POST", "/", string(data))
|
||||||
form := example.Test{}
|
form := protoexample.Test{}
|
||||||
body, _ := ioutil.ReadAll(req.Body)
|
body, _ := ioutil.ReadAll(req.Body)
|
||||||
assert.NoError(t, ProtoBuf.BindBody(body, &form))
|
assert.NoError(t, ProtoBuf.BindBody(body, &form))
|
||||||
assert.Equal(t, test, form)
|
assert.Equal(t, test, form)
|
||||||
|
|
|
@ -14,7 +14,7 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/gin-gonic/gin/binding/example"
|
"github.com/gin-gonic/gin/testdata/protoexample"
|
||||||
"github.com/golang/protobuf/proto"
|
"github.com/golang/protobuf/proto"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/ugorji/go/codec"
|
"github.com/ugorji/go/codec"
|
||||||
|
@ -562,7 +562,7 @@ func TestBindingFormMultipartFail(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestBindingProtoBuf(t *testing.T) {
|
func TestBindingProtoBuf(t *testing.T) {
|
||||||
test := &example.Test{
|
test := &protoexample.Test{
|
||||||
Label: proto.String("yes"),
|
Label: proto.String("yes"),
|
||||||
}
|
}
|
||||||
data, _ := proto.Marshal(test)
|
data, _ := proto.Marshal(test)
|
||||||
|
@ -574,7 +574,7 @@ func TestBindingProtoBuf(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestBindingProtoBufFail(t *testing.T) {
|
func TestBindingProtoBufFail(t *testing.T) {
|
||||||
test := &example.Test{
|
test := &protoexample.Test{
|
||||||
Label: proto.String("yes"),
|
Label: proto.String("yes"),
|
||||||
}
|
}
|
||||||
data, _ := proto.Marshal(test)
|
data, _ := proto.Marshal(test)
|
||||||
|
@ -1156,14 +1156,14 @@ func testBodyBindingFail(t *testing.T, b Binding, name, path, badPath, body, bad
|
||||||
func testProtoBodyBinding(t *testing.T, b Binding, name, path, badPath, body, badBody string) {
|
func testProtoBodyBinding(t *testing.T, b Binding, name, path, badPath, body, badBody string) {
|
||||||
assert.Equal(t, name, b.Name())
|
assert.Equal(t, name, b.Name())
|
||||||
|
|
||||||
obj := example.Test{}
|
obj := protoexample.Test{}
|
||||||
req := requestWithBody("POST", path, body)
|
req := requestWithBody("POST", path, body)
|
||||||
req.Header.Add("Content-Type", MIMEPROTOBUF)
|
req.Header.Add("Content-Type", MIMEPROTOBUF)
|
||||||
err := b.Bind(req, &obj)
|
err := b.Bind(req, &obj)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Equal(t, "yes", *obj.Label)
|
assert.Equal(t, "yes", *obj.Label)
|
||||||
|
|
||||||
obj = example.Test{}
|
obj = protoexample.Test{}
|
||||||
req = requestWithBody("POST", badPath, badBody)
|
req = requestWithBody("POST", badPath, badBody)
|
||||||
req.Header.Add("Content-Type", MIMEPROTOBUF)
|
req.Header.Add("Content-Type", MIMEPROTOBUF)
|
||||||
err = ProtoBuf.Bind(req, &obj)
|
err = ProtoBuf.Bind(req, &obj)
|
||||||
|
@ -1179,7 +1179,7 @@ func (h hook) Read([]byte) (int, error) {
|
||||||
func testProtoBodyBindingFail(t *testing.T, b Binding, name, path, badPath, body, badBody string) {
|
func testProtoBodyBindingFail(t *testing.T, b Binding, name, path, badPath, body, badBody string) {
|
||||||
assert.Equal(t, name, b.Name())
|
assert.Equal(t, name, b.Name())
|
||||||
|
|
||||||
obj := example.Test{}
|
obj := protoexample.Test{}
|
||||||
req := requestWithBody("POST", path, body)
|
req := requestWithBody("POST", path, body)
|
||||||
|
|
||||||
req.Body = ioutil.NopCloser(&hook{})
|
req.Body = ioutil.NopCloser(&hook{})
|
||||||
|
@ -1187,7 +1187,7 @@ func testProtoBodyBindingFail(t *testing.T, b Binding, name, path, badPath, body
|
||||||
err := b.Bind(req, &obj)
|
err := b.Bind(req, &obj)
|
||||||
assert.Error(t, err)
|
assert.Error(t, err)
|
||||||
|
|
||||||
obj = example.Test{}
|
obj = protoexample.Test{}
|
||||||
req = requestWithBody("POST", badPath, badBody)
|
req = requestWithBody("POST", badPath, badBody)
|
||||||
req.Header.Add("Content-Type", MIMEPROTOBUF)
|
req.Header.Add("Content-Type", MIMEPROTOBUF)
|
||||||
err = ProtoBuf.Bind(req, &obj)
|
err = ProtoBuf.Bind(req, &obj)
|
||||||
|
|
|
@ -72,7 +72,7 @@ func TestDebugPrintLoadTemplate(t *testing.T) {
|
||||||
setup(&w)
|
setup(&w)
|
||||||
defer teardown()
|
defer teardown()
|
||||||
|
|
||||||
templ := template.Must(template.New("").Delims("{[{", "}]}").ParseGlob("./fixtures/basic/hello.tmpl"))
|
templ := template.Must(template.New("").Delims("{[{", "}]}").ParseGlob("./testdata/template/hello.tmpl"))
|
||||||
debugPrintLoadTemplate(templ)
|
debugPrintLoadTemplate(templ)
|
||||||
assert.Regexp(t, `^\[GIN-debug\] Loaded HTML Templates \(2\): \n(\t- \n|\t- hello\.tmpl\n){2}\n`, w.String())
|
assert.Regexp(t, `^\[GIN-debug\] Loaded HTML Templates \(2\): \n(\t- \n|\t- hello\.tmpl\n){2}\n`, w.String())
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,7 +20,7 @@ func main() {
|
||||||
router.SetFuncMap(template.FuncMap{
|
router.SetFuncMap(template.FuncMap{
|
||||||
"formatAsDate": formatAsDate,
|
"formatAsDate": formatAsDate,
|
||||||
})
|
})
|
||||||
router.LoadHTMLFiles("../../fixtures/basic/raw.tmpl")
|
router.LoadHTMLFiles("../../testdata/template/raw.tmpl")
|
||||||
|
|
||||||
router.GET("/raw", func(c *gin.Context) {
|
router.GET("/raw", func(c *gin.Context) {
|
||||||
c.HTML(http.StatusOK, "raw.tmpl", map[string]interface{}{
|
c.HTML(http.StatusOK, "raw.tmpl", map[string]interface{}{
|
||||||
|
|
|
@ -30,7 +30,7 @@ func setupHTMLFiles(t *testing.T, mode string, tls bool) func() {
|
||||||
router.SetFuncMap(template.FuncMap{
|
router.SetFuncMap(template.FuncMap{
|
||||||
"formatAsDate": formatAsDate,
|
"formatAsDate": formatAsDate,
|
||||||
})
|
})
|
||||||
router.LoadHTMLFiles("./fixtures/basic/hello.tmpl", "./fixtures/basic/raw.tmpl")
|
router.LoadHTMLFiles("./testdata/template/hello.tmpl", "./testdata/template/raw.tmpl")
|
||||||
router.GET("/test", func(c *Context) {
|
router.GET("/test", func(c *Context) {
|
||||||
c.HTML(http.StatusOK, "hello.tmpl", map[string]string{"name": "world"})
|
c.HTML(http.StatusOK, "hello.tmpl", map[string]string{"name": "world"})
|
||||||
})
|
})
|
||||||
|
@ -41,7 +41,7 @@ func setupHTMLFiles(t *testing.T, mode string, tls bool) func() {
|
||||||
})
|
})
|
||||||
if tls {
|
if tls {
|
||||||
// these files generated by `go run $GOROOT/src/crypto/tls/generate_cert.go --host 127.0.0.1`
|
// these files generated by `go run $GOROOT/src/crypto/tls/generate_cert.go --host 127.0.0.1`
|
||||||
router.RunTLS(":9999", "./fixtures/testdata/cert.pem", "./fixtures/testdata/key.pem")
|
router.RunTLS(":9999", "./testdata/certificate/cert.pem", "./testdata/certificate/key.pem")
|
||||||
} else {
|
} else {
|
||||||
router.Run(":8888")
|
router.Run(":8888")
|
||||||
}
|
}
|
||||||
|
@ -59,7 +59,7 @@ func setupHTMLGlob(t *testing.T, mode string, tls bool) func() {
|
||||||
router.SetFuncMap(template.FuncMap{
|
router.SetFuncMap(template.FuncMap{
|
||||||
"formatAsDate": formatAsDate,
|
"formatAsDate": formatAsDate,
|
||||||
})
|
})
|
||||||
router.LoadHTMLGlob("./fixtures/basic/*")
|
router.LoadHTMLGlob("./testdata/template/*")
|
||||||
router.GET("/test", func(c *Context) {
|
router.GET("/test", func(c *Context) {
|
||||||
c.HTML(http.StatusOK, "hello.tmpl", map[string]string{"name": "world"})
|
c.HTML(http.StatusOK, "hello.tmpl", map[string]string{"name": "world"})
|
||||||
})
|
})
|
||||||
|
@ -70,7 +70,7 @@ func setupHTMLGlob(t *testing.T, mode string, tls bool) func() {
|
||||||
})
|
})
|
||||||
if tls {
|
if tls {
|
||||||
// these files generated by `go run $GOROOT/src/crypto/tls/generate_cert.go --host 127.0.0.1`
|
// these files generated by `go run $GOROOT/src/crypto/tls/generate_cert.go --host 127.0.0.1`
|
||||||
router.RunTLS(":9999", "./fixtures/testdata/cert.pem", "./fixtures/testdata/key.pem")
|
router.RunTLS(":9999", "./testdata/certificate/cert.pem", "./testdata/certificate/key.pem")
|
||||||
} else {
|
} else {
|
||||||
router.Run(":8888")
|
router.Run(":8888")
|
||||||
}
|
}
|
||||||
|
|
|
@ -388,7 +388,7 @@ func TestRenderHTMLTemplateEmptyName(t *testing.T) {
|
||||||
|
|
||||||
func TestRenderHTMLDebugFiles(t *testing.T) {
|
func TestRenderHTMLDebugFiles(t *testing.T) {
|
||||||
w := httptest.NewRecorder()
|
w := httptest.NewRecorder()
|
||||||
htmlRender := HTMLDebug{Files: []string{"../fixtures/basic/hello.tmpl"},
|
htmlRender := HTMLDebug{Files: []string{"../testdata/template/hello.tmpl"},
|
||||||
Glob: "",
|
Glob: "",
|
||||||
Delims: Delims{Left: "{[{", Right: "}]}"},
|
Delims: Delims{Left: "{[{", Right: "}]}"},
|
||||||
FuncMap: nil,
|
FuncMap: nil,
|
||||||
|
@ -407,7 +407,7 @@ func TestRenderHTMLDebugFiles(t *testing.T) {
|
||||||
func TestRenderHTMLDebugGlob(t *testing.T) {
|
func TestRenderHTMLDebugGlob(t *testing.T) {
|
||||||
w := httptest.NewRecorder()
|
w := httptest.NewRecorder()
|
||||||
htmlRender := HTMLDebug{Files: nil,
|
htmlRender := HTMLDebug{Files: nil,
|
||||||
Glob: "../fixtures/basic/hello*",
|
Glob: "../testdata/template/hello*",
|
||||||
Delims: Delims{Left: "{[{", Right: "}]}"},
|
Delims: Delims{Left: "{[{", Right: "}]}"},
|
||||||
FuncMap: nil,
|
FuncMap: nil,
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
// DO NOT EDIT!
|
// DO NOT EDIT!
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Package example is a generated protocol buffer package.
|
Package protoexample is a generated protocol buffer package.
|
||||||
|
|
||||||
It is generated from these files:
|
It is generated from these files:
|
||||||
test.proto
|
test.proto
|
||||||
|
@ -11,7 +11,7 @@ It is generated from these files:
|
||||||
It has these top-level messages:
|
It has these top-level messages:
|
||||||
Test
|
Test
|
||||||
*/
|
*/
|
||||||
package example
|
package protoexample
|
||||||
|
|
||||||
import proto "github.com/golang/protobuf/proto"
|
import proto "github.com/golang/protobuf/proto"
|
||||||
import math "math"
|
import math "math"
|
||||||
|
@ -109,5 +109,5 @@ func (m *Test_OptionalGroup) GetRequiredField() string {
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
proto.RegisterEnum("example.FOO", FOO_name, FOO_value)
|
proto.RegisterEnum("protoexample.FOO", FOO_name, FOO_value)
|
||||||
}
|
}
|
|
@ -1,4 +1,4 @@
|
||||||
package example;
|
package protoexample;
|
||||||
|
|
||||||
enum FOO {X=17;};
|
enum FOO {X=17;};
|
||||||
|
|
Loading…
Reference in New Issue