IndexTimeTests¶
TestTemplates¶
Includes the test scenarios to check the index time properties of an Add-on.
IndexTimeTestTemplate
¶
Bases: object
Test templates to test the index time fields of an App
Source code in pytest_splunk_addon/index_tests/test_templates.py
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 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 |
|
test_indextime_key_fields(splunk_search_util, splunk_ingest_data, splunk_setup, splunk_indextime_key_fields, record_property, caplog)
¶
This test case checks that a key_field has the expected values. The key fields are as follows:
* src
* src_port
* dest
* dest_port
* dvc
* host
* user
* url
Parameters:
Name | Type | Description | Default |
---|---|---|---|
splunk_search_util |
SearchUtil
|
Object that helps to search on Splunk. |
required |
splunk_ingest_data |
fixture
|
Ensure data was ingested before running test |
required |
splunk_setup |
fixture
|
Ensure that test environment was set up before running test |
required |
splunk_indextime_key_fields |
fixture
|
Test for key fields |
required |
record_property |
fixture
|
Document facts of test cases to provide more info in the test failure reports. |
required |
caplog |
fixture
|
fixture to capture logs. |
required |
Source code in pytest_splunk_addon/index_tests/test_templates.py
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 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 |
|
test_indextime_line_breaker(splunk_search_util, splunk_ingest_data, splunk_setup, splunk_indextime_line_breaker, record_property, caplog)
¶
This test case checks that number of events is as expected.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
splunk_search_util |
SearchUtil
|
Object that helps to search on Splunk. |
required |
splunk_ingest_data |
fixture
|
Ensure data was ingested before running test |
required |
splunk_setup |
fixture
|
Ensure that test environment was set up before running test |
required |
splunk_indextime_line_breaker |
fixture
|
Test for event count |
required |
record_property |
fixture
|
Document facts of test cases to provide more info in the test failure reports. |
required |
caplog |
fixture
|
fixture to capture logs. |
required |
Source code in pytest_splunk_addon/index_tests/test_templates.py
269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 |
|
test_indextime_time(splunk_search_util, splunk_ingest_data, splunk_setup, splunk_indextime_time, record_property, caplog)
¶
This test case checks that _time value in the events has the expected values.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
splunk_search_util |
SearchUtil
|
Object that helps to search on Splunk. |
required |
splunk_ingest_data |
fixture
|
Ensure data was ingested before running test |
required |
splunk_setup |
fixture
|
Ensure that test environment was set up before running test |
required |
splunk_indextime_time |
fixture
|
Test for _time field |
required |
record_property |
fixture
|
Document facts of test cases to provide more info in the test failure reports. |
required |
caplog |
fixture
|
fixture to capture logs. |
required |
Source code in pytest_splunk_addon/index_tests/test_templates.py
181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 |
|
TestGenerator¶
IndexTimeTestGenerator
¶
Bases: object
Generates test cases to test the index time extraction of an Add-on.
- Provides the pytest parameters to the test templates.
- Supports key_fields: List of fields which should be tested for the Add-on.
Source code in pytest_splunk_addon/index_tests/test_generator.py
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 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 |
|
add_host_prefix(host_prefix, hosts)
¶
Returns value of host with prefix
Parameters:
Name | Type | Description | Default |
---|---|---|---|
host_prefix |
str
|
Prefix value to be added in host |
required |
hosts |
list
|
List of host |
required |
Returns:
Type | Description |
---|---|
Value of host with prefix |
Source code in pytest_splunk_addon/index_tests/test_generator.py
214 215 216 217 218 219 220 221 222 223 224 225 226 |
|
generate_hosts_params(tokenized_event, hosts)
¶
Generates test case based on host value of the event
Parameters:
Name | Type | Description | Default |
---|---|---|---|
tokenized_event |
SampleEvent
|
Instance containing event info |
required |
hosts |
list
|
List of hosts for event |
required |
Yields:
Type | Description |
---|---|
pytest.params for the test templates |
Source code in pytest_splunk_addon/index_tests/test_generator.py
301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 |
|
generate_identifier_params(tokenized_event, identifier_key)
¶
Generates test case based on Identifier key mentioned in conf file
Parameters:
Name | Type | Description | Default |
---|---|---|---|
tokenized_event |
SampleEvent
|
Instance containing event info |
required |
identifier_key |
str
|
Identifier Key if mention in conf file |
required |
Yields:
Type | Description |
---|---|
pytest.params for the test templates |
Source code in pytest_splunk_addon/index_tests/test_generator.py
274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 |
|
generate_line_breaker_tests(tokenized_events)
¶
Generates test case for testing line breaker
Parameters:
Name | Type | Description | Default |
---|---|---|---|
tokenized_events |
list
|
list of tokenized events |
required |
Yields:
Type | Description |
---|---|
pytest.params for the test templates |
Source code in pytest_splunk_addon/index_tests/test_generator.py
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 |
|
generate_params(tokenized_event, identifier_key, hosts)
¶
Generates test case based on parameters
Parameters:
Name | Type | Description | Default |
---|---|---|---|
tokenized_event |
SampleEvent
|
Instance containing event info |
required |
identifier_key |
str
|
Identifier Key if mention in conf file |
required |
hosts |
list
|
List of host for event |
required |
Yields:
Type | Description |
---|---|
pytest.params for the test templates |
Source code in pytest_splunk_addon/index_tests/test_generator.py
257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 |
|
generate_tests(store_events, app_path, config_path, test_type)
¶
Generates the test cases based on test_type
Parameters:
Name | Type | Description | Default |
---|---|---|---|
store_events |
bool
|
variable to define if events should be stored |
required |
app_path |
str
|
Path of the app package |
required |
config_path |
str
|
Path of package which contains pytest-splunk-addon-data.conf |
required |
test_type |
str
|
Type of test case |
required |
Yields:
Type | Description |
---|---|
pytest.params for the test templates |
Source code in pytest_splunk_addon/index_tests/test_generator.py
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 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
|
get_hosts(tokenized_event)
¶
Returns value of host for event
Parameters:
Name | Type | Description | Default |
---|---|---|---|
tokenized_event |
SampleEvent
|
Instance containing event info |
required |
Returns:
Type | Description |
---|---|
Value of host for event |
Source code in pytest_splunk_addon/index_tests/test_generator.py
183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 |
|
get_source(sample_event)
¶
Returns value of source for event
Parameters:
Name | Type | Description | Default |
---|---|---|---|
sample_event |
SampleEvent
|
Instance containing event info |
required |
Returns:
Type | Description |
---|---|
Value of source for event |
Source code in pytest_splunk_addon/index_tests/test_generator.py
243 244 245 246 247 248 249 250 251 252 253 254 255 |
|
get_sourcetype(sample_event)
¶
Returns value of sourcetype for event
Parameters:
Name | Type | Description | Default |
---|---|---|---|
sample_event |
SampleEvent
|
Instance containing event info |
required |
Returns:
Type | Description |
---|---|
Value of sourcetype for event |
Source code in pytest_splunk_addon/index_tests/test_generator.py
228 229 230 231 232 233 234 235 236 237 238 239 240 241 |
|