summaryrefslogtreecommitdiff
path: root/features/steps/search_steps.rb
blob: 3dd179eebe70b9912d2c80f955b2b783861e99ac (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
Given "the search index has been committed" do
  sleep 1 # allow time for the objects to transit rabbitmq and opscode-expander.
  RestClient.get("http://localhost:8983/solr/update?commit=true&waitFlush=true")
end

Then "there should be '$expected_count' total search results" do |expected_count|
  expected_count = expected_count.to_i
  inflated_response.should respond_to(:[])
  inflated_response.should have_key("total")
  inflated_response["total"].should == expected_count
end

Then "a '$result_item_klass' with item name '$result_item_name' should be in the search result" do |result_item_klass, result_item_name|
  inflated_response.should respond_to(:[])
  inflated_response.should have_key("rows")

  found_match = false
  expected_klass = eval(result_item_klass)

  inflated_response['rows'].each do |item|
    next unless item.name == result_item_name
    found_match = true
    item.should be_a_kind_of(expected_klass)
  end

  unless found_match
    msg = "expected to find a #{result_item_klass} with item name #{result_item_name} in the inflated response but it's not there\n"
    msg << "actual inflated response is #{inflated_response.inspect}"
    raise msg
  end
end

Then "a '$result_item_klass' with id '$result_item_id' should be in the search result" do |result_item_klass, result_item_id|
  inflated_response.should respond_to(:[])
  inflated_response.should have_key("rows")

  result_item = inflated_response["rows"].find {|item| item["id"] == result_item_id }
  unless result_item
    msg = "expected to find a #{result_item_klass} with 'id' #{result_item_id} in the inflated response but it's not there\n"
    msg << "actual inflated response is #{inflated_response.inspect}"
    raise msg
  end
  expected_klass = eval(result_item_klass)

  result_item.should be_a_kind_of(expected_klass)
end

Given "PL-540 is resolved in favor of not removing this feature" do
  pending
end

Given /^a set of nodes pre-populated with known, searchable data$/ do
  node_script = File.join(datadir, 'search-tests', 'search-test-nodes.rb')
  shell_out! "knife exec #{get_knife_config} < #{node_script}", :timeout => 240
end

When /^I execute a randomized set of searches across my infrastructure$/ do
  search_script = File.join(datadir, 'search-tests', 'do_knife_search_test.rb')
  @shell_result = shell_out "knife exec #{get_knife_config} < #{search_script}"
end

Then /^all of the searches should return the expected results$/ do
  io = StringIO.new(@shell_result.stdout)
  while io.eof? == false
    l = io.readline
    next unless l =~ /^(OK|FAIL|ERROR)/
    case $1
    when "OK"
      next
    when "FAIL"
      message = [l, io.readline, io.readline].join("\n")
      puts @shell_result.stdout
      raise message
    when "ERROR"
      puts @shell_result.stdout
      raise l
    end
  end
end

# return a set of knife command line parameters that
# are based on the current Chef::Rest config being
# used by the feature tests
def get_knife_config
  [
    "--user",       @rest.auth_credentials.client_name,
    "--server-url", @rest.url,
    "--key",        @rest.auth_credentials.key_file
  ].join(" ")
end