Skip to content

Commit 2a9ad05

Browse files
committed
Test macros use directly in a SPL query
Currently we do not have a test that uses macros directly in SPL. This change adds such test. This change also changes the name of the macro, since names generated by tmpname() contain "-", which cannot be part of a macro name, since the SPL parser treats "-" as an argument.
1 parent baf19dc commit 2a9ad05

File tree

1 file changed

+21
-3
lines changed

1 file changed

+21
-3
lines changed

tests/integration/test_macro.py

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,24 +19,30 @@
1919
import logging
2020

2121
import splunklib.client as client
22+
from splunklib import results
2223

2324
import pytest
2425

2526

2627
@pytest.mark.smoke
2728
class TestMacro(testlib.SDKTestCase):
29+
macro_name = "SDKTestMacro"
30+
2831
def setUp(self):
2932
super(TestMacro, self).setUp()
33+
self.clean()
3034
macros = self.service.macros
3135
logging.debug("Macros namespace: %s", macros.service.namespace)
32-
self.macro_name = testlib.tmpname()
33-
definition = '| eval test="123"'
36+
definition = 'eval test="123"'
3437
self.macro = macros.create(self.macro_name, definition)
3538

3639
def tearDown(self):
3740
super(TestMacro, self).setUp()
41+
self.clean()
42+
43+
def clean(self):
3844
for macro in self.service.macros:
39-
if macro.name.startswith("delete-me"):
45+
if macro.name == self.macro_name:
4046
self.service.macros.delete(macro.name)
4147

4248
def check_macro(self, macro):
@@ -152,6 +158,18 @@ def test_acl_fails_without_owner(self):
152158
**{"perms.read": "admin, nobody"},
153159
)
154160

161+
def test_use_macro_in_search(self):
162+
stream = self.service.jobs.oneshot(
163+
f"| makeresults count=1 | `{self.macro_name}`",
164+
output_mode="json",
165+
)
166+
167+
result = results.JSONResultsReader(stream)
168+
out = list(result)
169+
170+
self.assertTrue(len(out) > 0)
171+
self.assertEqual(out[0]["test"], "123")
172+
155173

156174
if __name__ == "__main__":
157175
try:

0 commit comments

Comments
 (0)