github.com/blend/go-sdk@v1.20220411.3/web/xml_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 TestXMLResultProvider(t *testing.T) {
    19  	assert := assert.New(t)
    20  
    21  	assert.Equal(http.StatusNotFound, XML.NotFound().(*XMLResult).StatusCode)
    22  	assert.Equal("Not Found", XML.NotFound().(*XMLResult).Response)
    23  
    24  	assert.Equal(http.StatusUnauthorized, XML.NotAuthorized().(*XMLResult).StatusCode)
    25  	assert.Equal("Not Authorized", XML.NotAuthorized().(*XMLResult).Response)
    26  
    27  	assert.Equal(http.StatusBadRequest, XML.BadRequest(nil).(*XMLResult).StatusCode)
    28  	assert.Equal("Bad Request", XML.BadRequest(nil).(*XMLResult).Response)
    29  
    30  	assert.Equal(http.StatusBadRequest, XML.BadRequest(fmt.Errorf("bad-request")).(*XMLResult).StatusCode)
    31  	assert.Equal(fmt.Errorf("bad-request"), XML.BadRequest(fmt.Errorf("bad-request")).(*XMLResult).Response)
    32  
    33  	assert.Equal(http.StatusOK, XML.OK().(*XMLResult).StatusCode)
    34  	assert.Equal("OK!", XML.OK().(*XMLResult).Response)
    35  
    36  	assert.Equal(http.StatusBadGateway, XML.Status(http.StatusBadGateway, "test").(*XMLResult).StatusCode)
    37  	assert.Equal("test", XML.Status(http.StatusBadGateway, "test").(*XMLResult).Response)
    38  
    39  	assert.Equal(http.StatusOK, XML.Result("foo").(*XMLResult).StatusCode)
    40  	assert.Equal("foo", XML.Result("foo").(*XMLResult).Response)
    41  
    42  	internalError := XML.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.(*XMLResult)
    48  	assert.Equal(http.StatusInternalServerError, inner.StatusCode)
    49  	assert.Equal(fmt.Errorf("only a test"), inner.Response)
    50  }