github.com/blend/go-sdk@v1.20220411.3/configmeta/paths_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 configmeta
     9  
    10  import (
    11  	"context"
    12  	"testing"
    13  
    14  	"github.com/blend/go-sdk/assert"
    15  	"github.com/blend/go-sdk/configutil"
    16  	"github.com/blend/go-sdk/env"
    17  )
    18  
    19  func Test_Paths_fallbacks(t *testing.T) {
    20  	its := assert.New(t)
    21  
    22  	var opts configutil.ConfigOptions
    23  
    24  	vars := env.Vars{
    25  		env.VarServiceName: "bar",
    26  	}
    27  	ctx := env.WithVars(context.Background(), vars)
    28  	its.Nil(PathsFileContext(ctx, "foo.yml")(&opts))
    29  	its.Equal([]string{"/var/secrets/projects/bar/foo.yml", "/var/secrets/foo.yml"}, opts.FilePaths)
    30  }
    31  
    32  func Test_Paths_fallbacks_project(t *testing.T) {
    33  	its := assert.New(t)
    34  
    35  	var opts configutil.ConfigOptions
    36  
    37  	vars := env.Vars{
    38  		env.VarServiceName: "bar",
    39  		env.VarProjectName: "bar-proj",
    40  	}
    41  	ctx := env.WithVars(context.Background(), vars)
    42  	its.Nil(PathsFileContext(ctx, "foo.yml")(&opts))
    43  	its.Equal([]string{"/var/secrets/projects/bar-proj/foo.yml", "/var/secrets/foo.yml"}, opts.FilePaths)
    44  }
    45  
    46  func Test_Paths_env_projectPath(t *testing.T) {
    47  	its := assert.New(t)
    48  
    49  	var opts configutil.ConfigOptions
    50  
    51  	vars := env.Vars{
    52  		env.VarServiceName:      "bar",
    53  		env.VarProjectName:      "bar-proj",
    54  		EnvVarProjectConfigPath: "/var/project/secrets/bar/foo.yml",
    55  	}
    56  	ctx := env.WithVars(context.Background(), vars)
    57  	its.Nil(PathsFileContext(ctx, "foo.yml")(&opts))
    58  	its.Equal([]string{"/var/project/secrets/bar/foo.yml", "/var/secrets/foo.yml"}, opts.FilePaths)
    59  }
    60  
    61  func Test_Paths_env_configPath(t *testing.T) {
    62  	its := assert.New(t)
    63  
    64  	var opts configutil.ConfigOptions
    65  
    66  	vars := env.Vars{
    67  		env.VarServiceName:      "bar",
    68  		env.VarProjectName:      "bar-proj",
    69  		EnvVarProjectConfigPath: "/var/project/secrets/bar/foo.yml",
    70  		EnvVarConfigPath:        "/var/not-secrets/foo.yml",
    71  	}
    72  	ctx := env.WithVars(context.Background(), vars)
    73  	its.Nil(PathsFileContext(ctx, "foo.yml")(&opts))
    74  	its.Equal([]string{"/var/project/secrets/bar/foo.yml", "/var/not-secrets/foo.yml"}, opts.FilePaths)
    75  }