master
go 59 lines 1.2 KB
Raw
1 // SPDX-License-Identifier: GPL-3.0-or-later
2
3 package chartengine
4
5 import (
6 "testing"
7
8 "github.com/stretchr/testify/assert"
9 "github.com/stretchr/testify/require"
10 )
11
12 func TestParseTemplateLiteralOnly(t *testing.T) {
13 t.Parallel()
14
15 tests := map[string]struct {
16 in string
17 wantRaw string
18 wantErr bool
19 }{
20 "plain literal": {
21 in: "mysql_queries",
22 wantRaw: "mysql_queries",
23 },
24 "trims surrounding whitespace": {
25 in: " mysql_queries ",
26 wantRaw: "mysql_queries",
27 },
28 "keeps braces as literal characters": {
29 in: "osd_{osd_uuid}_space_usage",
30 wantRaw: "osd_{osd_uuid}_space_usage",
31 },
32 "keeps pipes as literal characters": {
33 in: "disk|iops|total",
34 wantRaw: "disk|iops|total",
35 },
36 "keeps malformed placeholder-like text as literal": {
37 in: `{key|replace("unterminated)}`,
38 wantRaw: `{key|replace("unterminated)}`,
39 },
40 "rejects empty template": {
41 in: " \t\n ",
42 wantErr: true,
43 },
44 }
45
46 for name, tc := range tests {
47 t.Run(name, func(t *testing.T) {
48 t.Parallel()
49
50 got, err := parseTemplate(tc.in)
51 if tc.wantErr {
52 require.Error(t, err)
53 return
54 }
55 require.NoError(t, err)
56 assert.Equal(t, tc.wantRaw, got.Raw)
57 })
58 }
59 }