splunk-sdk-ruby 0.1.0 → 0.8.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,46 @@
1
+ require_relative 'test_helper'
2
+ require 'splunk-sdk-ruby'
3
+
4
+ include Splunk
5
+
6
+ class ModularInputKindsTestCase < TestCaseWithSplunkConnection
7
+ def setup
8
+ super
9
+
10
+ omit_if(@service.splunk_version[0] < 5)
11
+ if not has_test_data?(@service)
12
+ fail("Install the SDK test data to test modular input kinds.")
13
+ end
14
+ install_app_from_collection("modular-inputs")
15
+ end
16
+
17
+ ##
18
+ # Does the argument method on ModularInputKind return the expected keys
19
+ # on a known modular input kind?
20
+ #
21
+ def test_list_arguments
22
+ test1 = @service.modular_input_kinds["test1"]
23
+ expected_args = ["name", "resname", "key_id", "no_description",
24
+ "empty_description", "arg_required_on_edit",
25
+ "not_required_on_edit", "required_on_create",
26
+ "not_required_on_create", "number_field",
27
+ "string_field", "boolean_field"].sort()
28
+ found_args = test1.arguments.keys().sort()
29
+ assert_equal(expected_args, found_args)
30
+ end
31
+
32
+ ##
33
+ # Does each iterate properly? Are the headers of the modular inputs sane?
34
+ #
35
+ def test_list_modular_inputs_and_headers
36
+ @service.modular_input_kinds.each do |mod_input|
37
+ if mod_input.name == "test1"
38
+ assert_equal('Test "Input" - 1', mod_input["title"])
39
+ assert_equal("xml", mod_input["streaming_mode"])
40
+ elsif mod_input.name == "test2"
41
+ assert_equal("test2", mod_input["title"])
42
+ assert_equal("simple", mod_input["streaming_mode"])
43
+ end
44
+ end
45
+ end
46
+ end
@@ -13,6 +13,9 @@ class TestRestarts < TestCaseWithSplunkConnection
13
13
  service.server_requires_restart?
14
14
  sleep(0.3)
15
15
  end
16
+ if !service.server_accepting_connections?
17
+ fail("Did not restart within timeout.")
18
+ end
16
19
  end
17
20
 
18
21
  assert_logged_in(service)
@@ -23,6 +26,12 @@ class TestRestarts < TestCaseWithSplunkConnection
23
26
  begin
24
27
  service.restart(0.1)
25
28
  rescue TimeoutError
29
+ # Wait for it to go down
30
+ while service.server_accepting_connections? &&
31
+ service.server_requires_restart?
32
+ sleep(0.1)
33
+ end
34
+
26
35
  # Wait for it to come back up
27
36
  while !service.server_accepting_connections? ||
28
37
  service.server_requires_restart?
@@ -37,6 +46,7 @@ class TestRestarts < TestCaseWithSplunkConnection
37
46
  def test_restart_with_no_timeout
38
47
  service = Context.new(@splunkrc).login()
39
48
  service.restart()
49
+
40
50
  assert_not_logged_in(service)
41
51
 
42
52
  # Wait for it to come back up
@@ -19,21 +19,23 @@ class TestResultsReader < Test::Unit::TestCase
19
19
  n_results = 0
20
20
  reader.each_with_index do |result, index|
21
21
  n_results += 1
22
+ expected_fields = expected["results"][index]["fields"]
22
23
  # The assert of the full data structure below works, but
23
24
  # by default Test::Unit doesn't print the diff of large
24
25
  # data structures, so for debugging purposes it's much
25
26
  # nicer to have each key checked individually as well.
26
- expected["results"][index].each_entry do |key, value|
27
+ expected_fields.each_entry do |key, value|
27
28
  assert_equal([index, key, value],
28
29
  [index, key, result[key]])
29
30
  end
30
- assert_equal(expected["results"][index], result)
31
+ assert_equal(expected_fields, result)
32
+ assert_equal(expected["results"][index]["RAW_XML"], result.segmented_raw())
31
33
  end
32
34
  assert_equal(expected["results"].length, n_results)
33
35
  end
34
36
 
35
- test_data = JSON::parse(open("test/resultsreader_test_data.json").read())
36
- export_data = JSON::parse(open("test/export_test_data.json").read())
37
+ test_data = JSON::parse(open("test/data/resultsreader_test_data.json").read())
38
+ export_data = JSON::parse(open("test/data/export_test_data.json").read())
37
39
 
38
40
  xml_libraries.each do |xml_library|
39
41
  test_data.each_entry do |version, tests|
@@ -49,11 +51,23 @@ class TestResultsReader < Test::Unit::TestCase
49
51
  end
50
52
 
51
53
  export_data.each_entry do |version, tests|
54
+ # without preview via ResultsReader
55
+ test_name = "test_#{xml_library}_#{version.gsub(/\./, "_")}_export_via_results_reader"
56
+ define_method(test_name.intern) do
57
+ Splunk::require_xml_library(xml_library)
58
+ raw_file = File.open("test/data/export/#{version}/export_results.xml")
59
+ file = Splunk::ExportStream.new(raw_file)
60
+ found = ResultsReader.new(file)
61
+ expected = tests["without_preview"]
62
+ assert_results_reader_equals(expected, found)
63
+ end
64
+
52
65
  # without_preview
53
66
  test_name = "test_#{xml_library}_#{version.gsub(/\./, "_")}_sans_preview"
54
67
  define_method(test_name.intern) do
55
68
  Splunk::require_xml_library(xml_library)
56
- file = File.open("test/data/export/#{version}/export_results.xml")
69
+ raw_file = File.open("test/data/export/#{version}/export_results.xml")
70
+ file = Splunk::ExportStream.new(raw_file)
57
71
  reader = MultiResultsReader.new(file)
58
72
  found = reader.final_results()
59
73
  expected = tests["without_preview"]
@@ -64,7 +78,8 @@ class TestResultsReader < Test::Unit::TestCase
64
78
  test_name = "test_#{xml_library}_#{version.gsub(/\./, "_")}_with_preview"
65
79
  define_method(test_name.intern) do
66
80
  Splunk::require_xml_library(xml_library)
67
- file = File.open("test/data/export/#{version}/export_results.xml")
81
+ raw_file = File.open("test/data/export/#{version}/export_results.xml")
82
+ file = Splunk::ExportStream.new(raw_file)
68
83
  multireader = MultiResultsReader.new(file)
69
84
  n_results_sets = 0
70
85
  readers = []
@@ -91,7 +106,7 @@ class TestResultsReader < Test::Unit::TestCase
91
106
  readers = []
92
107
  multireader.each_with_index do |rr, index|
93
108
  readers << rr
94
- expected = tests["nonreporting"][index]
109
+ expected = tests["nonreporting"]
95
110
  assert_results_reader_equals(expected, rr)
96
111
  n_results_sets += 1
97
112
  end
@@ -28,6 +28,14 @@ class UserTestCase < TestCaseWithSplunkConnection
28
28
  def test_case_insensitive
29
29
  name = temporary_name() + "UPCASE"
30
30
  user = @service.users.create(name, :password => "abc", :roles => ["power"])
31
+ assert_equal(name.downcase(), @service.users.fetch(name).name)
31
32
  assert_true(@service.users.has_key?(name.downcase()))
32
33
  end
34
+
35
+ def test_roles
36
+ name = temporary_name()
37
+ user = @service.users.create(name, :password => "abc",
38
+ :roles => ["power", "can_delete"])
39
+ assert_equal(["can_delete", "power"], user["roles"].sort())
40
+ end
33
41
  end
@@ -4,6 +4,16 @@ require 'splunk-sdk-ruby'
4
4
  include Splunk
5
5
 
6
6
  class TestXMLShim < Test::Unit::TestCase
7
+ def test_escape_string_with_rexml
8
+ Splunk::require_xml_library(:rexml)
9
+ assert_equal("&lt;&gt;'\"&amp;", Splunk::escape_string("<>'\"&"))
10
+ end
11
+
12
+ def test_escape_string_with_nokogiri
13
+ Splunk::require_xml_library(:nokogiri)
14
+ assert_equal("&lt;&gt;'\"&amp;", Splunk::escape_string("<>'\"&"))
15
+ end
16
+
7
17
  def test_no_matches_with_rexml
8
18
  Splunk::require_xml_library(:rexml)
9
19
  assert_nil(Splunk::text_at_xpath("//msg", "<html>Hi</html>"))
metadata CHANGED
@@ -1,20 +1,18 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: splunk-sdk-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
5
- prerelease:
4
+ version: 0.8.1
6
5
  platform: ruby
7
6
  authors:
8
7
  - Splunk
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-02-22 00:00:00.000000000 Z
11
+ date: 2013-04-08 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: rake
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
17
  - - ~>
20
18
  - !ruby/object:Gem::Version
@@ -22,7 +20,6 @@ dependencies:
22
20
  type: :runtime
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
24
  - - ~>
28
25
  - !ruby/object:Gem::Version
@@ -30,15 +27,13 @@ dependencies:
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: test-unit
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
31
  - - ! '>='
36
32
  - !ruby/object:Gem::Version
37
33
  version: '0'
38
- type: :runtime
34
+ type: :development
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
38
  - - ! '>='
44
39
  - !ruby/object:Gem::Version
@@ -50,80 +45,86 @@ executables: []
50
45
  extensions: []
51
46
  extra_rdoc_files: []
52
47
  files:
48
+ - lib/splunk-sdk-ruby/ambiguous_entity_reference.rb
53
49
  - lib/splunk-sdk-ruby/atomfeed.rb
54
- - lib/splunk-sdk-ruby/version.rb
55
- - lib/splunk-sdk-ruby/splunk_http_error.rb
56
- - lib/splunk-sdk-ruby/entity_not_ready.rb
57
- - lib/splunk-sdk-ruby/resultsreader.rb
58
- - lib/splunk-sdk-ruby/context.rb
59
- - lib/splunk-sdk-ruby/service.rb
60
- - lib/splunk-sdk-ruby/illegal_operation.rb
61
- - lib/splunk-sdk-ruby/entity.rb
62
- - lib/splunk-sdk-ruby/entity/stanza.rb
63
- - lib/splunk-sdk-ruby/entity/index.rb
64
- - lib/splunk-sdk-ruby/entity/message.rb
65
- - lib/splunk-sdk-ruby/entity/saved_search.rb
66
- - lib/splunk-sdk-ruby/entity/job.rb
50
+ - lib/splunk-sdk-ruby/collection/apps.rb
51
+ - lib/splunk-sdk-ruby/collection/case_insensitive_collection.rb
67
52
  - lib/splunk-sdk-ruby/collection/configuration_file.rb
68
53
  - lib/splunk-sdk-ruby/collection/configurations.rb
69
- - lib/splunk-sdk-ruby/collection/apps.rb
70
- - lib/splunk-sdk-ruby/collection/messages.rb
54
+ - lib/splunk-sdk-ruby/collection/input_kinds.rb
71
55
  - lib/splunk-sdk-ruby/collection/jobs.rb
72
- - lib/splunk-sdk-ruby/collection/case_insensitive_collection.rb
73
- - lib/splunk-sdk-ruby/ambiguous_entity_reference.rb
56
+ - lib/splunk-sdk-ruby/collection/messages.rb
74
57
  - lib/splunk-sdk-ruby/collection.rb
58
+ - lib/splunk-sdk-ruby/context.rb
59
+ - lib/splunk-sdk-ruby/entity/index.rb
60
+ - lib/splunk-sdk-ruby/entity/job.rb
61
+ - lib/splunk-sdk-ruby/entity/message.rb
62
+ - lib/splunk-sdk-ruby/entity/modular_input_kind.rb
63
+ - lib/splunk-sdk-ruby/entity/saved_search.rb
64
+ - lib/splunk-sdk-ruby/entity/stanza.rb
65
+ - lib/splunk-sdk-ruby/entity.rb
66
+ - lib/splunk-sdk-ruby/entity_not_ready.rb
67
+ - lib/splunk-sdk-ruby/illegal_operation.rb
75
68
  - lib/splunk-sdk-ruby/namespace.rb
69
+ - lib/splunk-sdk-ruby/resultsreader.rb
70
+ - lib/splunk-sdk-ruby/service.rb
71
+ - lib/splunk-sdk-ruby/splunk_http_error.rb
76
72
  - lib/splunk-sdk-ruby/synonyms.rb
73
+ - lib/splunk-sdk-ruby/version.rb
77
74
  - lib/splunk-sdk-ruby/xml_shim.rb
78
75
  - lib/splunk-sdk-ruby.rb
79
- - examples/5_stream_data_to_splunk.rb
80
- - examples/4_asynchronous_searches.rb
81
- - examples/3_blocking_searches.rb
82
76
  - examples/1_connect.rb
83
77
  - examples/2_manage.rb
84
- - test/test_atomfeed.rb
85
- - test/test_resultsreader.rb
86
- - test/test_configuration_file.rb
87
- - test/test_users.rb
88
- - test/resultsreader_test_data.json
89
- - test/export_test_data.json
90
- - test/test_roles.rb
91
- - test/test_index.rb
92
- - test/test_restarts.rb
93
- - test/services.xml
94
- - test/test_namespace.rb
95
- - test/test_messages.rb
96
- - test/test_service.rb
97
- - test/test_http_error.rb
98
- - test/atom_test_data.rb
99
- - test/data/results/4.2.5/results.xml
78
+ - examples/3_blocking_searches.rb
79
+ - examples/4_asynchronous_searches.rb
80
+ - examples/5_stream_data_to_splunk.rb
81
+ - examples/6_work_with_modular_inputs.rb
82
+ - examples/example_modular_inputs.spl
83
+ - test/data/atom/atom_feed_with_message.xml
84
+ - test/data/atom/atom_with_feed.xml
85
+ - test/data/atom/atom_with_several_entries.xml
86
+ - test/data/atom/atom_with_simple_entries.xml
87
+ - test/data/atom/atom_without_feed.xml
88
+ - test/data/atom_test_data.json
89
+ - test/data/export/4.2.5/export_results.xml
90
+ - test/data/export/4.3.5/export_results.xml
91
+ - test/data/export/5.0.1/export_results.xml
92
+ - test/data/export/5.0.1/nonreporting.xml
93
+ - test/data/export_test_data.json
100
94
  - test/data/results/4.2.5/results-empty.xml
101
95
  - test/data/results/4.2.5/results-preview.xml
102
- - test/data/results/5.0.2/results.xml
96
+ - test/data/results/4.2.5/results.xml
97
+ - test/data/results/4.3.5/results-empty.xml
98
+ - test/data/results/4.3.5/results-preview.xml
99
+ - test/data/results/4.3.5/results.xml
103
100
  - test/data/results/5.0.2/results-empty.xml
104
101
  - test/data/results/5.0.2/results-empty_preview.xml
105
102
  - test/data/results/5.0.2/results-preview.xml
106
- - test/data/results/4.3.5/results.xml
107
- - test/data/results/4.3.5/results-empty.xml
108
- - test/data/results/4.3.5/results-preview.xml
109
- - test/data/export/4.2.5/export_results.xml
110
- - test/data/export/5.0.1/export_results.xml
111
- - test/data/export/5.0.1/nonreporting.xml
112
- - test/data/export/4.3.5/export_results.xml
113
- - test/data/atom/atom_with_feed.xml
114
- - test/data/atom/atom_with_simple_entries.xml
115
- - test/data/atom/atom_with_several_entries.xml
116
- - test/data/atom/atom_feed_with_message.xml
117
- - test/data/atom/atom_without_feed.xml
118
- - test/test_context.rb
119
- - test/testfile.txt
120
- - test/test_saved_searches.rb
103
+ - test/data/results/5.0.2/results.xml
104
+ - test/data/resultsreader_test_data.json
105
+ - test/services.server.info.xml
106
+ - test/services.xml
107
+ - test/test_atomfeed.rb
121
108
  - test/test_collection.rb
109
+ - test/test_configuration_file.rb
110
+ - test/test_context.rb
122
111
  - test/test_entity.rb
123
- - test/test_jobs.rb
124
112
  - test/test_helper.rb
125
- - test/services.server.info.xml
113
+ - test/test_http_error.rb
114
+ - test/test_index.rb
115
+ - test/test_inputs.rb
116
+ - test/test_jobs.rb
117
+ - test/test_messages.rb
118
+ - test/test_modular_input_kinds.rb
119
+ - test/test_namespace.rb
120
+ - test/test_restarts.rb
121
+ - test/test_resultsreader.rb
122
+ - test/test_roles.rb
123
+ - test/test_saved_searches.rb
124
+ - test/test_service.rb
125
+ - test/test_users.rb
126
126
  - test/test_xml_shim.rb
127
+ - test/testfile.txt
127
128
  - CHANGELOG.md
128
129
  - LICENSE
129
130
  - README.md
@@ -131,70 +132,72 @@ files:
131
132
  - Rakefile
132
133
  - splunk-sdk-ruby.gemspec
133
134
  homepage: http://dev.splunk.com
134
- licenses: []
135
+ licenses:
136
+ - APL2
137
+ metadata: {}
135
138
  post_install_message:
136
139
  rdoc_options: []
137
140
  require_paths:
138
141
  - lib
139
142
  required_ruby_version: !ruby/object:Gem::Requirement
140
- none: false
141
143
  requirements:
142
144
  - - ! '>='
143
145
  - !ruby/object:Gem::Version
144
146
  version: 1.9.2
145
147
  required_rubygems_version: !ruby/object:Gem::Requirement
146
- none: false
147
148
  requirements:
148
149
  - - ! '>='
149
150
  - !ruby/object:Gem::Version
150
151
  version: '0'
151
152
  requirements: []
152
153
  rubyforge_project:
153
- rubygems_version: 1.8.25
154
+ rubygems_version: 2.0.3
154
155
  signing_key:
155
- specification_version: 3
156
+ specification_version: 4
156
157
  summary: Ruby bindings to Splunk REST layer
157
158
  test_files:
158
- - test/test_atomfeed.rb
159
- - test/test_resultsreader.rb
160
- - test/test_configuration_file.rb
161
- - test/test_users.rb
162
- - test/resultsreader_test_data.json
163
- - test/export_test_data.json
164
- - test/test_roles.rb
165
- - test/test_index.rb
166
- - test/test_restarts.rb
167
- - test/services.xml
168
- - test/test_namespace.rb
169
- - test/test_messages.rb
170
- - test/test_service.rb
171
- - test/test_http_error.rb
172
- - test/atom_test_data.rb
173
- - test/data/results/4.2.5/results.xml
159
+ - test/data/atom/atom_feed_with_message.xml
160
+ - test/data/atom/atom_with_feed.xml
161
+ - test/data/atom/atom_with_several_entries.xml
162
+ - test/data/atom/atom_with_simple_entries.xml
163
+ - test/data/atom/atom_without_feed.xml
164
+ - test/data/atom_test_data.json
165
+ - test/data/export/4.2.5/export_results.xml
166
+ - test/data/export/4.3.5/export_results.xml
167
+ - test/data/export/5.0.1/export_results.xml
168
+ - test/data/export/5.0.1/nonreporting.xml
169
+ - test/data/export_test_data.json
174
170
  - test/data/results/4.2.5/results-empty.xml
175
171
  - test/data/results/4.2.5/results-preview.xml
176
- - test/data/results/5.0.2/results.xml
172
+ - test/data/results/4.2.5/results.xml
173
+ - test/data/results/4.3.5/results-empty.xml
174
+ - test/data/results/4.3.5/results-preview.xml
175
+ - test/data/results/4.3.5/results.xml
177
176
  - test/data/results/5.0.2/results-empty.xml
178
177
  - test/data/results/5.0.2/results-empty_preview.xml
179
178
  - test/data/results/5.0.2/results-preview.xml
180
- - test/data/results/4.3.5/results.xml
181
- - test/data/results/4.3.5/results-empty.xml
182
- - test/data/results/4.3.5/results-preview.xml
183
- - test/data/export/4.2.5/export_results.xml
184
- - test/data/export/5.0.1/export_results.xml
185
- - test/data/export/5.0.1/nonreporting.xml
186
- - test/data/export/4.3.5/export_results.xml
187
- - test/data/atom/atom_with_feed.xml
188
- - test/data/atom/atom_with_simple_entries.xml
189
- - test/data/atom/atom_with_several_entries.xml
190
- - test/data/atom/atom_feed_with_message.xml
191
- - test/data/atom/atom_without_feed.xml
192
- - test/test_context.rb
193
- - test/testfile.txt
194
- - test/test_saved_searches.rb
179
+ - test/data/results/5.0.2/results.xml
180
+ - test/data/resultsreader_test_data.json
181
+ - test/services.server.info.xml
182
+ - test/services.xml
183
+ - test/test_atomfeed.rb
195
184
  - test/test_collection.rb
185
+ - test/test_configuration_file.rb
186
+ - test/test_context.rb
196
187
  - test/test_entity.rb
197
- - test/test_jobs.rb
198
188
  - test/test_helper.rb
199
- - test/services.server.info.xml
189
+ - test/test_http_error.rb
190
+ - test/test_index.rb
191
+ - test/test_inputs.rb
192
+ - test/test_jobs.rb
193
+ - test/test_messages.rb
194
+ - test/test_modular_input_kinds.rb
195
+ - test/test_namespace.rb
196
+ - test/test_restarts.rb
197
+ - test/test_resultsreader.rb
198
+ - test/test_roles.rb
199
+ - test/test_saved_searches.rb
200
+ - test/test_service.rb
201
+ - test/test_users.rb
200
202
  - test/test_xml_shim.rb
203
+ - test/testfile.txt