github.com/yandex/pandora@v0.5.32/lib/confutil/env_var_resolver_test.go (about)

     1  package confutil
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/stretchr/testify/assert"
     7  )
     8  
     9  func TestEnvVarResolver(t *testing.T) {
    10  	type testCase struct {
    11  		varname string
    12  		val     string
    13  		err     error
    14  	}
    15  
    16  	tests := []testCase{
    17  		{"SOME_BOOL", "True", nil},
    18  		{"INT_VALUE", "10", nil},
    19  		{"V_NAME", "10", nil},
    20  	}
    21  
    22  	for _, test := range tests {
    23  		t.Setenv(test.varname, test.val)
    24  	}
    25  
    26  	tests = append(tests, testCase{"NOT_EXISTS", "", ErrEnvVariableNotProvided})
    27  
    28  	for _, test := range tests {
    29  		actual, err := envTokenResolver(test.varname)
    30  		if test.err != nil {
    31  			assert.ErrorIs(t, err, test.err)
    32  		} else {
    33  			assert.NoError(t, err)
    34  			assert.Exactly(t, test.val, actual)
    35  		}
    36  	}
    37  }