mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2024-12-11 14:53:49 +00:00
069401a304
This should prevent from using incorrect config files
36 lines
715 B
Go
36 lines
715 B
Go
package envtemplate
|
|
|
|
import (
|
|
"os"
|
|
"testing"
|
|
)
|
|
|
|
func TestReplaceSuccess(t *testing.T) {
|
|
if err := os.Setenv("foo", "bar"); err != nil {
|
|
t.Fatalf("cannot set env var: %s", err)
|
|
}
|
|
f := func(s, resultExpected string) {
|
|
t.Helper()
|
|
result, err := Replace([]byte(s))
|
|
if err != nil {
|
|
t.Fatalf("unexpected error: %s", err)
|
|
}
|
|
if string(result) != resultExpected {
|
|
t.Fatalf("unexpected result;\ngot\n%q\nwant\n%q", result, resultExpected)
|
|
}
|
|
}
|
|
f("", "")
|
|
f("foo", "foo")
|
|
f("a %{foo}-x", "a bar-x")
|
|
}
|
|
|
|
func TestReplaceFailure(t *testing.T) {
|
|
f := func(s string) {
|
|
t.Helper()
|
|
_, err := Replace([]byte(s))
|
|
if err == nil {
|
|
t.Fatalf("expecting non-nil error")
|
|
}
|
|
}
|
|
f("foo %{bar} %{baz}")
|
|
}
|