MCPcopy Create free account
hub / github.com/bytebase/bytebase / TestParseFilter

Function TestParseFilter

backend/api/v1/common_test.go:44–91  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

42}
43
44func TestParseFilter(t *testing.T) {
45 testCases := []struct {
46 input string
47 want []Expression
48 err error
49 }{
50 {
51 input: `resource="environments/e1/instances/i2"`,
52 want: []Expression{
53 {
54 Key: "resource",
55 Operator: ComparatorTypeEqual,
56 Value: "environments/e1/instances/i2",
57 },
58 },
59 },
60 {
61 input: `project = "p1" && start_time>="2020-01-01T00:00:00Z" && start_time<2020-01-02T00:00:00Z`,
62 want: []Expression{
63 {
64 Key: "project",
65 Operator: ComparatorTypeEqual,
66 Value: "p1",
67 },
68 {
69 Key: "start_time",
70 Operator: ComparatorTypeGreaterEqual,
71 Value: "2020-01-01T00:00:00Z",
72 },
73 {
74 Key: "start_time",
75 Operator: ComparatorTypeLess,
76 Value: "2020-01-02T00:00:00Z",
77 },
78 },
79 },
80 }
81
82 for _, test := range testCases {
83 got, err := ParseFilter(test.input)
84 if test.err != nil {
85 require.EqualError(t, err, test.err.Error())
86 } else {
87 require.NoError(t, err)
88 require.Equal(t, test.want, got)
89 }
90 }
91}
92
93func TestIsValidateOnlyRequest(t *testing.T) {
94 tests := []struct {

Callers

nothing calls this directly

Calls 3

ParseFilterFunction · 0.85
EqualMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected