Skip to content

Commit

Permalink
Merge pull request #55497 from Akm0d/test_search_by
Browse files Browse the repository at this point in the history
Fixed issue #55149
  • Loading branch information
dwoz authored Dec 12, 2019
2 parents 6e7fa3f + 2944170 commit 9de2416
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 2 deletions.
3 changes: 1 addition & 2 deletions salt/modules/match.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import copy

# Import salt libs
import salt.minion
import salt.loader
from salt.defaults import DEFAULT_TARGET_DELIM
from salt.ext import six
Expand Down Expand Up @@ -47,7 +46,7 @@ def compound(tgt, minion_id=None):
opts = __opts__
matchers = salt.loader.matchers(opts)
try:
return matchers['compound_match.match'](tgt, opts=opts)
return matchers['compound_match.match'](tgt)
except Exception as exc:
log.exception(exc)
return False
Expand Down
38 changes: 38 additions & 0 deletions tests/unit/modules/test_match.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
)

# Import Salt Libs
import salt.loader
import salt.modules.match as match
import salt.matchers.compound_match as compound_match
import salt.matchers.glob_match as glob_match
Expand Down Expand Up @@ -61,6 +62,43 @@ def setup_loader_modules(self):
}
}

def test_compound_with_minion_id(self):
'''
Make sure that when a minion_id IS past, that it is contained in opts
'''
mock_compound_match = MagicMock()
target = 'bar04'
new_minion_id = 'new_minion_id'

with patch.object(salt.loader, 'matchers', return_value={'compound_match.match': mock_compound_match}) as matchers:
match.compound(target, minion_id=new_minion_id)

# The matcher should get called with MINION_ID
matchers.assert_called_once()
matchers_opts = matchers.call_args[0][0]
self.assertEqual(matchers_opts.get('id'), new_minion_id)

# The compound matcher should not get MINION_ID, no opts should be passed
mock_compound_match.assert_called_once_with(target)

def test_compound(self):
'''
Test issue #55149
'''
mock_compound_match = MagicMock()
target = 'bar04'

with patch.object(salt.loader, 'matchers', return_value={'compound_match.match': mock_compound_match}) as matchers:
match.compound(target)

# The matcher should get called with MINION_ID
matchers.assert_called_once()
self.assertEqual(len(matchers.call_args[0]), 1)
self.assertEqual(matchers.call_args[0][0].get('id'), MINION_ID)

# The compound matcher should not get MINION_ID, no opts should be passed
mock_compound_match.assert_called_once_with(target)

def test_filter_by(self):
'''
Tests if filter_by returns the correct dictionary.
Expand Down

0 comments on commit 9de2416

Please sign in to comment.