github.com/blend/go-sdk@v1.20220411.3/configutil/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 configutil
     9  
    10  import (
    11  	"testing"
    12  
    13  	"github.com/blend/go-sdk/assert"
    14  	"github.com/blend/go-sdk/env"
    15  )
    16  
    17  func Test_OptAddPaths(t *testing.T) {
    18  	assert := assert.New(t)
    19  
    20  	var options ConfigOptions
    21  	assert.Nil(OptAddPaths("foo", "bar")(&options))
    22  	assert.Len(options.FilePaths, 2)
    23  	assert.Equal([]string{"foo", "bar"}, options.FilePaths)
    24  
    25  	assert.Nil(OptAddPaths("moo", "loo")(&options))
    26  	assert.Len(options.FilePaths, 4)
    27  	assert.Equal([]string{"foo", "bar", "moo", "loo"}, options.FilePaths)
    28  }
    29  
    30  func Test_OptAddPreferredPaths(t *testing.T) {
    31  	assert := assert.New(t)
    32  
    33  	var options ConfigOptions
    34  	assert.Nil(OptAddPreferredPaths("foo", "bar")(&options))
    35  	assert.Len(options.FilePaths, 2)
    36  	assert.Equal([]string{"foo", "bar"}, options.FilePaths)
    37  
    38  	assert.Nil(OptAddPreferredPaths("moo", "loo")(&options))
    39  	assert.Len(options.FilePaths, 4)
    40  	assert.Equal([]string{"moo", "loo", "foo", "bar"}, options.FilePaths)
    41  }
    42  
    43  func Test_OptPaths(t *testing.T) {
    44  	assert := assert.New(t)
    45  
    46  	var options ConfigOptions
    47  	assert.Nil(OptPaths("foo", "bar")(&options))
    48  	assert.Len(options.FilePaths, 2)
    49  	assert.Equal([]string{"foo", "bar"}, options.FilePaths)
    50  
    51  	assert.Nil(OptPaths("moo", "loo")(&options))
    52  	assert.Len(options.FilePaths, 2)
    53  	assert.Equal([]string{"moo", "loo"}, options.FilePaths)
    54  }
    55  
    56  func Test_OptEnv(t *testing.T) {
    57  	assert := assert.New(t)
    58  
    59  	var options ConfigOptions
    60  	assert.Empty(options.Env)
    61  	assert.Nil(OptEnv(env.Vars{"FOO": "bar"})(&options))
    62  	assert.NotEmpty(options.Env)
    63  	assert.Len(options.Env, 1)
    64  	assert.Equal("bar", options.Env["FOO"])
    65  }