github.com/blend/go-sdk@v1.20220411.3/configmeta/meta_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/env" 16 ) 17 18 func Test_Meta_Resolve_envOverrides(t *testing.T) { 19 its := assert.New(t) 20 21 bareCfg := &Meta{ 22 ServiceName: "not-mock-test", 23 ServiceEnv: "not-mock-test-env", 24 Hostname: "not-mock-hostname", 25 } 26 27 vars := env.Vars{ 28 env.VarServiceName: "mock-test", 29 env.VarServiceEnv: "mock-test-env", 30 env.VarHostname: "mock-test-hostname", 31 } 32 ctx := env.WithVars(context.Background(), vars) 33 err := bareCfg.Resolve(ctx) 34 its.Nil(err) 35 36 its.Equal("mock-test", bareCfg.ServiceName) 37 its.Equal("mock-test-env", bareCfg.ServiceEnv) 38 its.Equal("mock-test-hostname", bareCfg.Hostname) 39 40 its.Equal("mock-test", bareCfg.ServiceNameOrDefault()) 41 its.Equal("mock-test-env", bareCfg.ServiceEnvOrDefault()) 42 }