test_helm.py 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677
  1. # -*- coding: utf-8 -*-
  2. # Import Python libs
  3. from __future__ import absolute_import, print_function, unicode_literals
  4. # Import Salt Libs
  5. import salt.modules.helm as helm
  6. # Import Exception
  7. from salt.exceptions import CommandExecutionError
  8. # Import Salt Testing Libs
  9. from tests.support.mixins import LoaderModuleMockMixin
  10. from tests.support.mock import MagicMock, call, patch
  11. from tests.support.unit import TestCase
  12. class HelmTestCase(TestCase, LoaderModuleMockMixin):
  13. """
  14. Test cases for salt.modules.helm
  15. """
  16. def setup_loader_modules(self):
  17. return {helm: {}}
  18. def test__prepare_cmd(self):
  19. self.assertEqual(helm._prepare_cmd(), ("helm",))
  20. def test__prepare_cmd_binary(self):
  21. self.assertEqual(helm._prepare_cmd(binary="binary"), ("binary",))
  22. def test__prepare_cmd_commands(self):
  23. self.assertEqual(
  24. helm._prepare_cmd(commands=["com1", "com2"]), ("helm", "com1", "com2",)
  25. )
  26. def test__prepare_cmd_flags(self):
  27. self.assertEqual(
  28. helm._prepare_cmd(flags=["flag1", "--flag2"]),
  29. ("helm", "--flag1", "--flag2",),
  30. )
  31. def test__prepare_cmd_kvflags(self):
  32. result_tuple = helm._prepare_cmd(
  33. kvflags={"kflag1": "vflag1", "--kflag2": "vflag2"}
  34. )
  35. tuple_valide_1 = (
  36. "helm",
  37. "--kflag1",
  38. "vflag1",
  39. "--kflag2",
  40. "vflag2",
  41. )
  42. tuple_valide_2 = (
  43. "helm",
  44. "--kflag2",
  45. "vflag2",
  46. "--kflag1",
  47. "vflag1",
  48. )
  49. #
  50. self.assertEqual(
  51. True, result_tuple == tuple_valide_1 or result_tuple == tuple_valide_2
  52. )
  53. def test__exec_cmd(self):
  54. cmd_prepare = helm._prepare_cmd()
  55. cmd_prepare_str = " ".join(cmd_prepare)
  56. cmd_return = {
  57. "stdout": "succes",
  58. "stderr": "",
  59. "retcode": 0,
  60. }
  61. result = cmd_return
  62. result.update({"cmd": cmd_prepare_str})
  63. with patch.dict(
  64. helm.__salt__,
  65. { # pylint: disable=no-member
  66. "cmd.run_all": MagicMock(return_value=cmd_return)
  67. },
  68. ):
  69. self.assertEqual(helm._exec_cmd(), result)
  70. def test__exec_true_return_valid(self):
  71. _exec_cmd_return = {"retcode": 0}
  72. with patch(
  73. "salt.modules.helm._exec_cmd", MagicMock(return_value=_exec_cmd_return)
  74. ):
  75. self.assertEqual(True, helm._exec_true_return())
  76. def test__exec_true_return_not_valid(self):
  77. _exec_cmd_return = {"retcode": -1, "stderr": "test"}
  78. with patch(
  79. "salt.modules.helm._exec_cmd", MagicMock(return_value=_exec_cmd_return)
  80. ):
  81. self.assertEqual("test", helm._exec_true_return())
  82. def test__exec_string_return_valid(self):
  83. _exec_cmd_return = {"retcode": 0, "stdout": "test"}
  84. with patch(
  85. "salt.modules.helm._exec_cmd", MagicMock(return_value=_exec_cmd_return)
  86. ):
  87. self.assertEqual("test", helm._exec_string_return())
  88. def test__exec_string_return_not_valid(self):
  89. _exec_cmd_return = {"retcode": -1, "stderr": "test"}
  90. with patch(
  91. "salt.modules.helm._exec_cmd", MagicMock(return_value=_exec_cmd_return)
  92. ):
  93. self.assertEqual("test", helm._exec_string_return())
  94. def test__exec_dict_return_valide(self):
  95. _exec_cmd_return = {"retcode": 0, "stdout": '{"test": true}'}
  96. with patch(
  97. "salt.modules.helm._exec_cmd", MagicMock(return_value=_exec_cmd_return)
  98. ):
  99. self.assertEqual({"test": True}, helm._exec_dict_return())
  100. def test__exec_dict_return_valide_no_json(self):
  101. _exec_cmd_return = {"retcode": 0, "stdout": '{"test": true}'}
  102. with patch(
  103. "salt.modules.helm._exec_cmd", MagicMock(return_value=_exec_cmd_return)
  104. ):
  105. self.assertEqual(
  106. '{"test": true}', helm._exec_dict_return(kvflags={"output": "table"})
  107. )
  108. def test__exec_dict_return_not_valid(self):
  109. _exec_cmd_return = {"retcode": -1, "stderr": "test"}
  110. with patch(
  111. "salt.modules.helm._exec_cmd", MagicMock(return_value=_exec_cmd_return)
  112. ):
  113. self.assertEqual("test", helm._exec_dict_return())
  114. def test_completion(self):
  115. magic_mock = MagicMock(return_value="the_return")
  116. with patch("salt.modules.helm._exec_string_return", magic_mock):
  117. self.assertEqual("the_return", helm.completion("bash"))
  118. self.assertEqual(
  119. [call(commands=["completion", "bash"], flags=None, kvflags=None)],
  120. magic_mock.mock_calls,
  121. )
  122. def test_create(self):
  123. magic_mock = MagicMock(return_value=True)
  124. with patch("salt.modules.helm._exec_true_return", magic_mock):
  125. self.assertEqual(True, helm.create("name"))
  126. self.assertEqual(
  127. [call(commands=["create", "name"], flags=None, kvflags=None)],
  128. magic_mock.mock_calls,
  129. )
  130. def test_dependency_build(self):
  131. magic_mock = MagicMock(return_value=True)
  132. with patch("salt.modules.helm._exec_true_return", magic_mock):
  133. self.assertEqual(True, helm.dependency_build("chart"))
  134. self.assertEqual(
  135. [
  136. call(
  137. commands=["dependency", "build", "chart"],
  138. flags=None,
  139. kvflags=None,
  140. )
  141. ],
  142. magic_mock.mock_calls,
  143. )
  144. def test_dependency_list(self):
  145. magic_mock = MagicMock(return_value="the_return")
  146. with patch("salt.modules.helm._exec_string_return", magic_mock):
  147. self.assertEqual("the_return", helm.dependency_list("chart"))
  148. self.assertEqual(
  149. [
  150. call(
  151. commands=["dependency", "list", "chart"],
  152. flags=None,
  153. kvflags=None,
  154. )
  155. ],
  156. magic_mock.mock_calls,
  157. )
  158. def test_dependency_update(self):
  159. magic_mock = MagicMock(return_value=True)
  160. with patch("salt.modules.helm._exec_true_return", magic_mock):
  161. self.assertEqual(True, helm.dependency_update("chart"))
  162. self.assertEqual(
  163. [
  164. call(
  165. commands=["dependency", "update", "chart"],
  166. flags=None,
  167. kvflags=None,
  168. )
  169. ],
  170. magic_mock.mock_calls,
  171. )
  172. def test_env(self):
  173. magic_mock = MagicMock(return_value="the_return")
  174. with patch("salt.modules.helm._exec_string_return", magic_mock):
  175. self.assertEqual("the_return", helm.env())
  176. self.assertEqual(
  177. [call(commands=["env"], flags=None, kvflags=None)],
  178. magic_mock.mock_calls,
  179. )
  180. def test_get_all(self):
  181. magic_mock = MagicMock(return_value="the_return")
  182. with patch("salt.modules.helm._exec_string_return", magic_mock):
  183. self.assertEqual("the_return", helm.get_all("release"))
  184. self.assertEqual(
  185. [call(commands=["get", "all", "release"], flags=None, kvflags=None)],
  186. magic_mock.mock_calls,
  187. )
  188. def test_get_hooks(self):
  189. magic_mock = MagicMock(return_value="the_return")
  190. with patch("salt.modules.helm._exec_string_return", magic_mock):
  191. self.assertEqual("the_return", helm.get_hooks("release"))
  192. self.assertEqual(
  193. [call(commands=["get", "hooks", "release"], flags=None, kvflags=None)],
  194. magic_mock.mock_calls,
  195. )
  196. def test_get_manifest(self):
  197. magic_mock = MagicMock(return_value="the_return")
  198. with patch("salt.modules.helm._exec_string_return", magic_mock):
  199. self.assertEqual("the_return", helm.get_manifest("release"))
  200. self.assertEqual(
  201. [
  202. call(
  203. commands=["get", "manifest", "release"],
  204. flags=None,
  205. kvflags=None,
  206. )
  207. ],
  208. magic_mock.mock_calls,
  209. )
  210. def test_get_notes(self):
  211. magic_mock = MagicMock(return_value="the_return")
  212. with patch("salt.modules.helm._exec_string_return", magic_mock):
  213. self.assertEqual("the_return", helm.get_notes("release"))
  214. self.assertEqual(
  215. [call(commands=["get", "notes", "release"], flags=None, kvflags=None)],
  216. magic_mock.mock_calls,
  217. )
  218. def test_get_values(self):
  219. magic_mock = MagicMock(return_value={"test": True})
  220. with patch("salt.modules.helm._exec_dict_return", magic_mock):
  221. self.assertEqual({"test": True}, helm.get_values("release"))
  222. self.assertEqual(
  223. [call(commands=["get", "values", "release"], flags=None, kvflags=None)],
  224. magic_mock.mock_calls,
  225. )
  226. def test_help_(self):
  227. magic_mock = MagicMock(return_value="the_return")
  228. with patch("salt.modules.helm._exec_string_return", magic_mock):
  229. self.assertEqual("the_return", helm.help_("command"))
  230. self.assertEqual(
  231. [call(commands=["help", "command"], flags=None, kvflags=None)],
  232. magic_mock.mock_calls,
  233. )
  234. def test_history(self):
  235. magic_mock = MagicMock(return_value={"test": True})
  236. with patch("salt.modules.helm._exec_dict_return", magic_mock):
  237. self.assertEqual({"test": True}, helm.history("release"))
  238. self.assertEqual(
  239. [call(commands=["history", "release"], flags=None, kvflags=None)],
  240. magic_mock.mock_calls,
  241. )
  242. def test_install(self):
  243. magic_mock = MagicMock(return_value=True)
  244. with patch("salt.modules.helm._exec_true_return", magic_mock):
  245. self.assertEqual(True, helm.install("release", "chart"))
  246. self.assertEqual(
  247. [
  248. call(
  249. commands=["install", "release", "chart"],
  250. flags=None,
  251. kvflags=None,
  252. )
  253. ],
  254. magic_mock.mock_calls,
  255. )
  256. def test_lint(self):
  257. magic_mock = MagicMock(return_value=True)
  258. with patch("salt.modules.helm._exec_true_return", magic_mock):
  259. self.assertEqual(True, helm.lint("path"))
  260. self.assertEqual(
  261. [call(commands=["lint", "path"], flags=None, kvflags=None)],
  262. magic_mock.mock_calls,
  263. )
  264. def test_list_(self):
  265. magic_mock = MagicMock(return_value={"test": True})
  266. with patch("salt.modules.helm._exec_dict_return", magic_mock):
  267. self.assertEqual({"test": True}, helm.list_())
  268. self.assertEqual(
  269. [call(commands=["list"], flags=None, kvflags=None)],
  270. magic_mock.mock_calls,
  271. )
  272. def test_package(self):
  273. magic_mock = MagicMock(return_value=True)
  274. with patch("salt.modules.helm._exec_true_return", magic_mock):
  275. self.assertEqual(True, helm.package("chart"))
  276. self.assertEqual(
  277. [call(commands=["package", "chart"], flags=None, kvflags=None)],
  278. magic_mock.mock_calls,
  279. )
  280. def test_plugin_install(self):
  281. magic_mock = MagicMock(return_value=True)
  282. with patch("salt.modules.helm._exec_true_return", magic_mock):
  283. self.assertEqual(True, helm.plugin_install("path"))
  284. self.assertEqual(
  285. [
  286. call(
  287. commands=["plugin", "install", "path"], flags=None, kvflags=None
  288. )
  289. ],
  290. magic_mock.mock_calls,
  291. )
  292. def test_plugin_list(self):
  293. magic_mock = MagicMock(return_value="the_return")
  294. with patch("salt.modules.helm._exec_string_return", magic_mock):
  295. self.assertEqual("the_return", helm.plugin_list())
  296. self.assertEqual(
  297. [call(commands=["plugin", "list"], flags=None, kvflags=None)],
  298. magic_mock.mock_calls,
  299. )
  300. def test_plugin_uninstall(self):
  301. magic_mock = MagicMock(return_value=True)
  302. with patch("salt.modules.helm._exec_true_return", magic_mock):
  303. self.assertEqual(True, helm.plugin_uninstall("plugin"))
  304. self.assertEqual(
  305. [
  306. call(
  307. commands=["plugin", "uninstall", "plugin"],
  308. flags=None,
  309. kvflags=None,
  310. )
  311. ],
  312. magic_mock.mock_calls,
  313. )
  314. def test_plugin_update(self):
  315. magic_mock = MagicMock(return_value=True)
  316. with patch("salt.modules.helm._exec_true_return", magic_mock):
  317. self.assertEqual(True, helm.plugin_update("plugin"))
  318. self.assertEqual(
  319. [
  320. call(
  321. commands=["plugin", "update", "plugin"],
  322. flags=None,
  323. kvflags=None,
  324. )
  325. ],
  326. magic_mock.mock_calls,
  327. )
  328. def test_pull(self):
  329. magic_mock = MagicMock(return_value=True)
  330. with patch("salt.modules.helm._exec_true_return", magic_mock):
  331. self.assertEqual(True, helm.pull("pkg"))
  332. self.assertEqual(
  333. [call(commands=["pull", "pkg"], flags=None, kvflags=None)],
  334. magic_mock.mock_calls,
  335. )
  336. def test_repo_add(self):
  337. magic_mock = MagicMock(return_value=True)
  338. with patch("salt.modules.helm._exec_true_return", magic_mock):
  339. self.assertEqual(True, helm.repo_add("name", "url"))
  340. self.assertEqual(
  341. [
  342. call(
  343. commands=["repo", "add", "name", "url"],
  344. flags=None,
  345. kvflags=None,
  346. )
  347. ],
  348. magic_mock.mock_calls,
  349. )
  350. def test_repo_index(self):
  351. magic_mock = MagicMock(return_value=True)
  352. with patch("salt.modules.helm._exec_true_return", magic_mock):
  353. self.assertEqual(True, helm.repo_index("directory"))
  354. self.assertEqual(
  355. [
  356. call(
  357. commands=["repo", "index", "directory"],
  358. flags=None,
  359. kvflags=None,
  360. )
  361. ],
  362. magic_mock.mock_calls,
  363. )
  364. def test_repo_list(self):
  365. magic_mock = MagicMock(return_value={"test": True})
  366. with patch("salt.modules.helm._exec_dict_return", magic_mock):
  367. self.assertEqual({"test": True}, helm.repo_list())
  368. self.assertEqual(
  369. [call(commands=["repo", "list"], flags=None, kvflags=None)],
  370. magic_mock.mock_calls,
  371. )
  372. def test_repo_remove(self):
  373. magic_mock = MagicMock(return_value=True)
  374. with patch("salt.modules.helm._exec_true_return", magic_mock):
  375. self.assertEqual(True, helm.repo_remove("name"))
  376. self.assertEqual(
  377. [call(commands=["repo", "remove", "name"], flags=None, kvflags=None)],
  378. magic_mock.mock_calls,
  379. )
  380. def test_repo_update(self):
  381. magic_mock = MagicMock(return_value=True)
  382. with patch("salt.modules.helm._exec_true_return", magic_mock):
  383. self.assertEqual(True, helm.repo_update())
  384. self.assertEqual(
  385. [call(commands=["repo", "update"], flags=None, kvflags=None)],
  386. magic_mock.mock_calls,
  387. )
  388. def test_repo_manage_present_bad_list(self):
  389. with patch("salt.modules.helm.repo_list", MagicMock(return_value=None)):
  390. with self.assertRaises(CommandExecutionError):
  391. helm.repo_manage(present=["test"])
  392. def test_repo_manage_present_bad_format(self):
  393. with patch("salt.modules.helm.repo_list", MagicMock(return_value=None)):
  394. with self.assertRaises(CommandExecutionError):
  395. helm.repo_manage(present=[{"test": True}])
  396. def test_repo_manage_present_failed(self):
  397. result_wanted = {
  398. "present": [],
  399. "added": [],
  400. "absent": [],
  401. "removed": [],
  402. "failed": [{"name": "myname", "url": "myurl"}],
  403. }
  404. with patch("salt.modules.helm.repo_list", MagicMock(return_value=None)):
  405. with patch("salt.modules.helm.repo_add", MagicMock(return_value="failed")):
  406. self.assertEqual(
  407. helm.repo_manage(present=[{"name": "myname", "url": "myurl"}]),
  408. result_wanted,
  409. )
  410. def test_repo_manage_present_succeed(self):
  411. result_wanted = {
  412. "present": [],
  413. "added": [{"name": "myname", "url": "myurl"}],
  414. "absent": [],
  415. "removed": [],
  416. "failed": [],
  417. }
  418. with patch("salt.modules.helm.repo_list", MagicMock(return_value=None)):
  419. with patch("salt.modules.helm.repo_add", MagicMock(return_value=True)):
  420. self.assertEqual(
  421. helm.repo_manage(present=[{"name": "myname", "url": "myurl"}]),
  422. result_wanted,
  423. )
  424. def test_repo_manage_present_already_present(self):
  425. result_wanted = {
  426. "present": [{"name": "myname", "url": "myurl"}],
  427. "added": [],
  428. "absent": [],
  429. "removed": [],
  430. "failed": [],
  431. }
  432. with patch(
  433. "salt.modules.helm.repo_list",
  434. MagicMock(return_value=[{"name": "myname", "url": "myurl"}]),
  435. ):
  436. self.assertEqual(
  437. helm.repo_manage(present=[{"name": "myname", "url": "myurl"}]),
  438. result_wanted,
  439. )
  440. def test_repo_manage_prune(self):
  441. result_wanted = {
  442. "present": [],
  443. "added": [],
  444. "absent": [],
  445. "removed": ["myname"],
  446. "failed": [],
  447. }
  448. with patch(
  449. "salt.modules.helm.repo_list",
  450. MagicMock(return_value=[{"name": "myname", "url": "myurl"}]),
  451. ):
  452. with patch("salt.modules.helm.repo_remove", MagicMock(return_value=True)):
  453. self.assertEqual(helm.repo_manage(prune=True), result_wanted)
  454. def test_repo_manage_absent(self):
  455. result_wanted = {
  456. "present": [],
  457. "added": [],
  458. "absent": ["myname"],
  459. "removed": [],
  460. "failed": [],
  461. }
  462. with patch("salt.modules.helm.repo_list", MagicMock(return_value=None)):
  463. with patch("salt.modules.helm.repo_remove", MagicMock(return_value=False)):
  464. self.assertEqual(helm.repo_manage(absent=["myname"]), result_wanted)
  465. def test_repo_manage_removed(self):
  466. result_wanted = {
  467. "present": [],
  468. "added": [],
  469. "absent": [],
  470. "removed": ["myname"],
  471. "failed": [],
  472. }
  473. with patch("salt.modules.helm.repo_list", MagicMock(return_value=None)):
  474. with patch("salt.modules.helm.repo_remove", MagicMock(return_value=True)):
  475. self.assertEqual(helm.repo_manage(absent=["myname"]), result_wanted)
  476. def test_rollback(self):
  477. magic_mock = MagicMock(return_value=True)
  478. with patch("salt.modules.helm._exec_true_return", magic_mock):
  479. self.assertEqual(True, helm.rollback("release", "revision"))
  480. self.assertEqual(
  481. [
  482. call(
  483. commands=["rollback", "release", "revision"],
  484. flags=None,
  485. kvflags=None,
  486. )
  487. ],
  488. magic_mock.mock_calls,
  489. )
  490. def test_search_hub(self):
  491. magic_mock = MagicMock(return_value={"test": True})
  492. with patch("salt.modules.helm._exec_dict_return", magic_mock):
  493. self.assertEqual({"test": True}, helm.search_hub("keyword"))
  494. self.assertEqual(
  495. [call(commands=["search", "hub", "keyword"], flags=None, kvflags=None)],
  496. magic_mock.mock_calls,
  497. )
  498. def test_search_repo(self):
  499. magic_mock = MagicMock(return_value={"test": True})
  500. with patch("salt.modules.helm._exec_dict_return", magic_mock):
  501. self.assertEqual({"test": True}, helm.search_repo("keyword"))
  502. self.assertEqual(
  503. [
  504. call(
  505. commands=["search", "repo", "keyword"], flags=None, kvflags=None
  506. )
  507. ],
  508. magic_mock.mock_calls,
  509. )
  510. def test_show_all(self):
  511. magic_mock = MagicMock(return_value="the_return")
  512. with patch("salt.modules.helm._exec_string_return", magic_mock):
  513. self.assertEqual("the_return", helm.show_all("chart"))
  514. self.assertEqual(
  515. [call(commands=["show", "all", "chart"], flags=None, kvflags=None)],
  516. magic_mock.mock_calls,
  517. )
  518. def test_show_chart(self):
  519. magic_mock = MagicMock(return_value="the_return")
  520. with patch("salt.modules.helm._exec_string_return", magic_mock):
  521. self.assertEqual("the_return", helm.show_chart("chart"))
  522. self.assertEqual(
  523. [call(commands=["show", "chart", "chart"], flags=None, kvflags=None)],
  524. magic_mock.mock_calls,
  525. )
  526. def test_show_readme(self):
  527. magic_mock = MagicMock(return_value="the_return")
  528. with patch("salt.modules.helm._exec_string_return", magic_mock):
  529. self.assertEqual("the_return", helm.show_readme("chart"))
  530. self.assertEqual(
  531. [call(commands=["show", "readme", "chart"], flags=None, kvflags=None)],
  532. magic_mock.mock_calls,
  533. )
  534. def test_show_values(self):
  535. magic_mock = MagicMock(return_value="the_return")
  536. with patch("salt.modules.helm._exec_string_return", magic_mock):
  537. self.assertEqual("the_return", helm.show_values("chart"))
  538. self.assertEqual(
  539. [call(commands=["show", "values", "chart"], flags=None, kvflags=None)],
  540. magic_mock.mock_calls,
  541. )
  542. def test_status(self):
  543. magic_mock = MagicMock(return_value={"test": True})
  544. with patch("salt.modules.helm._exec_dict_return", magic_mock):
  545. self.assertEqual({"test": True}, helm.status("release"))
  546. self.assertEqual(
  547. [call(commands=["status", "release"], flags=None, kvflags=None)],
  548. magic_mock.mock_calls,
  549. )
  550. def test_template(self):
  551. magic_mock = MagicMock(return_value="the_return")
  552. with patch("salt.modules.helm._exec_string_return", magic_mock):
  553. self.assertEqual("the_return", helm.template("name", "chart"))
  554. self.assertEqual(
  555. [
  556. call(
  557. commands=["template", "name", "chart"], flags=None, kvflags=None
  558. )
  559. ],
  560. magic_mock.mock_calls,
  561. )
  562. def test_test(self):
  563. magic_mock = MagicMock(return_value="the_return")
  564. with patch("salt.modules.helm._exec_string_return", magic_mock):
  565. self.assertEqual("the_return", helm.test("release"))
  566. self.assertEqual(
  567. [call(commands=["test", "release"], flags=None, kvflags=None)],
  568. magic_mock.mock_calls,
  569. )
  570. def test_uninstall(self):
  571. magic_mock = MagicMock(return_value=True)
  572. with patch("salt.modules.helm._exec_true_return", magic_mock):
  573. self.assertEqual(True, helm.uninstall("release"))
  574. self.assertEqual(
  575. [call(commands=["uninstall", "release"], flags=None, kvflags=None)],
  576. magic_mock.mock_calls,
  577. )
  578. def test_upgrade(self):
  579. magic_mock = MagicMock(return_value=True)
  580. with patch("salt.modules.helm._exec_true_return", magic_mock):
  581. self.assertEqual(True, helm.upgrade("release", "chart"))
  582. self.assertEqual(
  583. [
  584. call(
  585. commands=["upgrade", "release", "chart"],
  586. flags=None,
  587. kvflags=None,
  588. )
  589. ],
  590. magic_mock.mock_calls,
  591. )
  592. def test_verify(self):
  593. magic_mock = MagicMock(return_value=True)
  594. with patch("salt.modules.helm._exec_true_return", magic_mock):
  595. self.assertEqual(True, helm.verify("path"))
  596. self.assertEqual(
  597. [call(commands=["verify", "path"], flags=None, kvflags=None)],
  598. magic_mock.mock_calls,
  599. )
  600. def test_version(self):
  601. magic_mock = MagicMock(return_value="the_return")
  602. with patch("salt.modules.helm._exec_string_return", magic_mock):
  603. self.assertEqual("the_return", helm.version())
  604. self.assertEqual(
  605. [call(commands=["version"], flags=None, kvflags=None)],
  606. magic_mock.mock_calls,
  607. )