hotdog 0.26.0 → 0.27.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,3 @@
1
1
  module Hotdog
2
- VERSION = "0.26.0"
2
+ VERSION = "0.27.0"
3
3
  end
@@ -24,6 +24,9 @@ describe "commands" do
24
24
  cmd.options[:listing] = false
25
25
  cmd.options[:primary_tag] = nil
26
26
  allow(cmd).to receive(:update_db)
27
+ allow(cmd).to receive(:execute).with("SELECT id FROM hosts WHERE status = ? AND id IN (?, ?, ?);", [Hotdog::STATUS_RUNNING, 1, 2, 3]) {
28
+ [[1], [2], [3]]
29
+ }
27
30
  allow(cmd).to receive(:get_hosts_fields).with([1, 2, 3], ["host"])
28
31
  expect(cmd.__send__(:get_hosts, [1, 2, 3], []))
29
32
  end
@@ -32,6 +35,9 @@ describe "commands" do
32
35
  cmd.options[:listing] = false
33
36
  cmd.options[:primary_tag] = "foo"
34
37
  allow(cmd).to receive(:update_db)
38
+ allow(cmd).to receive(:execute).with("SELECT id FROM hosts WHERE status = ? AND id IN (?, ?, ?);", [Hotdog::STATUS_RUNNING, 1, 2, 3]) {
39
+ [[1], [2], [3]]
40
+ }
35
41
  allow(cmd).to receive(:get_hosts_fields).with([1, 2, 3], ["foo"])
36
42
  expect(cmd.__send__(:get_hosts, [1, 2, 3], []))
37
43
  end
@@ -40,6 +46,9 @@ describe "commands" do
40
46
  cmd.options[:listing] = false
41
47
  cmd.options[:primary_tag] = nil
42
48
  allow(cmd).to receive(:update_db)
49
+ allow(cmd).to receive(:execute).with("SELECT id FROM hosts WHERE status = ? AND id IN (?, ?, ?);", [Hotdog::STATUS_RUNNING, 1, 2, 3]) {
50
+ [[1], [2], [3]]
51
+ }
43
52
  allow(cmd).to receive(:get_hosts_fields).with([1, 2, 3], ["foo", "bar", "baz"])
44
53
  expect(cmd.__send__(:get_hosts, [1, 2, 3], ["foo", "bar", "baz"]))
45
54
  end
@@ -48,6 +57,9 @@ describe "commands" do
48
57
  cmd.options[:listing] = true
49
58
  cmd.options[:primary_tag] = nil
50
59
  allow(cmd).to receive(:update_db)
60
+ allow(cmd).to receive(:execute).with("SELECT id FROM hosts WHERE status = ? AND id IN (?, ?, ?);", [Hotdog::STATUS_RUNNING, 1, 2, 3]) {
61
+ [[1], [2], [3]]
62
+ }
51
63
  q1 = [
52
64
  "SELECT DISTINCT tags.name FROM hosts_tags",
53
65
  "INNER JOIN tags ON hosts_tags.tag_id = tags.id",
@@ -64,6 +76,9 @@ describe "commands" do
64
76
  cmd.options[:listing] = true
65
77
  cmd.options[:primary_tag] = "bar"
66
78
  allow(cmd).to receive(:update_db)
79
+ allow(cmd).to receive(:execute).with("SELECT id FROM hosts WHERE status = ? AND id IN (?, ?, ?);", [Hotdog::STATUS_RUNNING, 1, 2, 3]) {
80
+ [[1], [2], [3]]
81
+ }
67
82
  q1 = [
68
83
  "SELECT DISTINCT tags.name FROM hosts_tags",
69
84
  "INNER JOIN tags ON hosts_tags.tag_id = tags.id",
@@ -81,6 +96,9 @@ describe "commands" do
81
96
  end
82
97
 
83
98
  it "get host fields without host" do
99
+ allow(cmd).to receive(:execute).with("SELECT id FROM hosts WHERE status = ? AND id IN (?, ?, ?);", [Hotdog::STATUS_RUNNING, 1, 2, 3]) {
100
+ [[1], [2], [3]]
101
+ }
84
102
  q1 = [
85
103
  "SELECT LOWER(tags.name), GROUP_CONCAT(tags.value, ',') FROM hosts_tags",
86
104
  "INNER JOIN tags ON hosts_tags.tag_id = tags.id",
@@ -100,6 +118,9 @@ describe "commands" do
100
118
  end
101
119
 
102
120
  it "get host fields with host" do
121
+ allow(cmd).to receive(:execute).with("SELECT id FROM hosts WHERE status = ? AND id IN (?, ?, ?);", [Hotdog::STATUS_RUNNING, 1, 2, 3]) {
122
+ [[1], [2], [3]]
123
+ }
103
124
  q1 = [
104
125
  "SELECT LOWER(tags.name), GROUP_CONCAT(tags.value, ',') FROM hosts_tags",
105
126
  "INNER JOIN tags ON hosts_tags.tag_id = tags.id",
@@ -5,43 +5,45 @@ require "hotdog/commands/search"
5
5
  require "parslet"
6
6
 
7
7
  describe "binary expression" do
8
- it "everything AND x should return x" do
9
- expr = Hotdog::Expression::BinaryExpressionNode.new("AND", Hotdog::Expression::EverythingNode.new(), Hotdog::Expression::NothingNode.new())
10
- expect(expr.optimize.dump).to eq({
11
- query: "SELECT NULL AS host_id WHERE host_id NOT NULL;",
12
- values: [],
13
- })
14
- end
8
+ 3.times do |o|
9
+ it "everything AND x should return x (#{o})" do
10
+ expr = Hotdog::Expression::BinaryExpressionNode.new("AND", Hotdog::Expression::EverythingNode.new(), Hotdog::Expression::NothingNode.new())
11
+ expect(optimize_n(o+1, expr).dump).to eq({
12
+ query: "SELECT NULL AS host_id WHERE host_id NOT NULL;",
13
+ values: [],
14
+ })
15
+ end
15
16
 
16
- it "nothing AND x should return nothing" do
17
- expr = Hotdog::Expression::BinaryExpressionNode.new("AND", Hotdog::Expression::NothingNode.new(), Hotdog::Expression::EverythingNode.new())
18
- expect(expr.optimize.dump).to eq({
19
- query: "SELECT NULL AS host_id WHERE host_id NOT NULL;",
20
- values: [],
21
- })
22
- end
17
+ it "nothing AND x should return nothing (#{o})" do
18
+ expr = Hotdog::Expression::BinaryExpressionNode.new("AND", Hotdog::Expression::NothingNode.new(), Hotdog::Expression::EverythingNode.new())
19
+ expect(optimize_n(o+1, expr).dump).to eq({
20
+ query: "SELECT NULL AS host_id WHERE host_id NOT NULL;",
21
+ values: [],
22
+ })
23
+ end
23
24
 
24
- it "everything OR x should return everything" do
25
- expr = Hotdog::Expression::BinaryExpressionNode.new("OR", Hotdog::Expression::EverythingNode.new(), Hotdog::Expression::NothingNode.new())
26
- expect(expr.optimize.dump).to eq({
27
- query: "SELECT id AS host_id FROM hosts;",
28
- values: [],
29
- })
30
- end
25
+ it "everything OR x should return everything (#{o})" do
26
+ expr = Hotdog::Expression::BinaryExpressionNode.new("OR", Hotdog::Expression::EverythingNode.new(), Hotdog::Expression::NothingNode.new())
27
+ expect(optimize_n(o+1, expr).dump).to eq({
28
+ query: "SELECT id AS host_id FROM hosts;",
29
+ values: [],
30
+ })
31
+ end
31
32
 
32
- it "nothing OR x should return x" do
33
- expr = Hotdog::Expression::BinaryExpressionNode.new("OR", Hotdog::Expression::NothingNode.new(), Hotdog::Expression::EverythingNode.new())
34
- expect(expr.optimize.dump).to eq({
35
- query: "SELECT id AS host_id FROM hosts;",
36
- values: [],
37
- })
38
- end
33
+ it "nothing OR x should return x (#{o})" do
34
+ expr = Hotdog::Expression::BinaryExpressionNode.new("OR", Hotdog::Expression::NothingNode.new(), Hotdog::Expression::EverythingNode.new())
35
+ expect(optimize_n(o+1, expr).dump).to eq({
36
+ query: "SELECT id AS host_id FROM hosts;",
37
+ values: [],
38
+ })
39
+ end
39
40
 
40
- it "everything XOR everything should return nothing" do
41
- expr = Hotdog::Expression::BinaryExpressionNode.new("XOR", Hotdog::Expression::EverythingNode.new(), Hotdog::Expression::EverythingNode.new())
42
- expect(expr.optimize.dump).to eq({
43
- query: "SELECT NULL AS host_id WHERE host_id NOT NULL;",
44
- values: [],
45
- })
41
+ it "everything XOR everything should return nothing (#{o})" do
42
+ expr = Hotdog::Expression::BinaryExpressionNode.new("XOR", Hotdog::Expression::EverythingNode.new(), Hotdog::Expression::EverythingNode.new())
43
+ expect(optimize_n(o+1, expr).dump).to eq({
44
+ query: "SELECT NULL AS host_id WHERE host_id NOT NULL;",
45
+ values: [],
46
+ })
47
+ end
46
48
  end
47
49
  end
@@ -5,101 +5,103 @@ require "hotdog/commands/search"
5
5
  require "parslet"
6
6
 
7
7
  describe "tag glob expression" do
8
- it "interprets tag glob with host" do
9
- expr = Hotdog::Expression::GlobHostNode.new("foo*", ":")
10
- expect(expr.optimize.dump).to eq({
11
- tagname_glob: "host",
12
- separator: ":",
13
- tagvalue_glob: "foo*",
14
- fallback: {
15
- query: [
16
- "SELECT hosts.id AS host_id FROM hosts",
17
- "WHERE LOWER(hosts.name) GLOB LOWER(?);",
18
- ].join(" "),
19
- values: ["*foo*"],
20
- },
21
- })
22
- end
8
+ 3.times do |o|
9
+ it "interprets tag glob with host (#{o})" do
10
+ expr = Hotdog::Expression::GlobHostNode.new("foo*", ":")
11
+ expect(optimize_n(o+1, expr).dump).to eq({
12
+ tagname_glob: "host",
13
+ separator: ":",
14
+ tagvalue_glob: "foo*",
15
+ fallback: {
16
+ query: [
17
+ "SELECT hosts.id AS host_id FROM hosts",
18
+ "WHERE LOWER(hosts.name) GLOB LOWER(?);",
19
+ ].join(" "),
20
+ values: ["*foo*"],
21
+ },
22
+ })
23
+ end
23
24
 
24
- it "interprets tag glob with tagname and tagvalue" do
25
- expr = Hotdog::Expression::GlobTagNode.new("foo*", "bar*", ":")
26
- expect(expr.optimize.dump).to eq({
27
- tagname_glob: "foo*",
28
- separator: ":",
29
- tagvalue_glob: "bar*",
30
- fallback: {
31
- query: [
32
- "SELECT DISTINCT hosts_tags.host_id FROM hosts_tags",
33
- "INNER JOIN tags ON hosts_tags.tag_id = tags.id",
34
- "WHERE LOWER(tags.name) GLOB LOWER(?) AND LOWER(tags.value) GLOB LOWER(?);",
35
- ].join(" "),
36
- values: ["*foo*", "*bar*"],
37
- },
38
- })
39
- end
25
+ it "interprets tag glob with tagname and tagvalue (#{o})" do
26
+ expr = Hotdog::Expression::GlobTagNode.new("foo*", "bar*", ":")
27
+ expect(optimize_n(o+1, expr).dump).to eq({
28
+ tagname_glob: "foo*",
29
+ separator: ":",
30
+ tagvalue_glob: "bar*",
31
+ fallback: {
32
+ query: [
33
+ "SELECT DISTINCT hosts_tags.host_id FROM hosts_tags",
34
+ "INNER JOIN tags ON hosts_tags.tag_id = tags.id",
35
+ "WHERE LOWER(tags.name) GLOB LOWER(?) AND LOWER(tags.value) GLOB LOWER(?);",
36
+ ].join(" "),
37
+ values: ["*foo*", "*bar*"],
38
+ },
39
+ })
40
+ end
40
41
 
41
- it "interprets tag glob with tagname with separator" do
42
- expr = Hotdog::Expression::GlobTagnameNode.new("foo*", ":")
43
- expect(expr.optimize.dump).to eq({
44
- tagname_glob: "foo*",
45
- separator: ":",
46
- fallback: {
47
- query: [
48
- "SELECT DISTINCT hosts_tags.host_id FROM hosts_tags",
49
- "INNER JOIN tags ON hosts_tags.tag_id = tags.id",
50
- "WHERE LOWER(tags.name) GLOB LOWER(?);",
51
- ].join(" "),
52
- values: ["*foo*"],
53
- },
54
- })
55
- end
42
+ it "interprets tag glob with tagname with separator (#{o})" do
43
+ expr = Hotdog::Expression::GlobTagnameNode.new("foo*", ":")
44
+ expect(optimize_n(o+1, expr).dump).to eq({
45
+ tagname_glob: "foo*",
46
+ separator: ":",
47
+ fallback: {
48
+ query: [
49
+ "SELECT DISTINCT hosts_tags.host_id FROM hosts_tags",
50
+ "INNER JOIN tags ON hosts_tags.tag_id = tags.id",
51
+ "WHERE LOWER(tags.name) GLOB LOWER(?);",
52
+ ].join(" "),
53
+ values: ["*foo*"],
54
+ },
55
+ })
56
+ end
56
57
 
57
- it "interprets tag glob with tagname without separator" do
58
- expr = Hotdog::Expression::GlobHostOrTagNode.new("foo*", nil)
59
- expect(expr.optimize.dump).to eq({
60
- tagname_glob: "foo*",
61
- fallback: {
62
- query: [
63
- "SELECT DISTINCT hosts_tags.host_id FROM hosts_tags",
64
- "INNER JOIN hosts ON hosts_tags.host_id = hosts.id",
65
- "INNER JOIN tags ON hosts_tags.tag_id = tags.id",
66
- "WHERE LOWER(hosts.name) GLOB LOWER(?) OR LOWER(tags.name) GLOB LOWER(?) OR LOWER(tags.value) GLOB LOWER(?);",
67
- ].join(" "),
68
- values: ["*foo*", "*foo*", "*foo*"],
69
- },
70
- })
71
- end
58
+ it "interprets tag glob with tagname without separator (#{o})" do
59
+ expr = Hotdog::Expression::GlobHostOrTagNode.new("foo*", nil)
60
+ expect(optimize_n(o+1, expr).dump).to eq({
61
+ tagname_glob: "foo*",
62
+ fallback: {
63
+ query: [
64
+ "SELECT DISTINCT hosts_tags.host_id FROM hosts_tags",
65
+ "INNER JOIN hosts ON hosts_tags.host_id = hosts.id",
66
+ "INNER JOIN tags ON hosts_tags.tag_id = tags.id",
67
+ "WHERE LOWER(hosts.name) GLOB LOWER(?) OR LOWER(tags.name) GLOB LOWER(?) OR LOWER(tags.value) GLOB LOWER(?);",
68
+ ].join(" "),
69
+ values: ["*foo*", "*foo*", "*foo*"],
70
+ },
71
+ })
72
+ end
72
73
 
73
- it "interprets tag glob with tagvalue with separator" do
74
- expr = Hotdog::Expression::GlobTagvalueNode.new("foo*", ":")
75
- expect(expr.optimize.dump).to eq({
76
- separator: ":",
77
- tagvalue_glob: "foo*",
78
- fallback: {
79
- query: [
80
- "SELECT DISTINCT hosts_tags.host_id FROM hosts_tags",
81
- "INNER JOIN hosts ON hosts_tags.host_id = hosts.id",
82
- "INNER JOIN tags ON hosts_tags.tag_id = tags.id",
83
- "WHERE LOWER(hosts.name) GLOB LOWER(?) OR LOWER(tags.value) GLOB LOWER(?);",
84
- ].join(" "),
85
- values: ["*foo*", "*foo*"],
86
- },
87
- })
88
- end
74
+ it "interprets tag glob with tagvalue with separator (#{o})" do
75
+ expr = Hotdog::Expression::GlobTagvalueNode.new("foo*", ":")
76
+ expect(optimize_n(o+1, expr).dump).to eq({
77
+ separator: ":",
78
+ tagvalue_glob: "foo*",
79
+ fallback: {
80
+ query: [
81
+ "SELECT DISTINCT hosts_tags.host_id FROM hosts_tags",
82
+ "INNER JOIN hosts ON hosts_tags.host_id = hosts.id",
83
+ "INNER JOIN tags ON hosts_tags.tag_id = tags.id",
84
+ "WHERE LOWER(hosts.name) GLOB LOWER(?) OR LOWER(tags.value) GLOB LOWER(?);",
85
+ ].join(" "),
86
+ values: ["*foo*", "*foo*"],
87
+ },
88
+ })
89
+ end
89
90
 
90
- it "interprets tag glob with tagvalue without separator" do
91
- expr = Hotdog::Expression::GlobTagvalueNode.new("foo*", nil)
92
- expect(expr.optimize.dump).to eq({
93
- tagvalue_glob: "foo*",
94
- fallback: {
95
- query: [
96
- "SELECT DISTINCT hosts_tags.host_id FROM hosts_tags",
97
- "INNER JOIN hosts ON hosts_tags.host_id = hosts.id",
98
- "INNER JOIN tags ON hosts_tags.tag_id = tags.id",
99
- "WHERE LOWER(hosts.name) GLOB LOWER(?) OR LOWER(tags.value) GLOB LOWER(?);",
100
- ].join(" "),
101
- values: ["*foo*", "*foo*"],
102
- }
103
- })
91
+ it "interprets tag glob with tagvalue without separator (#{o})" do
92
+ expr = Hotdog::Expression::GlobTagvalueNode.new("foo*", nil)
93
+ expect(optimize_n(o+1, expr).dump).to eq({
94
+ tagvalue_glob: "foo*",
95
+ fallback: {
96
+ query: [
97
+ "SELECT DISTINCT hosts_tags.host_id FROM hosts_tags",
98
+ "INNER JOIN hosts ON hosts_tags.host_id = hosts.id",
99
+ "INNER JOIN tags ON hosts_tags.tag_id = tags.id",
100
+ "WHERE LOWER(hosts.name) GLOB LOWER(?) OR LOWER(tags.value) GLOB LOWER(?);",
101
+ ].join(" "),
102
+ values: ["*foo*", "*foo*"],
103
+ }
104
+ })
105
+ end
104
106
  end
105
107
  end
@@ -5,51 +5,53 @@ require "hotdog/commands/search"
5
5
  require "parslet"
6
6
 
7
7
  describe "tag regexp expression" do
8
- it "interprets tag regexp with host" do
9
- expr = Hotdog::Expression::RegexpHostNode.new("foo", ":")
10
- expect(expr.optimize.dump).to eq({
11
- tagname_regexp: "host",
12
- separator: ":",
13
- tagvalue_regexp: "foo",
14
- })
15
- end
8
+ 3.times do |o|
9
+ it "interprets tag regexp with host (#{o})" do
10
+ expr = Hotdog::Expression::RegexpHostNode.new("foo", ":")
11
+ expect(optimize_n(o+1, expr).dump).to eq({
12
+ tagname_regexp: "host",
13
+ separator: ":",
14
+ tagvalue_regexp: "foo",
15
+ })
16
+ end
16
17
 
17
- it "interprets tag regexp with tagname and tagvalue" do
18
- expr = Hotdog::Expression::RegexpTagNode.new("foo", "bar", ":")
19
- expect(expr.optimize.dump).to eq({
20
- tagname_regexp: "foo",
21
- separator: ":",
22
- tagvalue_regexp: "bar",
23
- })
24
- end
18
+ it "interprets tag regexp with tagname and tagvalue (#{o})" do
19
+ expr = Hotdog::Expression::RegexpTagNode.new("foo", "bar", ":")
20
+ expect(optimize_n(o+1, expr).dump).to eq({
21
+ tagname_regexp: "foo",
22
+ separator: ":",
23
+ tagvalue_regexp: "bar",
24
+ })
25
+ end
25
26
 
26
- it "interprets tag regexp with tagname with separator" do
27
- expr = Hotdog::Expression::RegexpTagnameNode.new("foo", ":")
28
- expect(expr.optimize.dump).to eq({
29
- tagname_regexp: "foo",
30
- separator: ":",
31
- })
32
- end
27
+ it "interprets tag regexp with tagname with separator (#{o})" do
28
+ expr = Hotdog::Expression::RegexpTagnameNode.new("foo", ":")
29
+ expect(optimize_n(o+1, expr).dump).to eq({
30
+ tagname_regexp: "foo",
31
+ separator: ":",
32
+ })
33
+ end
33
34
 
34
- it "interprets tag regexp with tagname without separator" do
35
- expr = Hotdog::Expression::RegexpHostOrTagNode.new("foo", nil)
36
- expect(expr.optimize.dump).to eq({
37
- tagname_regexp: "foo",
38
- })
39
- end
35
+ it "interprets tag regexp with tagname without separator (#{o})" do
36
+ expr = Hotdog::Expression::RegexpHostOrTagNode.new("foo", nil)
37
+ expect(optimize_n(o+1, expr).dump).to eq({
38
+ tagname_regexp: "foo",
39
+ })
40
+ end
40
41
 
41
- it "interprets tag regexp with tagvalue with separator" do
42
- expr = Hotdog::Expression::RegexpTagvalueNode.new("foo", ":")
43
- expect(expr.optimize.dump).to eq({
44
- separator: ":",
45
- tagvalue_regexp: "foo",
46
- })
47
- end
42
+ it "interprets tag regexp with tagvalue with separator (#{o})" do
43
+ expr = Hotdog::Expression::RegexpTagvalueNode.new("foo", ":")
44
+ expect(optimize_n(o+1, expr).dump).to eq({
45
+ separator: ":",
46
+ tagvalue_regexp: "foo",
47
+ })
48
+ end
48
49
 
49
- it "interprets tag regexp with tagvalue without separator" do
50
- expr = Hotdog::Expression::RegexpTagvalueNode.new("foo", nil)
51
- expect(expr.optimize.dump).to eq({
52
- tagvalue_regexp: "foo",
53
- })
50
+ it "interprets tag regexp with tagvalue without separator (#{o})" do
51
+ expr = Hotdog::Expression::RegexpTagvalueNode.new("foo", nil)
52
+ expect(optimize_n(o+1, expr).dump).to eq({
53
+ tagvalue_regexp: "foo",
54
+ })
55
+ end
54
56
  end
55
57
  end
@@ -5,101 +5,103 @@ require "hotdog/commands/search"
5
5
  require "parslet"
6
6
 
7
7
  describe "tag expression" do
8
- it "interprets tag with host" do
9
- expr = Hotdog::Expression::StringHostNode.new("foo", ":")
10
- expect(expr.optimize.dump).to eq({
11
- tagname: "host",
12
- separator: ":",
13
- tagvalue: "foo",
14
- fallback: {
15
- query: [
16
- "SELECT hosts.id AS host_id FROM hosts",
17
- "WHERE LOWER(hosts.name) GLOB LOWER(?);",
18
- ].join(" "),
19
- values: ["*foo*"],
20
- },
21
- })
22
- end
8
+ 3.times do |o|
9
+ it "interprets tag with host (#{o})" do
10
+ expr = Hotdog::Expression::StringHostNode.new("foo", ":")
11
+ expect(optimize_n(o+1, expr).dump).to eq({
12
+ tagname: "host",
13
+ separator: ":",
14
+ tagvalue: "foo",
15
+ fallback: {
16
+ query: [
17
+ "SELECT hosts.id AS host_id FROM hosts",
18
+ "WHERE LOWER(hosts.name) GLOB LOWER(?);",
19
+ ].join(" "),
20
+ values: ["*foo*"],
21
+ },
22
+ })
23
+ end
23
24
 
24
- it "interprets tag with tagname and tagvalue" do
25
- expr = Hotdog::Expression::StringTagNode.new("foo", "bar", ":")
26
- expect(expr.optimize.dump).to eq({
27
- tagname: "foo",
28
- separator: ":",
29
- tagvalue: "bar",
30
- fallback: {
31
- query: [
32
- "SELECT DISTINCT hosts_tags.host_id FROM hosts_tags",
33
- "INNER JOIN tags ON hosts_tags.tag_id = tags.id",
34
- "WHERE LOWER(tags.name) GLOB LOWER(?) AND LOWER(tags.value) GLOB LOWER(?);",
35
- ].join(" "),
36
- values: ["*foo*", "*bar*"],
37
- },
38
- })
39
- end
25
+ it "interprets tag with tagname and tagvalue (#{o})" do
26
+ expr = Hotdog::Expression::StringTagNode.new("foo", "bar", ":")
27
+ expect(optimize_n(o+1, expr).dump).to eq({
28
+ tagname: "foo",
29
+ separator: ":",
30
+ tagvalue: "bar",
31
+ fallback: {
32
+ query: [
33
+ "SELECT DISTINCT hosts_tags.host_id FROM hosts_tags",
34
+ "INNER JOIN tags ON hosts_tags.tag_id = tags.id",
35
+ "WHERE LOWER(tags.name) GLOB LOWER(?) AND LOWER(tags.value) GLOB LOWER(?);",
36
+ ].join(" "),
37
+ values: ["*foo*", "*bar*"],
38
+ },
39
+ })
40
+ end
40
41
 
41
- it "interprets tag with tagname with separator" do
42
- expr = Hotdog::Expression::StringTagnameNode.new("foo", ":")
43
- expect(expr.optimize.dump).to eq({
44
- tagname: "foo",
45
- separator: ":",
46
- fallback: {
47
- query: [
48
- "SELECT DISTINCT hosts_tags.host_id FROM hosts_tags",
49
- "INNER JOIN tags ON hosts_tags.tag_id = tags.id",
50
- "WHERE LOWER(tags.name) GLOB LOWER(?);",
51
- ].join(" "),
52
- values: ["*foo*"],
53
- }
54
- })
55
- end
42
+ it "interprets tag with tagname with separator (#{o})" do
43
+ expr = Hotdog::Expression::StringTagnameNode.new("foo", ":")
44
+ expect(optimize_n(o+1, expr).dump).to eq({
45
+ tagname: "foo",
46
+ separator: ":",
47
+ fallback: {
48
+ query: [
49
+ "SELECT DISTINCT hosts_tags.host_id FROM hosts_tags",
50
+ "INNER JOIN tags ON hosts_tags.tag_id = tags.id",
51
+ "WHERE LOWER(tags.name) GLOB LOWER(?);",
52
+ ].join(" "),
53
+ values: ["*foo*"],
54
+ }
55
+ })
56
+ end
56
57
 
57
- it "interprets tag with tagname without separator" do
58
- expr = Hotdog::Expression::StringHostOrTagNode.new("foo", nil)
59
- expect(expr.optimize.dump).to eq({
60
- tagname: "foo",
61
- fallback: {
62
- query: [
63
- "SELECT DISTINCT hosts_tags.host_id FROM hosts_tags",
64
- "INNER JOIN hosts ON hosts_tags.host_id = hosts.id",
65
- "INNER JOIN tags ON hosts_tags.tag_id = tags.id",
66
- "WHERE LOWER(hosts.name) GLOB LOWER(?) OR LOWER(tags.name) GLOB LOWER(?) OR LOWER(tags.value) GLOB LOWER(?);",
67
- ].join(" "),
68
- values: ["*foo*", "*foo*", "*foo*"],
69
- },
70
- })
71
- end
58
+ it "interprets tag with tagname without separator (#{o})" do
59
+ expr = Hotdog::Expression::StringHostOrTagNode.new("foo", nil)
60
+ expect(optimize_n(o+1, expr).dump).to eq({
61
+ tagname: "foo",
62
+ fallback: {
63
+ query: [
64
+ "SELECT DISTINCT hosts_tags.host_id FROM hosts_tags",
65
+ "INNER JOIN hosts ON hosts_tags.host_id = hosts.id",
66
+ "INNER JOIN tags ON hosts_tags.tag_id = tags.id",
67
+ "WHERE LOWER(hosts.name) GLOB LOWER(?) OR LOWER(tags.name) GLOB LOWER(?) OR LOWER(tags.value) GLOB LOWER(?);",
68
+ ].join(" "),
69
+ values: ["*foo*", "*foo*", "*foo*"],
70
+ },
71
+ })
72
+ end
72
73
 
73
- it "interprets tag with tagvalue with separator" do
74
- expr = Hotdog::Expression::StringTagvalueNode.new("foo", ":")
75
- expect(expr.optimize.dump).to eq({
76
- tagvalue: "foo",
77
- separator: ":",
78
- fallback: {
79
- query: [
80
- "SELECT DISTINCT hosts_tags.host_id FROM hosts_tags",
81
- "INNER JOIN hosts ON hosts_tags.host_id = hosts.id",
82
- "INNER JOIN tags ON hosts_tags.tag_id = tags.id",
83
- "WHERE LOWER(hosts.name) GLOB LOWER(?) OR LOWER(tags.value) GLOB LOWER(?);",
84
- ].join(" "),
85
- values: ["*foo*", "*foo*"],
86
- },
87
- })
88
- end
74
+ it "interprets tag with tagvalue with separator (#{o})" do
75
+ expr = Hotdog::Expression::StringTagvalueNode.new("foo", ":")
76
+ expect(optimize_n(o+1, expr).dump).to eq({
77
+ tagvalue: "foo",
78
+ separator: ":",
79
+ fallback: {
80
+ query: [
81
+ "SELECT DISTINCT hosts_tags.host_id FROM hosts_tags",
82
+ "INNER JOIN hosts ON hosts_tags.host_id = hosts.id",
83
+ "INNER JOIN tags ON hosts_tags.tag_id = tags.id",
84
+ "WHERE LOWER(hosts.name) GLOB LOWER(?) OR LOWER(tags.value) GLOB LOWER(?);",
85
+ ].join(" "),
86
+ values: ["*foo*", "*foo*"],
87
+ },
88
+ })
89
+ end
89
90
 
90
- it "interprets tag with tagvalue without separator" do
91
- expr = Hotdog::Expression::StringTagvalueNode.new("foo", nil)
92
- expect(expr.optimize.dump).to eq({
93
- tagvalue: "foo",
94
- fallback: {
95
- query: [
96
- "SELECT DISTINCT hosts_tags.host_id FROM hosts_tags",
97
- "INNER JOIN hosts ON hosts_tags.host_id = hosts.id",
98
- "INNER JOIN tags ON hosts_tags.tag_id = tags.id",
99
- "WHERE LOWER(hosts.name) GLOB LOWER(?) OR LOWER(tags.value) GLOB LOWER(?);",
100
- ].join(" "),
101
- values: ["*foo*", "*foo*"],
102
- },
103
- })
91
+ it "interprets tag with tagvalue without separator (#{o})" do
92
+ expr = Hotdog::Expression::StringTagvalueNode.new("foo", nil)
93
+ expect(optimize_n(o+1, expr).dump).to eq({
94
+ tagvalue: "foo",
95
+ fallback: {
96
+ query: [
97
+ "SELECT DISTINCT hosts_tags.host_id FROM hosts_tags",
98
+ "INNER JOIN hosts ON hosts_tags.host_id = hosts.id",
99
+ "INNER JOIN tags ON hosts_tags.tag_id = tags.id",
100
+ "WHERE LOWER(hosts.name) GLOB LOWER(?) OR LOWER(tags.value) GLOB LOWER(?);",
101
+ ].join(" "),
102
+ values: ["*foo*", "*foo*"],
103
+ },
104
+ })
105
+ end
104
106
  end
105
107
  end