Bladeren bron

unify test data (#1417)

mkdir a test data dir.
田欧 7 jaren geleden
bovenliggende
commit
6159213462

+ 1 - 1
README.md

@@ -1117,7 +1117,7 @@ func main() {
     router.SetFuncMap(template.FuncMap{
         "formatAsDate": formatAsDate,
     })
-    router.LoadHTMLFiles("./fixtures/basic/raw.tmpl")
+    router.LoadHTMLFiles("./testdata/template/raw.tmpl")
 
     router.GET("/raw", func(c *gin.Context) {
         c.HTML(http.StatusOK, "raw.tmpl", map[string]interface{}{

+ 3 - 3
binding/binding_body_test.go

@@ -5,7 +5,7 @@ import (
 	"io/ioutil"
 	"testing"
 
-	"github.com/gin-gonic/gin/binding/example"
+	"github.com/gin-gonic/gin/testdata/protoexample"
 	"github.com/golang/protobuf/proto"
 	"github.com/stretchr/testify/assert"
 	"github.com/ugorji/go/codec"
@@ -55,12 +55,12 @@ func msgPackBody(t *testing.T) string {
 }
 
 func TestBindingBodyProto(t *testing.T) {
-	test := example.Test{
+	test := protoexample.Test{
 		Label: proto.String("FOO"),
 	}
 	data, _ := proto.Marshal(&test)
 	req := requestWithBody("POST", "/", string(data))
-	form := example.Test{}
+	form := protoexample.Test{}
 	body, _ := ioutil.ReadAll(req.Body)
 	assert.NoError(t, ProtoBuf.BindBody(body, &form))
 	assert.Equal(t, test, form)

+ 7 - 7
binding/binding_test.go

@@ -14,7 +14,7 @@ import (
 	"testing"
 	"time"
 
-	"github.com/gin-gonic/gin/binding/example"
+	"github.com/gin-gonic/gin/testdata/protoexample"
 	"github.com/golang/protobuf/proto"
 	"github.com/stretchr/testify/assert"
 	"github.com/ugorji/go/codec"
@@ -562,7 +562,7 @@ func TestBindingFormMultipartFail(t *testing.T) {
 }
 
 func TestBindingProtoBuf(t *testing.T) {
-	test := &example.Test{
+	test := &protoexample.Test{
 		Label: proto.String("yes"),
 	}
 	data, _ := proto.Marshal(test)
@@ -574,7 +574,7 @@ func TestBindingProtoBuf(t *testing.T) {
 }
 
 func TestBindingProtoBufFail(t *testing.T) {
-	test := &example.Test{
+	test := &protoexample.Test{
 		Label: proto.String("yes"),
 	}
 	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) {
 	assert.Equal(t, name, b.Name())
 
-	obj := example.Test{}
+	obj := protoexample.Test{}
 	req := requestWithBody("POST", path, body)
 	req.Header.Add("Content-Type", MIMEPROTOBUF)
 	err := b.Bind(req, &obj)
 	assert.NoError(t, err)
 	assert.Equal(t, "yes", *obj.Label)
 
-	obj = example.Test{}
+	obj = protoexample.Test{}
 	req = requestWithBody("POST", badPath, badBody)
 	req.Header.Add("Content-Type", MIMEPROTOBUF)
 	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) {
 	assert.Equal(t, name, b.Name())
 
-	obj := example.Test{}
+	obj := protoexample.Test{}
 	req := requestWithBody("POST", path, body)
 
 	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)
 	assert.Error(t, err)
 
-	obj = example.Test{}
+	obj = protoexample.Test{}
 	req = requestWithBody("POST", badPath, badBody)
 	req.Header.Add("Content-Type", MIMEPROTOBUF)
 	err = ProtoBuf.Bind(req, &obj)

+ 1 - 1
debug_test.go

@@ -72,7 +72,7 @@ func TestDebugPrintLoadTemplate(t *testing.T) {
 	setup(&w)
 	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)
 	assert.Regexp(t, `^\[GIN-debug\] Loaded HTML Templates \(2\): \n(\t- \n|\t- hello\.tmpl\n){2}\n`, w.String())
 }

+ 1 - 1
examples/template/main.go

@@ -20,7 +20,7 @@ func main() {
 	router.SetFuncMap(template.FuncMap{
 		"formatAsDate": formatAsDate,
 	})
-	router.LoadHTMLFiles("../../fixtures/basic/raw.tmpl")
+	router.LoadHTMLFiles("../../testdata/template/raw.tmpl")
 
 	router.GET("/raw", func(c *gin.Context) {
 		c.HTML(http.StatusOK, "raw.tmpl", map[string]interface{}{

+ 4 - 4
gin_test.go

@@ -30,7 +30,7 @@ func setupHTMLFiles(t *testing.T, mode string, tls bool) func() {
 		router.SetFuncMap(template.FuncMap{
 			"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) {
 			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 {
 			// 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 {
 			router.Run(":8888")
 		}
@@ -59,7 +59,7 @@ func setupHTMLGlob(t *testing.T, mode string, tls bool) func() {
 		router.SetFuncMap(template.FuncMap{
 			"formatAsDate": formatAsDate,
 		})
-		router.LoadHTMLGlob("./fixtures/basic/*")
+		router.LoadHTMLGlob("./testdata/template/*")
 		router.GET("/test", func(c *Context) {
 			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 {
 			// 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 {
 			router.Run(":8888")
 		}

+ 2 - 2
render/render_test.go

@@ -388,7 +388,7 @@ func TestRenderHTMLTemplateEmptyName(t *testing.T) {
 
 func TestRenderHTMLDebugFiles(t *testing.T) {
 	w := httptest.NewRecorder()
-	htmlRender := HTMLDebug{Files: []string{"../fixtures/basic/hello.tmpl"},
+	htmlRender := HTMLDebug{Files: []string{"../testdata/template/hello.tmpl"},
 		Glob:    "",
 		Delims:  Delims{Left: "{[{", Right: "}]}"},
 		FuncMap: nil,
@@ -407,7 +407,7 @@ func TestRenderHTMLDebugFiles(t *testing.T) {
 func TestRenderHTMLDebugGlob(t *testing.T) {
 	w := httptest.NewRecorder()
 	htmlRender := HTMLDebug{Files: nil,
-		Glob:    "../fixtures/basic/hello*",
+		Glob:    "../testdata/template/hello*",
 		Delims:  Delims{Left: "{[{", Right: "}]}"},
 		FuncMap: nil,
 	}

+ 0 - 0
fixtures/testdata/cert.pem → testdata/certificate/cert.pem


+ 0 - 0
fixtures/testdata/key.pem → testdata/certificate/key.pem


+ 3 - 3
binding/example/test.pb.go → testdata/protoexample/test.pb.go

@@ -3,7 +3,7 @@
 // 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:
 	test.proto
@@ -11,7 +11,7 @@ It is generated from these files:
 It has these top-level messages:
 	Test
 */
-package example
+package protoexample
 
 import proto "github.com/golang/protobuf/proto"
 import math "math"
@@ -109,5 +109,5 @@ func (m *Test_OptionalGroup) GetRequiredField() string {
 }
 
 func init() {
-	proto.RegisterEnum("example.FOO", FOO_name, FOO_value)
+	proto.RegisterEnum("protoexample.FOO", FOO_name, FOO_value)
 }

+ 1 - 1
binding/example/test.proto → testdata/protoexample/test.proto

@@ -1,4 +1,4 @@
-package example;
+package protoexample;
 
 enum FOO {X=17;};
 

+ 0 - 0
fixtures/basic/hello.tmpl → testdata/template/hello.tmpl


+ 0 - 0
fixtures/basic/raw.tmpl → testdata/template/raw.tmpl