github.com/blend/go-sdk@v1.20220411.3/web/default_provider_middleware_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  	"testing"
    13  
    14  	"github.com/blend/go-sdk/assert"
    15  	"github.com/blend/go-sdk/webutil"
    16  )
    17  
    18  func TestDefaultProviderMiddlewares(t *testing.T) {
    19  	assert := assert.New(t)
    20  
    21  	r := applyMiddleware(JSONProviderAsDefault)
    22  	_, ok := r.DefaultProvider.(JSONResultProvider)
    23  	assert.True(ok)
    24  
    25  	r = applyMiddleware(ViewProviderAsDefault)
    26  	_, ok = r.DefaultProvider.(*ViewCache)
    27  	assert.True(ok)
    28  
    29  	r = applyMiddleware(XMLProviderAsDefault)
    30  	_, ok = r.DefaultProvider.(XMLResultProvider)
    31  	assert.True(ok)
    32  
    33  	r = applyMiddleware(TextProviderAsDefault)
    34  	_, ok = r.DefaultProvider.(TextResultProvider)
    35  	assert.True(ok)
    36  }
    37  
    38  func applyMiddleware(middleware Middleware) (output *Ctx) {
    39  	middleware(func(ctx *Ctx) Result {
    40  		output = ctx
    41  		return NoContent
    42  	})(NewCtx(webutil.NewMockResponse(new(bytes.Buffer)), webutil.NewMockRequest("GET", "/")))
    43  	return
    44  }