From 3621bcf5a65e526d9473f73622144066a0e09082 Mon Sep 17 00:00:00 2001 From: Daniel Nelson Date: Mon, 7 Jan 2019 14:13:37 -0800 Subject: [PATCH] Add basic unittest for templating engine --- internal/templating/engine_test.go | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 internal/templating/engine_test.go diff --git a/internal/templating/engine_test.go b/internal/templating/engine_test.go new file mode 100644 index 000000000..b7dd23f38 --- /dev/null +++ b/internal/templating/engine_test.go @@ -0,0 +1,22 @@ +package templating + +import ( + "testing" + + "github.com/stretchr/testify/require" +) + +func TestEngineAlternateSeparator(t *testing.T) { + defaultTemplate, _ := NewDefaultTemplateWithPattern("topic*") + engine, err := NewEngine("_", defaultTemplate, []string{ + "/ /*/*/* /measurement/origin/measurement*", + }) + require.NoError(t, err) + name, tags, field, err := engine.Apply("/telegraf/host01/cpu") + require.NoError(t, err) + require.Equal(t, "telegraf_cpu", name) + require.Equal(t, map[string]string{ + "origin": "host01", + }, tags) + require.Equal(t, "", field) +}