mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2024-12-15 08:23:34 +01:00
d0288ea417
This should prevent from using incorrect config files
37 lines
715 B
Go
37 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}")
|
|
}
|