github.com/blend/go-sdk@v1.20220411.3/configutil/resolve_if_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 configutil
     9  
    10  import (
    11  	"context"
    12  	"testing"
    13  
    14  	"github.com/blend/go-sdk/assert"
    15  )
    16  
    17  func TestResolveIf(t *testing.T) {
    18  	assert := assert.New(t)
    19  
    20  	var called bool
    21  	assert.Nil(ResolveIf(false, func(_ context.Context) error {
    22  		called = true
    23  		return nil
    24  	})(context.Background()))
    25  
    26  	assert.False(called)
    27  
    28  	assert.Nil(ResolveIf(true, func(_ context.Context) error {
    29  		called = true
    30  		return nil
    31  	})(context.Background()))
    32  	assert.True(called)
    33  }
    34  
    35  func TestResolveIfFunc(t *testing.T) {
    36  	assert := assert.New(t)
    37  
    38  	returnBool := func(v bool) func(context.Context) bool {
    39  		return func(_ context.Context) bool {
    40  			return v
    41  		}
    42  	}
    43  
    44  	var called bool
    45  	assert.Nil(ResolveIfFunc(returnBool(false), func(_ context.Context) error {
    46  		called = true
    47  		return nil
    48  	})(context.Background()))
    49  
    50  	assert.False(called)
    51  
    52  	assert.Nil(ResolveIfFunc(returnBool(true), func(_ context.Context) error {
    53  		called = true
    54  		return nil
    55  	})(context.Background()))
    56  	assert.True(called)
    57  }