Debian Codegraph @

cmd/influx/cli/parser_internal_test.go

raw
1 package cli
2
3 import (
4 "errors"
5 "testing"
6 )
7
8 func Test_parseDatabaseAndretentionPolicy(t *testing.T) {
9 tests := []struct {
10 stmt string
11 db string
12 rp string
13 err error
14 }{
15 {
16 stmt: `foo`,
17 db: "foo",
18 },
19 {
20 stmt: `"foo.bar"`,
21 db: "foo.bar",
22 },
23 {
24 stmt: `"foo.bar".`,
25 db: "foo.bar",
26 },
27 {
28 stmt: `."foo.bar"`,
29 rp: "foo.bar",
30 },
31 {
32 stmt: `foo.bar`,
33 db: "foo",
34 rp: "bar",
35 },
36 {
37 stmt: `"foo".bar`,
38 db: "foo",
39 rp: "bar",
40 },
41 {
42 stmt: `"foo"."bar"`,
43 db: "foo",
44 rp: "bar",
45 },
46 {
47 stmt: `"foo.bin"."bar"`,
48 db: "foo.bin",
49 rp: "bar",
50 },
51 {
52 stmt: `"foo.bin"."bar.baz...."`,
53 db: "foo.bin",
54 rp: "bar.baz....",
55 },
56 {
57 stmt: ` "foo.bin"."bar.baz...." `,
58 db: "foo.bin",
59 rp: "bar.baz....",
60 },
61
62 {
63 stmt: `"foo.bin"."bar".boom`,
64 err: errors.New("foo"),
65 },
66 {
67 stmt: "foo.bar.",
68 err: errors.New("foo"),
69 },
70 }
71
72 for _, test := range tests {
73 db, rp, err := parseDatabaseAndRetentionPolicy([]byte(test.stmt))
74 if err != nil && test.err == nil {
75 t.Errorf("unexpected error: got %s", err)
76 continue
77 }
78 if test.err != nil && err == nil {
79 t.Errorf("expected err: got: nil, exp: %s", test.err)
80 continue
81 }
82 if db != test.db {
83 t.Errorf("unexpected database: got: %s, exp: %s", db, test.db)
84 }
85 if rp != test.rp {
86 t.Errorf("unexpected retention policy: got: %s, exp: %s", rp, test.rp)
87 }
88 }
89
90 }