github.com/blend/go-sdk@v1.20220411.3/db/invocation_option_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 db 9 10 import ( 11 "context" 12 "testing" 13 "time" 14 15 "github.com/blend/go-sdk/assert" 16 ) 17 18 func TestInvocationOptions(t *testing.T) { 19 assert := assert.New(t) 20 21 i := &Invocation{} 22 23 assert.Empty(i.Label) 24 OptLabel("label")(i) 25 assert.Equal("label", i.Label) 26 27 assert.Nil(i.StatementInterceptor) 28 OptInvocationStatementInterceptor(func(_ context.Context, label, statement string) (string, error) { return "OK!", nil })(i) 29 assert.NotNil(i.StatementInterceptor) 30 31 assert.Nil(i.Context) 32 OptContext(context.Background())(i) 33 assert.NotNil(i.Context) 34 35 assert.Nil(i.Cancel) 36 OptCancel(func() {})(i) 37 assert.NotNil(i.Cancel) 38 39 i.Cancel = nil 40 assert.Nil(i.Cancel) 41 OptTimeout(5 * time.Second)(i) 42 assert.NotNil(i.Cancel) 43 assert.NotNil(i.Context) 44 45 i.DB = defaultDB().Connection 46 assert.NotNil(i.DB) 47 OptTx(nil)(i) 48 assert.NotNil(i.DB) 49 50 i.DB = nil 51 tx, err := defaultDB().Begin() 52 assert.Nil(err) 53 OptTx(tx)(i) 54 assert.NotNil(i.DB) 55 56 i.DB = nil 57 OptInvocationDB(defaultDB().Connection)(i) 58 assert.NotNil(i.DB) 59 60 i.DB = nil 61 OptInvocationDB(tx)(i) 62 assert.NotNil(i.DB) 63 64 i.StatementInterceptor = nil 65 OptInvocationStatementInterceptor(failInterceptor)(i) 66 assert.NotNil(i.StatementInterceptor) 67 }