forked from stripe/veneur
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow templating when loading configs. (stripe#1004)
- Loading branch information
1 parent
1851efb
commit 48ec7e4
Showing
3 changed files
with
76 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package config_test | ||
|
||
import ( | ||
"io/ioutil" | ||
"os" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
"github.com/stripe/veneur/v14/util/config" | ||
) | ||
|
||
type Config struct { | ||
Key1 string | ||
} | ||
|
||
func TestReadConfigWithoutTemplate(t *testing.T) { | ||
file, err := ioutil.TempFile("", "config.yaml") | ||
require.NoError(t, err) | ||
defer os.Remove(file.Name()) | ||
|
||
file.Write([]byte("key1: value1")) | ||
|
||
parsedConfig, err := | ||
config.ReadConfig[Config](file.Name(), nil, "") | ||
require.NoError(t, err) | ||
|
||
assert.Equal(t, "value1", parsedConfig.Key1) | ||
} | ||
|
||
type ConfigParams struct { | ||
ConfigValue string | ||
} | ||
|
||
func TestReadConfigWithTemplate(t *testing.T) { | ||
file, err := ioutil.TempFile("", "config.yaml") | ||
require.NoError(t, err) | ||
defer os.Remove(file.Name()) | ||
|
||
file.Write([]byte("key1: {{.ConfigValue}}")) | ||
|
||
parsedConfig, err := | ||
config.ReadConfig[Config](file.Name(), ConfigParams{ | ||
ConfigValue: "value1", | ||
}, "") | ||
require.NoError(t, err) | ||
|
||
assert.Equal(t, "value1", parsedConfig.Key1) | ||
} |