hotdog 0.1.18 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.travis.yml +6 -0
- data/README.md +2 -0
- data/hotdog.gemspec +1 -0
- data/lib/hotdog/commands/down.rb +3 -3
- data/lib/hotdog/commands/hosts.rb +3 -11
- data/lib/hotdog/commands/search.rb +146 -92
- data/lib/hotdog/commands/tags.rb +23 -17
- data/lib/hotdog/commands/up.rb +3 -3
- data/lib/hotdog/commands.rb +145 -195
- data/lib/hotdog/formatters/ltsv.rb +9 -4
- data/lib/hotdog/formatters/plain.rb +1 -1
- data/lib/hotdog/version.rb +1 -1
- data/spec/core/application_spec.rb +36 -0
- data/spec/formatter/csv_spec.rb +33 -0
- data/spec/formatter/json_spec.rb +66 -0
- data/spec/formatter/ltsv_spec.rb +32 -0
- data/spec/formatter/plain_spec.rb +76 -0
- data/spec/formatter/text_spec.rb +76 -0
- data/spec/formatter/tsv_spec.rb +33 -0
- data/spec/formatter/yaml_spec.rb +49 -0
- data/spec/parser/parser_spec.rb +300 -0
- data/spec/parser/tag_expression_spec.rb +63 -0
- data/spec/parser/tag_glob_expression_spec.rb +63 -0
- data/spec/parser/tag_regexp_expression_spec.rb +63 -0
- data/spec/spec_helper.rb +1 -0
- metadata +44 -3
@@ -0,0 +1,76 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
require "hotdog/formatters"
|
3
|
+
require "hotdog/formatters/plain"
|
4
|
+
|
5
|
+
describe "plain" do
|
6
|
+
let(:fmt) {
|
7
|
+
Hotdog::Formatters::Plain.new
|
8
|
+
}
|
9
|
+
|
10
|
+
it "generates plain (print0) without headers" do
|
11
|
+
options = {
|
12
|
+
headers: false,
|
13
|
+
print0: true,
|
14
|
+
print1: false,
|
15
|
+
}
|
16
|
+
expect(fmt.format([["foo", "aaa", 1], ["bar", "bbb", 2], ["baz", "ccc", 3]], options)).to eq("foo aaa 1\0bar bbb 2\0baz ccc 3")
|
17
|
+
end
|
18
|
+
|
19
|
+
it "generates plain (print0) with headers" do
|
20
|
+
options = {
|
21
|
+
headers: true,
|
22
|
+
fields: ["key1", "key2", "val1"],
|
23
|
+
print0: true,
|
24
|
+
print1: false,
|
25
|
+
}
|
26
|
+
expect(fmt.format([["foo", "aaa", 1], ["bar", "bbb", 2], ["baz", "ccc", 3]], options)).to eq("foo aaa 1\0bar bbb 2\0baz ccc 3")
|
27
|
+
end
|
28
|
+
|
29
|
+
it "generates plain (print1) without headers" do
|
30
|
+
options = {
|
31
|
+
headers: false,
|
32
|
+
print0: false,
|
33
|
+
print1: true,
|
34
|
+
}
|
35
|
+
expect(fmt.format([["foo", "aaa", 1], ["bar", "bbb", 2], ["baz", "ccc", 3]], options)).to eq(<<-EOS)
|
36
|
+
foo aaa 1
|
37
|
+
bar bbb 2
|
38
|
+
baz ccc 3
|
39
|
+
EOS
|
40
|
+
end
|
41
|
+
|
42
|
+
it "generates plain (print1) with headers" do
|
43
|
+
options = {
|
44
|
+
headers: true,
|
45
|
+
fields: ["key1", "key2", "val1"],
|
46
|
+
print0: false,
|
47
|
+
print1: true,
|
48
|
+
}
|
49
|
+
expect(fmt.format([["foo", "aaa", 1], ["bar", "bbb", 2], ["baz", "ccc", 3]], options)).to eq(<<-EOS)
|
50
|
+
key1 key2 val1
|
51
|
+
---- ---- ----
|
52
|
+
foo aaa 1
|
53
|
+
bar bbb 2
|
54
|
+
baz ccc 3
|
55
|
+
EOS
|
56
|
+
end
|
57
|
+
|
58
|
+
it "generates plain (space) without headers" do
|
59
|
+
options = {
|
60
|
+
headers: false,
|
61
|
+
print0: false,
|
62
|
+
print1: false,
|
63
|
+
}
|
64
|
+
expect(fmt.format([["foo", "aaa", 1], ["bar", "bbb", 2], ["baz", "ccc", 3]], options)).to eq("foo aaa 1 bar bbb 2 baz ccc 3\n")
|
65
|
+
end
|
66
|
+
|
67
|
+
it "generates plain (space) with headers" do
|
68
|
+
options = {
|
69
|
+
headers: true,
|
70
|
+
fields: ["key1", "key2", "val1"],
|
71
|
+
print0: false,
|
72
|
+
print1: false,
|
73
|
+
}
|
74
|
+
expect(fmt.format([["foo", "aaa", 1], ["bar", "bbb", 2], ["baz", "ccc", 3]], options)).to eq("foo aaa 1 bar bbb 2 baz ccc 3\n")
|
75
|
+
end
|
76
|
+
end
|
@@ -0,0 +1,76 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
require "hotdog/formatters"
|
3
|
+
require "hotdog/formatters/text"
|
4
|
+
|
5
|
+
describe "text" do
|
6
|
+
let(:fmt) {
|
7
|
+
Hotdog::Formatters::Text.new
|
8
|
+
}
|
9
|
+
|
10
|
+
it "generates text (print0) without headers" do
|
11
|
+
options = {
|
12
|
+
headers: false,
|
13
|
+
print0: true,
|
14
|
+
print1: false,
|
15
|
+
}
|
16
|
+
expect(fmt.format([["foo", "aaa", 1], ["bar", "bbb", 2], ["baz", "ccc", 3]], options)).to eq("foo aaa 1\0bar bbb 2\0baz ccc 3")
|
17
|
+
end
|
18
|
+
|
19
|
+
it "generates text (print0) with headers" do
|
20
|
+
options = {
|
21
|
+
headers: true,
|
22
|
+
fields: ["key1", "key2", "val1"],
|
23
|
+
print0: true,
|
24
|
+
print1: false,
|
25
|
+
}
|
26
|
+
expect(fmt.format([["foo", "aaa", 1], ["bar", "bbb", 2], ["baz", "ccc", 3]], options)).to eq("foo aaa 1\0bar bbb 2\0baz ccc 3")
|
27
|
+
end
|
28
|
+
|
29
|
+
it "generates text (print1) without headers" do
|
30
|
+
options = {
|
31
|
+
headers: false,
|
32
|
+
print0: false,
|
33
|
+
print1: true,
|
34
|
+
}
|
35
|
+
expect(fmt.format([["foo", "aaa", 1], ["bar", "bbb", 2], ["baz", "ccc", 3]], options)).to eq(<<-EOS)
|
36
|
+
foo aaa 1
|
37
|
+
bar bbb 2
|
38
|
+
baz ccc 3
|
39
|
+
EOS
|
40
|
+
end
|
41
|
+
|
42
|
+
it "generates text (print1) with headers" do
|
43
|
+
options = {
|
44
|
+
headers: true,
|
45
|
+
fields: ["key1", "key2", "val1"],
|
46
|
+
print0: false,
|
47
|
+
print1: true,
|
48
|
+
}
|
49
|
+
expect(fmt.format([["foo", "aaa", 1], ["bar", "bbb", 2], ["baz", "ccc", 3]], options)).to eq(<<-EOS)
|
50
|
+
key1 key2 val1
|
51
|
+
---- ---- ----
|
52
|
+
foo aaa 1
|
53
|
+
bar bbb 2
|
54
|
+
baz ccc 3
|
55
|
+
EOS
|
56
|
+
end
|
57
|
+
|
58
|
+
it "generates text (space) without headers" do
|
59
|
+
options = {
|
60
|
+
headers: false,
|
61
|
+
print0: false,
|
62
|
+
print1: false,
|
63
|
+
}
|
64
|
+
expect(fmt.format([["foo", "aaa", 1], ["bar", "bbb", 2], ["baz", "ccc", 3]], options)).to eq("foo aaa 1 bar bbb 2 baz ccc 3\n")
|
65
|
+
end
|
66
|
+
|
67
|
+
it "generates text (space) with headers" do
|
68
|
+
options = {
|
69
|
+
headers: true,
|
70
|
+
fields: ["key1", "key2", "val1"],
|
71
|
+
print0: false,
|
72
|
+
print1: false,
|
73
|
+
}
|
74
|
+
expect(fmt.format([["foo", "aaa", 1], ["bar", "bbb", 2], ["baz", "ccc", 3]], options)).to eq("foo aaa 1 bar bbb 2 baz ccc 3\n")
|
75
|
+
end
|
76
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
require "hotdog/formatters"
|
3
|
+
require "hotdog/formatters/tsv"
|
4
|
+
|
5
|
+
describe "tsv" do
|
6
|
+
let(:fmt) {
|
7
|
+
Hotdog::Formatters::Tsv.new
|
8
|
+
}
|
9
|
+
|
10
|
+
it "generates tsv without headers" do
|
11
|
+
options = {
|
12
|
+
headers: false,
|
13
|
+
}
|
14
|
+
expect(fmt.format([["foo", "aaa", 1], ["bar", "bbb", 2], ["baz", "ccc", 3]], options)).to eq(<<-EOS)
|
15
|
+
foo\taaa\t1
|
16
|
+
bar\tbbb\t2
|
17
|
+
baz\tccc\t3
|
18
|
+
EOS
|
19
|
+
end
|
20
|
+
|
21
|
+
it "generates tsv with headers" do
|
22
|
+
options = {
|
23
|
+
headers: true,
|
24
|
+
fields: ["key1", "key2", "val1"],
|
25
|
+
}
|
26
|
+
expect(fmt.format([["foo", "aaa", 1], ["bar", "bbb", 2], ["baz", "ccc", 3]], options)).to eq(<<-EOS)
|
27
|
+
key1\tkey2\tval1
|
28
|
+
foo\taaa\t1
|
29
|
+
bar\tbbb\t2
|
30
|
+
baz\tccc\t3
|
31
|
+
EOS
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
require "hotdog/formatters"
|
3
|
+
require "hotdog/formatters/yaml"
|
4
|
+
|
5
|
+
describe "yaml" do
|
6
|
+
let(:fmt) {
|
7
|
+
Hotdog::Formatters::Yaml.new
|
8
|
+
}
|
9
|
+
|
10
|
+
it "generates yaml without headers" do
|
11
|
+
options = {
|
12
|
+
headers: false,
|
13
|
+
}
|
14
|
+
expect(fmt.format([["foo", "aaa", 1], ["bar", "bbb", 2], ["baz", "ccc", 3]], options)).to eq(<<-EOS)
|
15
|
+
---
|
16
|
+
- - foo
|
17
|
+
- aaa
|
18
|
+
- 1
|
19
|
+
- - bar
|
20
|
+
- bbb
|
21
|
+
- 2
|
22
|
+
- - baz
|
23
|
+
- ccc
|
24
|
+
- 3
|
25
|
+
EOS
|
26
|
+
end
|
27
|
+
|
28
|
+
it "generates yaml with headers" do
|
29
|
+
options = {
|
30
|
+
headers: true,
|
31
|
+
fields: ["key1", "key2", "val1"],
|
32
|
+
}
|
33
|
+
expect(fmt.format([["foo", "aaa", 1], ["bar", "bbb", 2], ["baz", "ccc", 3]], options)).to eq(<<-EOS)
|
34
|
+
---
|
35
|
+
- - key1
|
36
|
+
- key2
|
37
|
+
- val1
|
38
|
+
- - foo
|
39
|
+
- aaa
|
40
|
+
- 1
|
41
|
+
- - bar
|
42
|
+
- bbb
|
43
|
+
- 2
|
44
|
+
- - baz
|
45
|
+
- ccc
|
46
|
+
- 3
|
47
|
+
EOS
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,300 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
require "hotdog/application"
|
3
|
+
require "hotdog/commands"
|
4
|
+
require "hotdog/commands/search"
|
5
|
+
require "parslet"
|
6
|
+
|
7
|
+
describe "parser" do
|
8
|
+
let(:cmd) {
|
9
|
+
Hotdog::Commands::Search.new(Hotdog::Application.new)
|
10
|
+
}
|
11
|
+
|
12
|
+
before(:each) do
|
13
|
+
ENV["DATADOG_API_KEY"] = "DATADOG_API_KEY"
|
14
|
+
ENV["DATADOG_APPLICATION_KEY"] = "DATADOG_APPLICATION_KEY"
|
15
|
+
end
|
16
|
+
|
17
|
+
it "parses ':foo'" do
|
18
|
+
expect(cmd.parse(":foo")).to eq({attribute: "foo"})
|
19
|
+
end
|
20
|
+
|
21
|
+
it "parses ':foo*'" do
|
22
|
+
expect(cmd.parse(":foo*")).to eq({attribute_glob: "foo*"})
|
23
|
+
end
|
24
|
+
|
25
|
+
it "parses ':/foo/'" do
|
26
|
+
expect(cmd.parse(":/foo/")).to eq({attribute_regexp: "/foo/"})
|
27
|
+
end
|
28
|
+
|
29
|
+
it "parses 'foo'" do
|
30
|
+
expect(cmd.parse("foo")).to eq({identifier: "foo"})
|
31
|
+
end
|
32
|
+
|
33
|
+
it "parses 'foo:bar'" do
|
34
|
+
expect(cmd.parse("foo:bar")).to eq({identifier: "foo", attribute: "bar"})
|
35
|
+
end
|
36
|
+
|
37
|
+
it "parses 'foo: bar'" do
|
38
|
+
expect(cmd.parse("foo:bar")).to eq({identifier: "foo", attribute: "bar"})
|
39
|
+
end
|
40
|
+
|
41
|
+
it "parses 'foo :bar'" do
|
42
|
+
expect(cmd.parse("foo:bar")).to eq({identifier: "foo", attribute: "bar"})
|
43
|
+
end
|
44
|
+
|
45
|
+
it "parses 'foo : bar'" do
|
46
|
+
expect(cmd.parse("foo:bar")).to eq({identifier: "foo", attribute: "bar"})
|
47
|
+
end
|
48
|
+
|
49
|
+
it "parses 'foo:bar*'" do
|
50
|
+
expect(cmd.parse("foo:bar*")).to eq({identifier: "foo", attribute_glob: "bar*"})
|
51
|
+
end
|
52
|
+
|
53
|
+
it "parses 'foo*'" do
|
54
|
+
expect(cmd.parse("foo*")).to eq({identifier_glob: "foo*"})
|
55
|
+
end
|
56
|
+
|
57
|
+
it "parses 'foo*:bar'" do
|
58
|
+
expect(cmd.parse("foo*:bar")).to eq({identifier_glob: "foo*", attribute: "bar"})
|
59
|
+
end
|
60
|
+
|
61
|
+
it "parses 'foo*:bar*'" do
|
62
|
+
expect(cmd.parse("foo*:bar*")).to eq({identifier_glob: "foo*", attribute_glob: "bar*"})
|
63
|
+
end
|
64
|
+
|
65
|
+
it "parses '/foo/'" do
|
66
|
+
expect(cmd.parse("/foo/")).to eq({identifier_regexp: "/foo/"})
|
67
|
+
end
|
68
|
+
|
69
|
+
it "parses '/foo/:/bar/'" do
|
70
|
+
expect(cmd.parse("/foo/:/bar/")).to eq({identifier_regexp: "/foo/", attribute_regexp: "/bar/"})
|
71
|
+
end
|
72
|
+
|
73
|
+
it "parses '(foo)'" do
|
74
|
+
expect(cmd.parse("(foo)")).to eq({identifier: "foo"})
|
75
|
+
end
|
76
|
+
|
77
|
+
it "parses '( foo )'" do
|
78
|
+
expect(cmd.parse("( foo )")).to eq({identifier: "foo"})
|
79
|
+
end
|
80
|
+
|
81
|
+
it "parses ' ( foo ) '" do
|
82
|
+
expect(cmd.parse(" ( foo ) ")).to eq({identifier: "foo"})
|
83
|
+
end
|
84
|
+
|
85
|
+
it "parses '((foo))'" do
|
86
|
+
expect(cmd.parse("((foo))")).to eq({identifier: "foo"})
|
87
|
+
end
|
88
|
+
|
89
|
+
it "parses '(( foo ))'" do
|
90
|
+
expect(cmd.parse("(( foo ))")).to eq({identifier: "foo"})
|
91
|
+
end
|
92
|
+
|
93
|
+
it "parses ' ( ( foo ) ) '" do
|
94
|
+
expect(cmd.parse("( ( foo ) )")).to eq({identifier: "foo"})
|
95
|
+
end
|
96
|
+
|
97
|
+
it "parses 'foo bar'" do
|
98
|
+
expect(cmd.parse("foo bar")).to eq({left: {identifier: "foo"}, binary_op: nil, right: {identifier: "bar"}})
|
99
|
+
end
|
100
|
+
|
101
|
+
it "parses 'foo bar baz'" do
|
102
|
+
expect(cmd.parse("foo bar baz")).to eq({left: {identifier: "foo"}, binary_op: nil, right: {left: {identifier: "bar"}, binary_op: nil, right: {identifier: "baz"}}})
|
103
|
+
end
|
104
|
+
|
105
|
+
it "parses 'not foo'" do
|
106
|
+
expect(cmd.parse("not foo")).to eq({unary_op: "not", expression: {identifier: "foo"}})
|
107
|
+
end
|
108
|
+
|
109
|
+
it "parses '! foo'" do
|
110
|
+
expect(cmd.parse("! foo")).to eq({unary_op: "!", expression: {identifier: "foo"}})
|
111
|
+
end
|
112
|
+
|
113
|
+
it "parses '~ foo'" do
|
114
|
+
expect(cmd.parse("~ foo")).to eq({unary_op: "~", expression: {identifier: "foo"}})
|
115
|
+
end
|
116
|
+
|
117
|
+
it "parses 'not(not foo)'" do
|
118
|
+
expect(cmd.parse("not(not foo)")).to eq({unary_op: "not", expression: {unary_op: "not", expression: {identifier: "foo"}}})
|
119
|
+
end
|
120
|
+
|
121
|
+
it "parses '!(!foo)'" do
|
122
|
+
expect(cmd.parse("!(!foo)")).to eq({unary_op: "!", expression: {unary_op: "!", expression: {identifier: "foo"}}})
|
123
|
+
end
|
124
|
+
|
125
|
+
it "parses '~(~foo)'" do
|
126
|
+
expect(cmd.parse("~(~foo)")).to eq({unary_op: "~", expression: {unary_op: "~", expression: {identifier: "foo"}}})
|
127
|
+
end
|
128
|
+
|
129
|
+
it "parses 'not not foo'" do
|
130
|
+
expect(cmd.parse("not not foo")).to eq({unary_op: "not", expression: {unary_op: "not", expression: {identifier: "foo"}}})
|
131
|
+
end
|
132
|
+
|
133
|
+
it "parses '!!foo'" do
|
134
|
+
expect(cmd.parse("!! foo")).to eq({unary_op: "!", expression: {unary_op: "!", expression: {identifier: "foo"}}})
|
135
|
+
end
|
136
|
+
|
137
|
+
it "parses '! ! foo'" do
|
138
|
+
expect(cmd.parse("!! foo")).to eq({unary_op: "!", expression: {unary_op: "!", expression: {identifier: "foo"}}})
|
139
|
+
end
|
140
|
+
|
141
|
+
it "parses '~~foo'" do
|
142
|
+
expect(cmd.parse("~~ foo")).to eq({unary_op: "~", expression: {unary_op: "~", expression: {identifier: "foo"}}})
|
143
|
+
end
|
144
|
+
|
145
|
+
it "parses '~ ~ foo'" do
|
146
|
+
expect(cmd.parse("~~ foo")).to eq({unary_op: "~", expression: {unary_op: "~", expression: {identifier: "foo"}}})
|
147
|
+
end
|
148
|
+
|
149
|
+
it "parses 'foo and bar'" do
|
150
|
+
expect(cmd.parse("foo and bar")).to eq({left: {identifier: "foo"}, binary_op: "and", right: {identifier: "bar"}})
|
151
|
+
end
|
152
|
+
|
153
|
+
it "parses 'foo and bar and baz'" do
|
154
|
+
expect(cmd.parse("foo and bar and baz")).to eq({left: {identifier: "foo"}, binary_op: "and", right: {left: {identifier: "bar"}, binary_op: "and", right: {identifier: "baz"}}})
|
155
|
+
end
|
156
|
+
|
157
|
+
it "parses 'foo&bar'" do
|
158
|
+
expect(cmd.parse("foo&bar")).to eq({left: {identifier: "foo"}, binary_op: "&", right: {identifier: "bar"}})
|
159
|
+
end
|
160
|
+
|
161
|
+
it "parses 'foo & bar'" do
|
162
|
+
expect(cmd.parse("foo & bar")).to eq({left: {identifier: "foo"}, binary_op: "&", right: {identifier: "bar"}})
|
163
|
+
end
|
164
|
+
|
165
|
+
it "parses 'foo&bar&baz'" do
|
166
|
+
expect(cmd.parse("foo & bar & baz")).to eq({left: {identifier: "foo"}, binary_op: "&", right: {left: {identifier: "bar"}, binary_op: "&", right: {identifier: "baz"}}})
|
167
|
+
end
|
168
|
+
|
169
|
+
it "parses 'foo & bar & baz'" do
|
170
|
+
expect(cmd.parse("foo & bar & baz")).to eq({left: {identifier: "foo"}, binary_op: "&", right: {left: {identifier: "bar"}, binary_op: "&", right: {identifier: "baz"}}})
|
171
|
+
end
|
172
|
+
|
173
|
+
it "parses 'foo&&bar'" do
|
174
|
+
expect(cmd.parse("foo&&bar")).to eq({left: {identifier: "foo"}, binary_op: "&&", right: {identifier: "bar"}})
|
175
|
+
end
|
176
|
+
|
177
|
+
it "parses 'foo && bar'" do
|
178
|
+
expect(cmd.parse("foo && bar")).to eq({left: {identifier: "foo"}, binary_op: "&&", right: {identifier: "bar"}})
|
179
|
+
end
|
180
|
+
|
181
|
+
it "parses 'foo&&bar&&baz'" do
|
182
|
+
expect(cmd.parse("foo&&bar&&baz")).to eq({left: {identifier: "foo"}, binary_op: "&&", right: {left: {identifier: "bar"}, binary_op: "&&", right: {identifier: "baz"}}})
|
183
|
+
end
|
184
|
+
|
185
|
+
it "parses 'foo && bar && baz'" do
|
186
|
+
expect(cmd.parse("foo && bar && baz")).to eq({left: {identifier: "foo"}, binary_op: "&&", right: {left: {identifier: "bar"}, binary_op: "&&", right: {identifier: "baz"}}})
|
187
|
+
end
|
188
|
+
|
189
|
+
it "parses 'foo or bar'" do
|
190
|
+
expect(cmd.parse("foo or bar")).to eq({left: {identifier: "foo"}, binary_op: "or", right: {identifier: "bar"}})
|
191
|
+
end
|
192
|
+
|
193
|
+
it "parses 'foo or bar or baz'" do
|
194
|
+
expect(cmd.parse("foo or bar or baz")).to eq({left: {identifier: "foo"}, binary_op: "or", right: {left: {identifier: "bar"}, binary_op: "or", right: {identifier: "baz"}}})
|
195
|
+
end
|
196
|
+
|
197
|
+
it "parses 'foo|bar'" do
|
198
|
+
expect(cmd.parse("foo|bar")).to eq({left: {identifier: "foo"}, binary_op: "|", right: {identifier: "bar"}})
|
199
|
+
end
|
200
|
+
|
201
|
+
it "parses 'foo | bar'" do
|
202
|
+
expect(cmd.parse("foo | bar")).to eq({left: {identifier: "foo"}, binary_op: "|", right: {identifier: "bar"}})
|
203
|
+
end
|
204
|
+
|
205
|
+
it "parses 'foo|bar|baz'" do
|
206
|
+
expect(cmd.parse("foo|bar|baz")).to eq({left: {identifier: "foo"}, binary_op: "|", right: {left: {identifier: "bar"}, binary_op: "|", right: {identifier: "baz"}}})
|
207
|
+
end
|
208
|
+
|
209
|
+
it "parses 'foo | bar | baz'" do
|
210
|
+
expect(cmd.parse("foo | bar | baz")).to eq({left: {identifier: "foo"}, binary_op: "|", right: {left: {identifier: "bar"}, binary_op: "|", right: {identifier: "baz"}}})
|
211
|
+
end
|
212
|
+
|
213
|
+
it "parses 'foo||bar'" do
|
214
|
+
expect(cmd.parse("foo||bar")).to eq({left: {identifier: "foo"}, binary_op: "||", right: {identifier: "bar"}})
|
215
|
+
end
|
216
|
+
|
217
|
+
it "parses 'foo || bar'" do
|
218
|
+
expect(cmd.parse("foo || bar")).to eq({left: {identifier: "foo"}, binary_op: "||", right: {identifier: "bar"}})
|
219
|
+
end
|
220
|
+
|
221
|
+
it "parses 'foo||bar||baz'" do
|
222
|
+
expect(cmd.parse("foo||bar||baz")).to eq({left: {identifier: "foo"}, binary_op: "||", right: {left: {identifier: "bar"}, binary_op: "||", right: {identifier: "baz"}}})
|
223
|
+
end
|
224
|
+
|
225
|
+
it "parses 'foo || bar || baz'" do
|
226
|
+
expect(cmd.parse("foo || bar || baz")).to eq({left: {identifier: "foo"}, binary_op: "||", right: {left: {identifier: "bar"}, binary_op: "||", right: {identifier: "baz"}}})
|
227
|
+
end
|
228
|
+
|
229
|
+
it "parses '(foo and bar) or baz'" do
|
230
|
+
expect(cmd.parse("(foo and bar) or baz")).to eq({left: {left: {identifier: "foo"}, binary_op: "and", right: {identifier: "bar"}}, binary_op: "or", right: {identifier: "baz"}})
|
231
|
+
end
|
232
|
+
|
233
|
+
it "parses 'foo and (bar or baz)'" do
|
234
|
+
expect(cmd.parse("foo and (bar or baz)")).to eq({left: {identifier: "foo"}, binary_op: "and", right: {left: {identifier: "bar"}, binary_op: "or", right: {identifier: "baz"}}})
|
235
|
+
end
|
236
|
+
|
237
|
+
it "parses 'not foo and bar'" do
|
238
|
+
expect(cmd.parse("not foo and bar")).to eq({left: {unary_op: "not", expression: {identifier: "foo"}}, binary_op: "and", right: {identifier: "bar"}})
|
239
|
+
end
|
240
|
+
|
241
|
+
it "parses '! foo and bar'" do
|
242
|
+
expect(cmd.parse("! foo and bar")).to eq({left: {unary_op: "!", expression: {identifier: "foo"}}, binary_op: "and", right: {identifier: "bar"}})
|
243
|
+
end
|
244
|
+
|
245
|
+
it "parses 'not foo && bar'" do
|
246
|
+
expect(cmd.parse("not foo && bar")).to eq({left: {unary_op: "not", expression: {identifier: "foo"}}, binary_op: "&&", right: {identifier: "bar"}})
|
247
|
+
end
|
248
|
+
|
249
|
+
it "parses '! foo && bar'" do
|
250
|
+
expect(cmd.parse("! foo && bar")).to eq({left: {unary_op: "!", expression: {identifier: "foo"}}, binary_op: "&&", right: {identifier: "bar"}})
|
251
|
+
end
|
252
|
+
|
253
|
+
it "is unable to parse ' '" do
|
254
|
+
expect {
|
255
|
+
cmd.parse(" ")
|
256
|
+
}.to raise_error(Parslet::ParseFailed)
|
257
|
+
end
|
258
|
+
|
259
|
+
it "is unable to parse '((()))'" do
|
260
|
+
expect {
|
261
|
+
cmd.parse("((()))")
|
262
|
+
}.to raise_error(Parslet::ParseFailed)
|
263
|
+
end
|
264
|
+
|
265
|
+
it "is unable to parse 'foo and'" do
|
266
|
+
expect {
|
267
|
+
cmd.parse("foo and")
|
268
|
+
}.to raise_error(Parslet::ParseFailed)
|
269
|
+
end
|
270
|
+
|
271
|
+
it "is unable to parse 'foo &'" do
|
272
|
+
expect {
|
273
|
+
cmd.parse("foo &")
|
274
|
+
}.to raise_error(Parslet::ParseFailed)
|
275
|
+
end
|
276
|
+
|
277
|
+
it "is unable to parse 'foo &&'" do
|
278
|
+
expect {
|
279
|
+
cmd.parse("foo &&")
|
280
|
+
}.to raise_error(Parslet::ParseFailed)
|
281
|
+
end
|
282
|
+
|
283
|
+
it "is unable to parse 'and foo'" do
|
284
|
+
expect {
|
285
|
+
cmd.parse("and foo")
|
286
|
+
}.to raise_error(Parslet::ParseFailed)
|
287
|
+
end
|
288
|
+
|
289
|
+
it "is unable to parse '& foo'" do
|
290
|
+
expect {
|
291
|
+
cmd.parse("& foo")
|
292
|
+
}.to raise_error(Parslet::ParseFailed)
|
293
|
+
end
|
294
|
+
|
295
|
+
it "is unable to parse '&& foo'" do
|
296
|
+
expect {
|
297
|
+
cmd.parse("&& foo")
|
298
|
+
}.to raise_error(Parslet::ParseFailed)
|
299
|
+
end
|
300
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
require "hotdog/application"
|
3
|
+
require "hotdog/commands"
|
4
|
+
require "hotdog/commands/search"
|
5
|
+
require "parslet"
|
6
|
+
|
7
|
+
describe "tag expression" do
|
8
|
+
let(:cmd) {
|
9
|
+
Hotdog::Commands::Search.new(Hotdog::Application.new)
|
10
|
+
}
|
11
|
+
|
12
|
+
it "interprets tag with host" do
|
13
|
+
expr = Hotdog::Commands::Search::TagExpressionNode.new("host", "foo")
|
14
|
+
q = [
|
15
|
+
"SELECT hosts.id FROM hosts",
|
16
|
+
"WHERE hosts.name = ?;",
|
17
|
+
]
|
18
|
+
allow(cmd).to receive(:execute).with(q.join(" "), ["foo"]) {
|
19
|
+
[[1], [2], [3]]
|
20
|
+
}
|
21
|
+
expect(expr.evaluate(cmd)).to eq([1, 2, 3])
|
22
|
+
end
|
23
|
+
|
24
|
+
it "interprets tag with identifier and attribute" do
|
25
|
+
expr = Hotdog::Commands::Search::TagExpressionNode.new("foo", "bar")
|
26
|
+
q = [
|
27
|
+
"SELECT DISTINCT hosts_tags.host_id FROM hosts_tags",
|
28
|
+
"INNER JOIN tags ON hosts_tags.tag_id = tags.id",
|
29
|
+
"WHERE tags.name = ? AND tags.value = ?;",
|
30
|
+
]
|
31
|
+
allow(cmd).to receive(:execute).with(q.join(" "), ["foo", "bar"]) {
|
32
|
+
[[1], [2], [3]]
|
33
|
+
}
|
34
|
+
expect(expr.evaluate(cmd)).to eq([1, 2, 3])
|
35
|
+
end
|
36
|
+
|
37
|
+
it "interprets tag with identifier" do
|
38
|
+
expr = Hotdog::Commands::Search::TagExpressionNode.new("foo", nil)
|
39
|
+
q = [
|
40
|
+
"SELECT DISTINCT hosts_tags.host_id FROM hosts_tags",
|
41
|
+
"INNER JOIN hosts ON hosts_tags.host_id = hosts.id",
|
42
|
+
"INNER JOIN tags ON hosts_tags.tag_id = tags.id",
|
43
|
+
"WHERE hosts.name = ? OR tags.name = ? OR tags.value = ?;",
|
44
|
+
]
|
45
|
+
allow(cmd).to receive(:execute).with(q.join(" "), ["foo", "foo", "foo"]) {
|
46
|
+
[[1], [2], [3]]
|
47
|
+
}
|
48
|
+
expect(expr.evaluate(cmd)).to eq([1, 2, 3])
|
49
|
+
end
|
50
|
+
|
51
|
+
it "interprets tag with attribute" do
|
52
|
+
expr = Hotdog::Commands::Search::TagExpressionNode.new(nil, "foo")
|
53
|
+
q = [
|
54
|
+
"SELECT DISTINCT hosts_tags.host_id FROM hosts_tags",
|
55
|
+
"INNER JOIN tags ON hosts_tags.tag_id = tags.id",
|
56
|
+
"WHERE tags.value = ?;",
|
57
|
+
]
|
58
|
+
allow(cmd).to receive(:execute).with(q.join(" "), ["foo"]) {
|
59
|
+
[[1], [2], [3]]
|
60
|
+
}
|
61
|
+
expect(expr.evaluate(cmd)).to eq([1, 2, 3])
|
62
|
+
end
|
63
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
require "hotdog/application"
|
3
|
+
require "hotdog/commands"
|
4
|
+
require "hotdog/commands/search"
|
5
|
+
require "parslet"
|
6
|
+
|
7
|
+
describe "tag glob expression" do
|
8
|
+
let(:cmd) {
|
9
|
+
Hotdog::Commands::Search.new(Hotdog::Application.new)
|
10
|
+
}
|
11
|
+
|
12
|
+
it "interprets tag glob with host" do
|
13
|
+
expr = Hotdog::Commands::Search::TagGlobExpressionNode.new("host", "foo*")
|
14
|
+
q = [
|
15
|
+
"SELECT hosts.id FROM hosts",
|
16
|
+
"WHERE hosts.name GLOB ?;",
|
17
|
+
]
|
18
|
+
allow(cmd).to receive(:execute).with(q.join(" "), ["foo*"]) {
|
19
|
+
[[1], [2], [3]]
|
20
|
+
}
|
21
|
+
expect(expr.evaluate(cmd)).to eq([1, 2, 3])
|
22
|
+
end
|
23
|
+
|
24
|
+
it "interprets tag glob with identifier and attribute" do
|
25
|
+
expr = Hotdog::Commands::Search::TagGlobExpressionNode.new("foo*", "bar*")
|
26
|
+
q = [
|
27
|
+
"SELECT DISTINCT hosts_tags.host_id FROM hosts_tags",
|
28
|
+
"INNER JOIN tags ON hosts_tags.tag_id = tags.id",
|
29
|
+
"WHERE tags.name GLOB ? AND tags.value GLOB ?;",
|
30
|
+
]
|
31
|
+
allow(cmd).to receive(:execute).with(q.join(" "), ["foo*", "bar*"]) {
|
32
|
+
[[1], [2], [3]]
|
33
|
+
}
|
34
|
+
expect(expr.evaluate(cmd)).to eq([1, 2, 3])
|
35
|
+
end
|
36
|
+
|
37
|
+
it "interprets tag glob with identifier" do
|
38
|
+
expr = Hotdog::Commands::Search::TagGlobExpressionNode.new("foo*", nil)
|
39
|
+
q = [
|
40
|
+
"SELECT DISTINCT hosts_tags.host_id FROM hosts_tags",
|
41
|
+
"INNER JOIN hosts ON hosts_tags.host_id = hosts.id",
|
42
|
+
"INNER JOIN tags ON hosts_tags.tag_id = tags.id",
|
43
|
+
"WHERE hosts.name GLOB ? OR tags.name GLOB ? OR tags.value GLOB ?;",
|
44
|
+
]
|
45
|
+
allow(cmd).to receive(:execute).with(q.join(" "), ["foo*", "foo*", "foo*"]) {
|
46
|
+
[[1], [2], [3]]
|
47
|
+
}
|
48
|
+
expect(expr.evaluate(cmd)).to eq([1, 2, 3])
|
49
|
+
end
|
50
|
+
|
51
|
+
it "interprets tag glob with attribute" do
|
52
|
+
expr = Hotdog::Commands::Search::TagGlobExpressionNode.new(nil, "foo*")
|
53
|
+
q = [
|
54
|
+
"SELECT DISTINCT hosts_tags.host_id FROM hosts_tags",
|
55
|
+
"INNER JOIN tags ON hosts_tags.tag_id = tags.id",
|
56
|
+
"WHERE tags.value GLOB ?;",
|
57
|
+
]
|
58
|
+
allow(cmd).to receive(:execute).with(q.join(" "), ["foo*"]) {
|
59
|
+
[[1], [2], [3]]
|
60
|
+
}
|
61
|
+
expect(expr.evaluate(cmd)).to eq([1, 2, 3])
|
62
|
+
end
|
63
|
+
end
|