github.com/blend/go-sdk@v1.20220411.3/web/view_cache_config_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 "context" 12 "testing" 13 14 "github.com/blend/go-sdk/assert" 15 "github.com/blend/go-sdk/configutil" 16 "github.com/blend/go-sdk/env" 17 ) 18 19 var ( 20 _ configutil.Resolver = (*ViewCacheConfig)(nil) 21 ) 22 23 func TestViewCacheConfigResolve(t *testing.T) { 24 assert := assert.New(t) 25 vcc := &ViewCacheConfig{} 26 27 defer env.Restore() 28 env.SetEnv(env.New()) 29 assert.Nil(vcc.Resolve(env.WithVars(context.Background(), env.Env()))) 30 assert.False(vcc.LiveReload) 31 32 env.Env().Set("LIVE_RELOAD", "true") 33 assert.Nil(vcc.Resolve(env.WithVars(context.Background(), env.Env()))) 34 assert.True(vcc.LiveReload) 35 } 36 37 func TestViewCacheConfigBufferPool(t *testing.T) { 38 assert := assert.New(t) 39 vcc := &ViewCacheConfig{} 40 assert.Equal(DefaultViewBufferPoolSize, vcc.BufferPoolSizeOrDefault()) 41 vcc.BufferPoolSize = 10 42 assert.Equal(vcc.BufferPoolSize, vcc.BufferPoolSizeOrDefault()) 43 } 44 45 func TestViewCacheConfigTemplateNames(t *testing.T) { 46 assert := assert.New(t) 47 vcc := &ViewCacheConfig{} 48 assert.Equal(DefaultTemplateNameInternalError, vcc.InternalErrorTemplateNameOrDefault()) 49 vcc.InternalErrorTemplateName = "hello" 50 assert.Equal(vcc.InternalErrorTemplateName, vcc.InternalErrorTemplateNameOrDefault()) 51 52 assert.Equal(DefaultTemplateNameBadRequest, vcc.BadRequestTemplateNameOrDefault()) 53 vcc.BadRequestTemplateName = "hello" 54 assert.Equal(vcc.BadRequestTemplateName, vcc.BadRequestTemplateNameOrDefault()) 55 56 assert.Equal(DefaultTemplateNameNotFound, vcc.NotFoundTemplateNameOrDefault()) 57 vcc.NotFoundTemplateName = "hello" 58 assert.Equal(vcc.NotFoundTemplateName, vcc.NotFoundTemplateNameOrDefault()) 59 60 assert.Equal(DefaultTemplateNameNotAuthorized, vcc.NotAuthorizedTemplateNameOrDefault()) 61 vcc.NotAuthorizedTemplateName = "hello" 62 assert.Equal(vcc.NotAuthorizedTemplateName, vcc.NotAuthorizedTemplateNameOrDefault()) 63 64 assert.Equal(DefaultTemplateNameStatus, vcc.StatusTemplateNameOrDefault()) 65 vcc.StatusTemplateName = "hello" 66 assert.Equal(vcc.StatusTemplateName, vcc.StatusTemplateNameOrDefault()) 67 }