github.com/blend/go-sdk@v1.20220411.3/web/xml_result_test.go (about) 1 /* 2 3 Copyright (c) 2022 - Present. Blend Labs, Inc. All rights reserved 4 Use of this source code is governed by a MIT license that can be found in the LICENSE file. 5 6 */ 7 8 package web 9 10 import ( 11 "bytes" 12 "net/http" 13 "testing" 14 15 "github.com/blend/go-sdk/assert" 16 "github.com/blend/go-sdk/webutil" 17 ) 18 19 type xmltest struct { 20 Foo string `xml:"foo"` 21 } 22 23 func TestXMLResultRender(t *testing.T) { 24 assert := assert.New(t) 25 26 buf := new(bytes.Buffer) 27 w := webutil.NewMockResponse(buf) 28 r := NewCtx(w, webutil.NewMockRequest("GET", "/")) 29 30 xr := &XMLResult{ 31 StatusCode: http.StatusOK, 32 Response: xmltest{Foo: "bar"}, 33 } 34 35 assert.Nil(xr.Render(r)) 36 assert.Equal(http.StatusOK, w.StatusCode()) 37 assert.Equal("<xmltest><foo>bar</foo></xmltest>", buf.String()) 38 } 39 40 func TestXMLResultRenderStatusCode(t *testing.T) { 41 assert := assert.New(t) 42 43 buf := new(bytes.Buffer) 44 w := webutil.NewMockResponse(buf) 45 r := NewCtx(w, webutil.NewMockRequest("GET", "/")) 46 47 xr := &XMLResult{ 48 StatusCode: http.StatusBadRequest, 49 Response: xmltest{Foo: "bar"}, 50 } 51 52 assert.Nil(xr.Render(r)) 53 assert.Equal(http.StatusBadRequest, w.StatusCode()) 54 assert.Equal("<xmltest><foo>bar</foo></xmltest>", buf.String()) 55 }