github.com/blend/go-sdk@v1.20220411.3/web/text_result_provider_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 "fmt" 12 "net/http" 13 "testing" 14 15 "github.com/blend/go-sdk/assert" 16 ) 17 18 func TestTextResultProvider(t *testing.T) { 19 assert := assert.New(t) 20 21 assert.Equal(http.StatusNotFound, Text.NotFound().(*RawResult).StatusCode) 22 assert.Equal("Not Found", string(Text.NotFound().(*RawResult).Response)) 23 24 assert.Equal(http.StatusUnauthorized, Text.NotAuthorized().(*RawResult).StatusCode) 25 assert.Equal("Not Authorized", string(Text.NotAuthorized().(*RawResult).Response)) 26 27 assert.Equal(http.StatusBadRequest, Text.BadRequest(nil).(*RawResult).StatusCode) 28 assert.Equal("Bad Request", string(Text.BadRequest(nil).(*RawResult).Response)) 29 30 assert.Equal(http.StatusBadRequest, Text.BadRequest(fmt.Errorf("bad-request")).(*RawResult).StatusCode) 31 assert.Equal("Bad Request: bad-request", string(Text.BadRequest(fmt.Errorf("bad-request")).(*RawResult).Response)) 32 33 assert.Equal(http.StatusOK, Text.OK().(*RawResult).StatusCode) 34 assert.Equal("OK!", string(Text.OK().(*RawResult).Response)) 35 36 assert.Equal(http.StatusBadGateway, Text.Status(http.StatusBadGateway, "test").(*RawResult).StatusCode) 37 assert.Equal("test", string(Text.Status(http.StatusBadGateway, "test").(*RawResult).Response)) 38 39 assert.Equal(http.StatusOK, Text.Result("foo").(*RawResult).StatusCode) 40 assert.Equal("foo", string(Text.Result("foo").(*RawResult).Response)) 41 42 internalError := Text.InternalError(fmt.Errorf("only a test")) 43 44 typed, ok := internalError.(*LoggedErrorResult) 45 assert.True(ok) 46 assert.Equal(fmt.Errorf("only a test"), typed.Error) 47 inner := typed.Result.(*RawResult) 48 assert.Equal(http.StatusInternalServerError, inner.StatusCode) 49 assert.Equal("only a test", string(inner.Response)) 50 }