test_find.py 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556
  1. # -*- coding: utf-8 -*-
  2. # Import python libs
  3. from __future__ import absolute_import, print_function, unicode_literals
  4. import os
  5. import shutil
  6. import stat
  7. import sys
  8. import tempfile
  9. # Import salt libs
  10. import salt.utils.files
  11. import salt.utils.find
  12. from salt.ext import six
  13. # Import 3rd-party libs
  14. from salt.ext.six.moves import range # pylint: disable=import-error,redefined-builtin
  15. # Import Salt Testing libs
  16. from tests.support.runtests import RUNTIME_VARS
  17. from tests.support.unit import TestCase, skipIf
  18. class TestFind(TestCase):
  19. def test_parse_interval(self):
  20. self.assertRaises(ValueError, salt.utils.find._parse_interval, "w")
  21. self.assertRaises(ValueError, salt.utils.find._parse_interval, "1")
  22. self.assertRaises(ValueError, salt.utils.find._parse_interval, "1s1w")
  23. self.assertRaises(ValueError, salt.utils.find._parse_interval, "1s1s")
  24. result, resolution, modifier = salt.utils.find._parse_interval("")
  25. self.assertEqual(result, 0)
  26. self.assertIs(resolution, None)
  27. self.assertEqual(modifier, "")
  28. result, resolution, modifier = salt.utils.find._parse_interval("1s")
  29. self.assertEqual(result, 1.0)
  30. self.assertEqual(resolution, 1)
  31. self.assertEqual(modifier, "")
  32. result, resolution, modifier = salt.utils.find._parse_interval("1m")
  33. self.assertEqual(result, 60.0)
  34. self.assertEqual(resolution, 60)
  35. self.assertEqual(modifier, "")
  36. result, resolution, modifier = salt.utils.find._parse_interval("1h")
  37. self.assertEqual(result, 3600.0)
  38. self.assertEqual(resolution, 3600)
  39. self.assertEqual(modifier, "")
  40. result, resolution, modifier = salt.utils.find._parse_interval("1d")
  41. self.assertEqual(result, 86400.0)
  42. self.assertEqual(resolution, 86400)
  43. self.assertEqual(modifier, "")
  44. result, resolution, modifier = salt.utils.find._parse_interval("1w")
  45. self.assertEqual(result, 604800.0)
  46. self.assertEqual(resolution, 604800)
  47. self.assertEqual(modifier, "")
  48. result, resolution, modifier = salt.utils.find._parse_interval("1w3d6h")
  49. self.assertEqual(result, 885600.0)
  50. self.assertEqual(resolution, 3600)
  51. self.assertEqual(modifier, "")
  52. result, resolution, modifier = salt.utils.find._parse_interval("1m1s")
  53. self.assertEqual(result, 61.0)
  54. self.assertEqual(resolution, 1)
  55. self.assertEqual(modifier, "")
  56. result, resolution, modifier = salt.utils.find._parse_interval("1m2s")
  57. self.assertEqual(result, 62.0)
  58. self.assertEqual(resolution, 1)
  59. self.assertEqual(modifier, "")
  60. result, resolution, modifier = salt.utils.find._parse_interval("+1d")
  61. self.assertEqual(result, 86400.0)
  62. self.assertEqual(resolution, 86400)
  63. self.assertEqual(modifier, "+")
  64. result, resolution, modifier = salt.utils.find._parse_interval("-1d")
  65. self.assertEqual(result, 86400.0)
  66. self.assertEqual(resolution, 86400)
  67. self.assertEqual(modifier, "-")
  68. def test_parse_size(self):
  69. self.assertRaises(ValueError, salt.utils.find._parse_size, "")
  70. self.assertRaises(ValueError, salt.utils.find._parse_size, "1s1s")
  71. min_size, max_size = salt.utils.find._parse_size("1")
  72. self.assertEqual(min_size, 1)
  73. self.assertEqual(max_size, 1)
  74. min_size, max_size = salt.utils.find._parse_size("1b")
  75. self.assertEqual(min_size, 1)
  76. self.assertEqual(max_size, 1)
  77. min_size, max_size = salt.utils.find._parse_size("1k")
  78. self.assertEqual(min_size, 1024)
  79. self.assertEqual(max_size, 2047)
  80. min_size, max_size = salt.utils.find._parse_size("1m")
  81. self.assertEqual(min_size, 1048576)
  82. self.assertEqual(max_size, 2097151)
  83. min_size, max_size = salt.utils.find._parse_size("1g")
  84. self.assertEqual(min_size, 1073741824)
  85. self.assertEqual(max_size, 2147483647)
  86. min_size, max_size = salt.utils.find._parse_size("1t")
  87. self.assertEqual(min_size, 1099511627776)
  88. self.assertEqual(max_size, 2199023255551)
  89. min_size, max_size = salt.utils.find._parse_size("0m")
  90. self.assertEqual(min_size, 0)
  91. self.assertEqual(max_size, 1048575)
  92. min_size, max_size = salt.utils.find._parse_size("-1m")
  93. self.assertEqual(min_size, 0)
  94. self.assertEqual(max_size, 1048576)
  95. min_size, max_size = salt.utils.find._parse_size("+1m")
  96. self.assertEqual(min_size, 1048576)
  97. self.assertEqual(max_size, sys.maxsize)
  98. min_size, max_size = salt.utils.find._parse_size("+1M")
  99. self.assertEqual(min_size, 1048576)
  100. self.assertEqual(max_size, sys.maxsize)
  101. def test_option_requires(self):
  102. option = salt.utils.find.Option()
  103. self.assertEqual(option.requires(), salt.utils.find._REQUIRES_PATH)
  104. def test_name_option_match(self):
  105. option = salt.utils.find.NameOption("name", "*.txt")
  106. self.assertIs(option.match("", "", ""), None)
  107. self.assertIs(option.match("", "hello.txt", "").group(), "hello.txt")
  108. self.assertIs(option.match("", "HELLO.TXT", ""), None)
  109. def test_iname_option_match(self):
  110. option = salt.utils.find.InameOption("name", "*.txt")
  111. self.assertIs(option.match("", "", ""), None)
  112. self.assertIs(option.match("", "hello.txt", "").group(), "hello.txt")
  113. self.assertIs(option.match("", "HELLO.TXT", "").group(), "HELLO.TXT")
  114. def test_regex_option_match(self):
  115. self.assertRaises(ValueError, salt.utils.find.RegexOption, "name", "(.*}")
  116. option = salt.utils.find.RegexOption("name", r".*\.txt")
  117. self.assertIs(option.match("", "", ""), None)
  118. self.assertIs(option.match("", "hello.txt", "").group(), "hello.txt")
  119. self.assertIs(option.match("", "HELLO.TXT", ""), None)
  120. def test_iregex_option_match(self):
  121. self.assertRaises(ValueError, salt.utils.find.IregexOption, "name", "(.*}")
  122. option = salt.utils.find.IregexOption("name", r".*\.txt")
  123. self.assertIs(option.match("", "", ""), None)
  124. self.assertIs(option.match("", "hello.txt", "").group(), "hello.txt")
  125. self.assertIs(option.match("", "HELLO.TXT", "").group(), "HELLO.TXT")
  126. def test_type_option_requires(self):
  127. self.assertRaises(ValueError, salt.utils.find.TypeOption, "type", "w")
  128. option = salt.utils.find.TypeOption("type", "d")
  129. self.assertEqual(option.requires(), salt.utils.find._REQUIRES_STAT)
  130. def test_type_option_match(self):
  131. option = salt.utils.find.TypeOption("type", "b")
  132. self.assertEqual(option.match("", "", [stat.S_IFREG]), False)
  133. option = salt.utils.find.TypeOption("type", "c")
  134. self.assertEqual(option.match("", "", [stat.S_IFREG]), False)
  135. option = salt.utils.find.TypeOption("type", "d")
  136. self.assertEqual(option.match("", "", [stat.S_IFREG]), False)
  137. option = salt.utils.find.TypeOption("type", "f")
  138. self.assertEqual(option.match("", "", [stat.S_IFREG]), True)
  139. option = salt.utils.find.TypeOption("type", "l")
  140. self.assertEqual(option.match("", "", [stat.S_IFREG]), False)
  141. option = salt.utils.find.TypeOption("type", "p")
  142. self.assertEqual(option.match("", "", [stat.S_IFREG]), False)
  143. option = salt.utils.find.TypeOption("type", "s")
  144. self.assertEqual(option.match("", "", [stat.S_IFREG]), False)
  145. option = salt.utils.find.TypeOption("type", "b")
  146. self.assertEqual(option.match("", "", [stat.S_IFBLK]), True)
  147. option = salt.utils.find.TypeOption("type", "c")
  148. self.assertEqual(option.match("", "", [stat.S_IFCHR]), True)
  149. option = salt.utils.find.TypeOption("type", "d")
  150. self.assertEqual(option.match("", "", [stat.S_IFDIR]), True)
  151. option = salt.utils.find.TypeOption("type", "l")
  152. self.assertEqual(option.match("", "", [stat.S_IFLNK]), True)
  153. option = salt.utils.find.TypeOption("type", "p")
  154. self.assertEqual(option.match("", "", [stat.S_IFIFO]), True)
  155. option = salt.utils.find.TypeOption("type", "s")
  156. self.assertEqual(option.match("", "", [stat.S_IFSOCK]), True)
  157. @skipIf(sys.platform.startswith("win"), "pwd not available on Windows")
  158. def test_owner_option_requires(self):
  159. self.assertRaises(ValueError, salt.utils.find.OwnerOption, "owner", "notexist")
  160. option = salt.utils.find.OwnerOption("owner", "root")
  161. self.assertEqual(option.requires(), salt.utils.find._REQUIRES_STAT)
  162. @skipIf(sys.platform.startswith("win"), "pwd not available on Windows")
  163. def test_owner_option_match(self):
  164. option = salt.utils.find.OwnerOption("owner", "root")
  165. self.assertEqual(option.match("", "", [0] * 5), True)
  166. option = salt.utils.find.OwnerOption("owner", "500")
  167. self.assertEqual(option.match("", "", [500] * 5), True)
  168. @skipIf(sys.platform.startswith("win"), "grp not available on Windows")
  169. def test_group_option_requires(self):
  170. self.assertRaises(ValueError, salt.utils.find.GroupOption, "group", "notexist")
  171. if sys.platform.startswith(("darwin", "freebsd", "openbsd")):
  172. group_name = "wheel"
  173. else:
  174. group_name = "root"
  175. option = salt.utils.find.GroupOption("group", group_name)
  176. self.assertEqual(option.requires(), salt.utils.find._REQUIRES_STAT)
  177. @skipIf(sys.platform.startswith("win"), "grp not available on Windows")
  178. def test_group_option_match(self):
  179. if sys.platform.startswith(("darwin", "freebsd", "openbsd")):
  180. group_name = "wheel"
  181. else:
  182. group_name = "root"
  183. option = salt.utils.find.GroupOption("group", group_name)
  184. self.assertEqual(option.match("", "", [0] * 6), True)
  185. option = salt.utils.find.GroupOption("group", "500")
  186. self.assertEqual(option.match("", "", [500] * 6), True)
  187. def test_size_option_requires(self):
  188. self.assertRaises(ValueError, salt.utils.find.SizeOption, "size", "1s1s")
  189. option = salt.utils.find.SizeOption("size", "+1G")
  190. self.assertEqual(option.requires(), salt.utils.find._REQUIRES_STAT)
  191. def test_size_option_match(self):
  192. option = salt.utils.find.SizeOption("size", "+1k")
  193. self.assertEqual(option.match("", "", [10000] * 7), True)
  194. option = salt.utils.find.SizeOption("size", "+1G")
  195. self.assertEqual(option.match("", "", [10000] * 7), False)
  196. def test_mtime_option_requires(self):
  197. self.assertRaises(ValueError, salt.utils.find.MtimeOption, "mtime", "4g")
  198. option = salt.utils.find.MtimeOption("mtime", "1d")
  199. self.assertEqual(option.requires(), salt.utils.find._REQUIRES_STAT)
  200. def test_mtime_option_match(self):
  201. option = salt.utils.find.MtimeOption("mtime", "-1w")
  202. self.assertEqual(option.match("", "", [1] * 9), False)
  203. option = salt.utils.find.MtimeOption("mtime", "-1s")
  204. self.assertEqual(option.match("", "", [10 ** 10] * 9), True)
  205. class TestGrepOption(TestCase):
  206. def setUp(self):
  207. super(TestGrepOption, self).setUp()
  208. self.tmpdir = tempfile.mkdtemp(dir=RUNTIME_VARS.TMP)
  209. def tearDown(self):
  210. shutil.rmtree(self.tmpdir)
  211. super(TestGrepOption, self).tearDown()
  212. def test_grep_option_requires(self):
  213. self.assertRaises(ValueError, salt.utils.find.GrepOption, "grep", "(foo)|(bar}")
  214. option = salt.utils.find.GrepOption("grep", "(foo)|(bar)")
  215. find = salt.utils.find
  216. self.assertEqual(
  217. option.requires(), (find._REQUIRES_CONTENTS | find._REQUIRES_STAT)
  218. )
  219. def test_grep_option_match_regular_file(self):
  220. hello_file = os.path.join(self.tmpdir, "hello.txt")
  221. with salt.utils.files.fopen(hello_file, "w") as fp_:
  222. fp_.write(salt.utils.stringutils.to_str("foo"))
  223. option = salt.utils.find.GrepOption("grep", "foo")
  224. self.assertEqual(
  225. option.match(self.tmpdir, "hello.txt", os.stat(hello_file)), hello_file
  226. )
  227. option = salt.utils.find.GrepOption("grep", "bar")
  228. self.assertEqual(
  229. option.match(self.tmpdir, "hello.txt", os.stat(hello_file)), None
  230. )
  231. @skipIf(sys.platform.startswith("win"), "No /dev/null on Windows")
  232. def test_grep_option_match_dev_null(self):
  233. option = salt.utils.find.GrepOption("grep", "foo")
  234. self.assertEqual(option.match("dev", "null", os.stat("/dev/null")), None)
  235. class TestPrintOption(TestCase):
  236. def setUp(self):
  237. super(TestPrintOption, self).setUp()
  238. self.tmpdir = tempfile.mkdtemp(dir=RUNTIME_VARS.TMP)
  239. def tearDown(self):
  240. shutil.rmtree(self.tmpdir)
  241. super(TestPrintOption, self).tearDown()
  242. def test_print_option_defaults(self):
  243. option = salt.utils.find.PrintOption("print", "")
  244. self.assertEqual(option.need_stat, False)
  245. self.assertEqual(option.print_title, False)
  246. self.assertEqual(option.fmt, ["path"])
  247. def test_print_option_requires(self):
  248. option = salt.utils.find.PrintOption("print", "")
  249. self.assertEqual(option.requires(), salt.utils.find._REQUIRES_PATH)
  250. option = salt.utils.find.PrintOption("print", "name")
  251. self.assertEqual(option.requires(), salt.utils.find._REQUIRES_PATH)
  252. option = salt.utils.find.PrintOption("print", "path")
  253. self.assertEqual(option.requires(), salt.utils.find._REQUIRES_PATH)
  254. option = salt.utils.find.PrintOption("print", "name,path")
  255. self.assertEqual(option.requires(), salt.utils.find._REQUIRES_PATH)
  256. option = salt.utils.find.PrintOption("print", "user")
  257. self.assertEqual(option.requires(), salt.utils.find._REQUIRES_STAT)
  258. option = salt.utils.find.PrintOption("print", "path user")
  259. self.assertEqual(option.requires(), salt.utils.find._REQUIRES_STAT)
  260. def test_print_option_execute(self):
  261. hello_file = os.path.join(self.tmpdir, "hello.txt")
  262. with salt.utils.files.fopen(hello_file, "w") as fp_:
  263. fp_.write(salt.utils.stringutils.to_str("foo"))
  264. option = salt.utils.find.PrintOption("print", "")
  265. self.assertEqual(option.execute("", [0] * 9), "")
  266. option = salt.utils.find.PrintOption("print", "path")
  267. self.assertEqual(option.execute("test_name", [0] * 9), "test_name")
  268. option = salt.utils.find.PrintOption("print", "name")
  269. self.assertEqual(option.execute("test_name", [0] * 9), "test_name")
  270. option = salt.utils.find.PrintOption("print", "size")
  271. self.assertEqual(option.execute(hello_file, os.stat(hello_file)), 3)
  272. option = salt.utils.find.PrintOption("print", "type")
  273. self.assertEqual(option.execute(hello_file, os.stat(hello_file)), "f")
  274. option = salt.utils.find.PrintOption("print", "mode")
  275. self.assertEqual(option.execute(hello_file, range(10)), 0)
  276. option = salt.utils.find.PrintOption("print", "mtime")
  277. self.assertEqual(option.execute(hello_file, range(10)), 8)
  278. option = salt.utils.find.PrintOption("print", "md5")
  279. self.assertEqual(
  280. option.execute(hello_file, os.stat(hello_file)),
  281. "acbd18db4cc2f85cedef654fccc4a4d8",
  282. )
  283. option = salt.utils.find.PrintOption("print", "path name")
  284. self.assertEqual(
  285. option.execute("test_name", [0] * 9), ["test_name", "test_name"]
  286. )
  287. option = salt.utils.find.PrintOption("print", "size name")
  288. self.assertEqual(option.execute("test_name", [0] * 9), [0, "test_name"])
  289. @skipIf(sys.platform.startswith("win"), "pwd not available on Windows")
  290. def test_print_user(self):
  291. option = salt.utils.find.PrintOption("print", "user")
  292. self.assertEqual(option.execute("", [0] * 10), "root")
  293. option = salt.utils.find.PrintOption("print", "user")
  294. self.assertEqual(option.execute("", [2 ** 31] * 10), 2 ** 31)
  295. @skipIf(sys.platform.startswith("win"), "grp not available on Windows")
  296. def test_print_group(self):
  297. option = salt.utils.find.PrintOption("print", "group")
  298. if sys.platform.startswith(("darwin", "freebsd", "openbsd")):
  299. group_name = "wheel"
  300. else:
  301. group_name = "root"
  302. self.assertEqual(option.execute("", [0] * 10), group_name)
  303. # This seems to be not working in Ubuntu 12.04 32 bit
  304. # option = salt.utils.find.PrintOption('print', 'group')
  305. # self.assertEqual(option.execute('', [2 ** 31] * 10), 2 ** 31)
  306. @skipIf(sys.platform.startswith("win"), "no /dev/null on windows")
  307. def test_print_md5(self):
  308. option = salt.utils.find.PrintOption("print", "md5")
  309. self.assertEqual(option.execute("/dev/null", os.stat("/dev/null")), "")
  310. class TestFinder(TestCase):
  311. def setUp(self):
  312. super(TestFinder, self).setUp()
  313. self.tmpdir = tempfile.mkdtemp(dir=RUNTIME_VARS.TMP)
  314. def tearDown(self):
  315. shutil.rmtree(self.tmpdir)
  316. super(TestFinder, self).tearDown()
  317. @skipIf(sys.platform.startswith("win"), "No /dev/null on Windows")
  318. def test_init(self):
  319. finder = salt.utils.find.Finder({})
  320. self.assertEqual(
  321. six.text_type(finder.actions[0].__class__)[-13:-2], "PrintOption"
  322. )
  323. self.assertEqual(finder.criteria, [])
  324. finder = salt.utils.find.Finder({"_": None})
  325. self.assertEqual(
  326. six.text_type(finder.actions[0].__class__)[-13:-2], "PrintOption"
  327. )
  328. self.assertEqual(finder.criteria, [])
  329. self.assertRaises(ValueError, salt.utils.find.Finder, {"": None})
  330. self.assertRaises(ValueError, salt.utils.find.Finder, {"name": None})
  331. self.assertRaises(ValueError, salt.utils.find.Finder, {"nonexist": "somevalue"})
  332. finder = salt.utils.find.Finder({"name": "test_name"})
  333. self.assertEqual(
  334. six.text_type(finder.actions[0].__class__)[-13:-2], "PrintOption"
  335. )
  336. self.assertEqual(
  337. six.text_type(finder.criteria[0].__class__)[-12:-2], "NameOption"
  338. )
  339. finder = salt.utils.find.Finder({"iname": "test_name"})
  340. self.assertEqual(
  341. six.text_type(finder.actions[0].__class__)[-13:-2], "PrintOption"
  342. )
  343. self.assertEqual(
  344. six.text_type(finder.criteria[0].__class__)[-13:-2], "InameOption"
  345. )
  346. finder = salt.utils.find.Finder({"regex": r".*\.txt"})
  347. self.assertEqual(
  348. six.text_type(finder.actions[0].__class__)[-13:-2], "PrintOption"
  349. )
  350. self.assertEqual(
  351. six.text_type(finder.criteria[0].__class__)[-13:-2], "RegexOption"
  352. )
  353. finder = salt.utils.find.Finder({"iregex": r".*\.txt"})
  354. self.assertEqual(
  355. six.text_type(finder.actions[0].__class__)[-13:-2], "PrintOption"
  356. )
  357. self.assertEqual(
  358. six.text_type(finder.criteria[0].__class__)[-14:-2], "IregexOption"
  359. )
  360. finder = salt.utils.find.Finder({"type": "d"})
  361. self.assertEqual(
  362. six.text_type(finder.actions[0].__class__)[-13:-2], "PrintOption"
  363. )
  364. self.assertEqual(
  365. six.text_type(finder.criteria[0].__class__)[-12:-2], "TypeOption"
  366. )
  367. finder = salt.utils.find.Finder({"owner": "root"})
  368. self.assertEqual(
  369. six.text_type(finder.actions[0].__class__)[-13:-2], "PrintOption"
  370. )
  371. self.assertEqual(
  372. six.text_type(finder.criteria[0].__class__)[-13:-2], "OwnerOption"
  373. )
  374. if sys.platform.startswith(("darwin", "freebsd", "openbsd")):
  375. group_name = "wheel"
  376. else:
  377. group_name = "root"
  378. finder = salt.utils.find.Finder({"group": group_name})
  379. self.assertEqual(
  380. six.text_type(finder.actions[0].__class__)[-13:-2], "PrintOption"
  381. )
  382. self.assertEqual(
  383. six.text_type(finder.criteria[0].__class__)[-13:-2], "GroupOption"
  384. )
  385. finder = salt.utils.find.Finder({"size": "+1G"})
  386. self.assertEqual(
  387. six.text_type(finder.actions[0].__class__)[-13:-2], "PrintOption"
  388. )
  389. self.assertEqual(
  390. six.text_type(finder.criteria[0].__class__)[-12:-2], "SizeOption"
  391. )
  392. finder = salt.utils.find.Finder({"mtime": "1d"})
  393. self.assertEqual(
  394. six.text_type(finder.actions[0].__class__)[-13:-2], "PrintOption"
  395. )
  396. self.assertEqual(
  397. six.text_type(finder.criteria[0].__class__)[-13:-2], "MtimeOption"
  398. )
  399. finder = salt.utils.find.Finder({"grep": "foo"})
  400. self.assertEqual(
  401. six.text_type(finder.actions[0].__class__)[-13:-2], "PrintOption"
  402. )
  403. self.assertEqual(
  404. six.text_type(finder.criteria[0].__class__)[-12:-2], "GrepOption"
  405. )
  406. finder = salt.utils.find.Finder({"print": "name"})
  407. self.assertEqual(
  408. six.text_type(finder.actions[0].__class__)[-13:-2], "PrintOption"
  409. )
  410. self.assertEqual(finder.criteria, [])
  411. def test_find(self):
  412. hello_file = os.path.join(self.tmpdir, "hello.txt")
  413. with salt.utils.files.fopen(hello_file, "w") as fp_:
  414. fp_.write(salt.utils.stringutils.to_str("foo"))
  415. finder = salt.utils.find.Finder({})
  416. self.assertEqual(list(finder.find(self.tmpdir)), [self.tmpdir, hello_file])
  417. finder = salt.utils.find.Finder({"mindepth": 1})
  418. self.assertEqual(list(finder.find(self.tmpdir)), [hello_file])
  419. finder = salt.utils.find.Finder({"maxdepth": 0})
  420. self.assertEqual(list(finder.find(self.tmpdir)), [self.tmpdir])
  421. finder = salt.utils.find.Finder({"name": "hello.txt"})
  422. self.assertEqual(list(finder.find(self.tmpdir)), [hello_file])
  423. finder = salt.utils.find.Finder({"type": "f", "print": "path"})
  424. self.assertEqual(list(finder.find(self.tmpdir)), [hello_file])
  425. finder = salt.utils.find.Finder({"size": "+1G", "print": "path"})
  426. self.assertEqual(list(finder.find(self.tmpdir)), [])
  427. finder = salt.utils.find.Finder({"name": "hello.txt", "print": "path name"})
  428. self.assertEqual(list(finder.find(self.tmpdir)), [[hello_file, "hello.txt"]])
  429. finder = salt.utils.find.Finder({"name": "test_name"})
  430. self.assertEqual(list(finder.find("")), [])