github.com/blend/go-sdk@v1.20220411.3/web/redirect_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 func TestRedirectResult(t *testing.T) { 20 assert := assert.New(t) 21 22 resBody := new(bytes.Buffer) 23 res := webutil.NewMockResponse(resBody) 24 req := webutil.NewMockRequest("GET", "/") 25 ctx := NewCtx(res, req) 26 27 assert.Nil((&RedirectResult{RedirectURI: "/foo"}).Render(ctx)) 28 29 assert.Equal(http.StatusTemporaryRedirect, res.StatusCode()) 30 assert.Contains(resBody.String(), "/foo", resBody.String()) 31 } 32 33 func TestRedirectResultMethod(t *testing.T) { 34 assert := assert.New(t) 35 36 resBody := new(bytes.Buffer) 37 res := webutil.NewMockResponse(resBody) 38 req := webutil.NewMockRequest("POST", "/") 39 ctx := NewCtx(res, req) 40 41 assert.Nil((&RedirectResult{Method: "GET", RedirectURI: "/foo"}).Render(ctx)) 42 43 assert.Equal(http.StatusFound, res.StatusCode()) 44 assert.Contains(resBody.String(), "/foo", resBody.String()) 45 }