Files
core/restream/app/process_test.go
Ingo Oppermann a2898061b0 Add optional escape character to process placeholder
If a value for a placeholder needs escaping, add the character to
escape with an "^" to the name of the placeholder, e.g. {memfs^:}.
This will escape all occurences of ":" in the value for {memfs}
with a "\".
2022-07-04 20:20:15 +02:00

46 lines
1.0 KiB
Go

package app
import (
"testing"
"github.com/stretchr/testify/require"
)
func TestReplace(t *testing.T) {
foobar := `;:.,-_$£!^`
samples := [][2]string{
{"{foobar}", foobar},
{"{foobar^:}", `;\:.,-_$£!^`},
{"{foobar^:}barfoo{foobar^:}", `;\:.,-_$£!^barfoo;\:.,-_$£!^`},
{"{foobar^:.}", "{foobar^:.}"},
{"{foobar^}", "{foobar^}"},
{"{barfoo^:}", "{barfoo^:}"},
{"{foobar^^}", `;:.,-_$£!\^`},
}
for _, e := range samples {
replaced := replace(e[0], "foobar", foobar)
require.Equal(t, e[1], replaced)
}
}
func TestCreateCommand(t *testing.T) {
config := &Config{
Options: []string{"-global", "global"},
Input: []ConfigIO{
{Address: "inputAddress", Options: []string{"-input", "inputoption"}},
},
Output: []ConfigIO{
{Address: "outputAddress", Options: []string{"-output", "oututoption"}},
},
}
command := config.CreateCommand()
require.Equal(t, []string{
"-global", "global",
"-input", "inputoption", "-i", "inputAddress",
"-output", "oututoption", "outputAddress",
}, command)
}