github.com/johnnyeven/libtools@v0.0.0-20191126065708-61829c1adf46/httplib/context/context_test.go (about) 1 package context 2 3 import ( 4 "bytes" 5 "net/http" 6 "reflect" 7 "testing" 8 9 "github.com/gin-gonic/gin" 10 ) 11 12 func getNormalContext() *gin.Context { 13 c := gin.Context{} 14 request, _ := http.NewRequest("GET", "http://127.0.0.1/testgo/v0/sum?num1=1&num2=2", nil) 15 c.Request = request 16 rwiter := TestResponseWriter{} 17 rwiter.Body = *bytes.NewBuffer([]byte{}) 18 c.Writer = &rwiter 19 c.Writer.Write([]byte{'1'}) 20 return &c 21 } 22 23 func TestGetTestContextBody(t *testing.T) { 24 type args struct { 25 c *gin.Context 26 } 27 tests := []struct { 28 name string 29 args args 30 want []byte 31 }{ 32 { 33 name: "normal", 34 args: args{ 35 getNormalContext(), 36 }, 37 want: []byte{'1'}, 38 }, 39 } 40 for _, tt := range tests { 41 if got := GetTestContextBody(tt.args.c); !reflect.DeepEqual(got, tt.want) { 42 t.Errorf("%q. GetTestContextBody() = %v, want %v", tt.name, got, tt.want) 43 } 44 } 45 }