github.com/blend/go-sdk@v1.20220411.3/testutil/opt_with_default_db.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  
    14  // OptWithDefaultDB runs a test suite with a dedicated database connection.
    15  func OptWithDefaultDB() Option {
    16  	return func(s *Suite) {
    17  		var err error
    18  		s.Before = append(s.Before, func(ctx context.Context) error {
    19  			_defaultDB, err = CreateTestDatabase(ctx)
    20  			if err != nil {
    21  				return err
    22  			}
    23  			return nil
    24  		})
    25  		s.After = append(s.After, func(ctx context.Context) error {
    26  			if err := _defaultDB.Close(); err != nil {
    27  				return err
    28  			}
    29  			return DropTestDatabase(ctx, _defaultDB)
    30  		})
    31  	}
    32  }