github.com/blend/go-sdk@v1.20220411.3/testutil/opt_with_default_dbs.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 testutil 9 10 import ( 11 "context" 12 13 "github.com/blend/go-sdk/db" 14 ) 15 16 // OptWithDefaultDBs runs a test suite with a count of database connections. 17 // Note: this type of connection pool is used in rare circumstances for 18 // performance reasons; you probably want to use `OptWithDefaultDB` for your tests. 19 func OptWithDefaultDBs(count int) Option { 20 return func(s *Suite) { 21 s.Before = append(s.Before, func(ctx context.Context) error { 22 _defaultDBs = make([]*db.Connection, count) 23 for index := 0; index < count; index++ { 24 conn, err := CreateTestDatabase(ctx) 25 if err != nil { 26 return err 27 } 28 _defaultDBs[index] = conn 29 } 30 return nil 31 }) 32 s.After = append(s.After, func(ctx context.Context) error { 33 for index := range _defaultDBs { 34 if err := _defaultDBs[index].Close(); err != nil { 35 return err 36 } 37 if err := DropTestDatabase(ctx, _defaultDBs[index]); err != nil { 38 return err 39 } 40 } 41 return nil 42 }) 43 } 44 }