Module: SearchDbTests

Included in:
TestExplicitSearchDB, TestImplicitSearchDB
Defined in:
lib/knife-solo/resources/patch_cookbooks/chef-solo-search/tests/test_search.rb

Instance Method Summary collapse

Instance Method Details

#test_AND_conditionObject



93
94
95
96
97
# File 'lib/knife-solo/resources/patch_cookbooks/chef-solo-search/tests/test_search.rb', line 93

def test_AND_condition
  nodes = search(:users, "married:true AND age:35")
  assert nodes.length == 1
  assert nodes[0]["username"] == "lea"
end

#test_any_valueObject



113
114
115
116
# File 'lib/knife-solo/resources/patch_cookbooks/chef-solo-search/tests/test_search.rb', line 113

def test_any_value
  nodes = search(:users, "children:*")
  assert nodes.length == 2
end

#test_any_value_lucene_rangeObject



118
119
120
121
# File 'lib/knife-solo/resources/patch_cookbooks/chef-solo-search/tests/test_search.rb', line 118

def test_any_value_lucene_range
  nodes = search(:users, "address:[* TO *]")
  assert nodes.length == 2
end

#test_array_includesObject



69
70
71
72
73
74
75
76
# File 'lib/knife-solo/resources/patch_cookbooks/chef-solo-search/tests/test_search.rb', line 69

def test_array_includes
  nodes = search(:users, "children:tom")
  assert nodes.length == 2
  assert nodes.all?{ |x| x["children"].include?("tom") }
  nodes = search(:users, "children:jerry")
  assert nodes.length == 1
  assert nodes.all?{ |x| x["children"].include?("jerry") }
end

#test_block_usageObject



129
130
131
132
133
134
135
136
137
138
139
140
141
# File 'lib/knife-solo/resources/patch_cookbooks/chef-solo-search/tests/test_search.rb', line 129

def test_block_usage
  # bracket syntax
  result = []
  search(:users, "*:*") {|x| result << x["id"]}
  assert result.length == 4
  
  # do...end syntax
  result = []
  search(:users) do |x|
    result << x["id"]
  end
  assert result.length == 4
end

#test_booleanObject



78
79
80
81
82
83
84
85
# File 'lib/knife-solo/resources/patch_cookbooks/chef-solo-search/tests/test_search.rb', line 78

def test_boolean
  nodes = search(:users, "married:true")
  assert nodes.length == 3
  assert nodes.all?{ |x| x["married"] == true }
  nodes = search(:users, "married:false")
  assert nodes.length == 1
  assert nodes[0]["married"] == false
end

#test_check_escaped_charsObject



143
144
145
146
147
148
149
150
151
152
153
154
155
156
# File 'lib/knife-solo/resources/patch_cookbooks/chef-solo-search/tests/test_search.rb', line 143

def test_check_escaped_chars
  nodes = search(:users, 'tag:tag\:\:test')
  assert nodes.length == 1
  nodes = search(:users, "tag:tag\\:\\:test")
  assert nodes.length == 1
  nodes = search(:users, 'tags:tag\:\:first')
  assert nodes.length == 1
  nodes = search(:users, "tags:tag\\:\\:first")
  assert nodes.length == 1
  nodes = search(:users, 'tags:tag\:\:*')
  assert nodes.length == 1
  nodes = search(:users, "tags:tag\\:\\:*")
  assert nodes.length == 1
end

#test_empty_field_valueObject



167
168
169
170
171
172
173
174
175
176
177
# File 'lib/knife-solo/resources/patch_cookbooks/chef-solo-search/tests/test_search.rb', line 167

def test_empty_field_value
  assert_raise(RuntimeError) {
    search(:users, "gender:#{nil} AND age:35")
  }
  assert_raise(RuntimeError) {
    search(:users, "gender: AND age:35")
  }
  assert_raise(RuntimeError) {
    search(:users, "gender:\"\" AND age:35")
  }
end

#test_general_lucene_range_failsObject



123
124
125
126
127
# File 'lib/knife-solo/resources/patch_cookbooks/chef-solo-search/tests/test_search.rb', line 123

def test_general_lucene_range_fails
  assert_raises RuntimeError do
    nodes = search(:users, "children:[aaa TO zzz]")
  end
end

#test_get_all_but_speedyObject



63
64
65
66
67
# File 'lib/knife-solo/resources/patch_cookbooks/chef-solo-search/tests/test_search.rb', line 63

def test_get_all_but_speedy
  nodes = search(:users, "NOT username:speedy")
  assert nodes.length > 0
  assert nodes.all?{|x| x["username"] != "speedy"}
end

#test_get_all_with_fieldObject



49
50
51
52
53
# File 'lib/knife-solo/resources/patch_cookbooks/chef-solo-search/tests/test_search.rb', line 49

def test_get_all_with_field
  nodes = search(:users, "username:*")
  assert nodes.length > 0
  assert nodes.all?{|x| !x["username"].nil?}
end

#test_get_all_without_fieldObject



55
56
57
58
59
60
61
# File 'lib/knife-solo/resources/patch_cookbooks/chef-solo-search/tests/test_search.rb', line 55

def test_get_all_without_field
  nodes = search(:users, "(NOT username:*)")
  assert nodes.length == 0
  nodes = search(:users, "(NOT color:*)")
  assert nodes.length == 3
  assert nodes.all?{|x| x["color"].nil?}
end

#test_integerObject



87
88
89
90
91
# File 'lib/knife-solo/resources/patch_cookbooks/chef-solo-search/tests/test_search.rb', line 87

def test_integer
  nodes = search(:users, "age:35")
  assert nodes.length == 1
  assert nodes[0]["age"] == 35
end

#test_nested_fieldnamesObject



184
185
186
187
188
189
# File 'lib/knife-solo/resources/patch_cookbooks/chef-solo-search/tests/test_search.rb', line 184

def test_nested_fieldnames
  nodes = search(:users, "address_street:wilhelmsstrasse")
  assert nodes.length == 1
  nodes = search(:users, "address_street_floor:1")
  assert nodes.length == 1
end

#test_NOT_conditionObject



104
105
106
107
108
109
110
111
# File 'lib/knife-solo/resources/patch_cookbooks/chef-solo-search/tests/test_search.rb', line 104

def test_NOT_condition
  nodes = search(:users, "children:tom AND (NOT gender:female)")
  assert nodes.length == 1
  nodes = search(:users, "children:tom AND (NOT gender:female) AND age:42")
  assert nodes.length == 1
  nodes = search(:users, "children:tom AND (NOT gender:female) AND (NOT age:42)")
  assert nodes.length == 0
end

#test_OR_conditionObject



99
100
101
102
# File 'lib/knife-solo/resources/patch_cookbooks/chef-solo-search/tests/test_search.rb', line 99

def test_OR_condition
  nodes = search(:users, "age:42 OR age:22")
  assert nodes.length == 2
end

#test_OR_groupObject



179
180
181
182
# File 'lib/knife-solo/resources/patch_cookbooks/chef-solo-search/tests/test_search.rb', line 179

def test_OR_group
  nodes = search(:users, "id:(mike OR tom)")
  assert nodes.length == 2
end

#test_search_allObject



33
34
35
36
37
38
39
40
41
# File 'lib/knife-solo/resources/patch_cookbooks/chef-solo-search/tests/test_search.rb', line 33

def test_search_all
  # try to get data of all users
  nodes = search(:users, "*:*")
  assert_equal nodes.length, 4
  nodes = search(:users)
  assert_equal nodes.length, 4
  nodes = search(:users, nil)
  assert_equal nodes.length, 4
end

#test_search_exact_matchObject



43
44
45
46
47
# File 'lib/knife-solo/resources/patch_cookbooks/chef-solo-search/tests/test_search.rb', line 43

def test_search_exact_match
  nodes = search(:users, "username:speedy")
  assert_equal nodes.length, 1
  assert_equal nodes[0]["username"], "speedy"
end

#test_wildcardsObject



158
159
160
161
162
163
164
165
# File 'lib/knife-solo/resources/patch_cookbooks/chef-solo-search/tests/test_search.rb', line 158

def test_wildcards
  nodes = search(:users, "gender:f??ale")
  assert nodes.length == 1
  nodes = search(:users, "username:spee?y")
  assert nodes.length == 1
  nodes = search(:users, "username:spee*")
  assert nodes.length == 1
end