From 39584a1273d53d0ef90272e9f167d3571a553f13 Mon Sep 17 00:00:00 2001 From: John Mulligan Date: Thu, 9 May 2024 14:29:28 -0400 Subject: [PATCH] mgr/smb: add test coverage for show command Signed-off-by: John Mulligan --- src/pybind/mgr/smb/tests/test_smb.py | 70 ++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) diff --git a/src/pybind/mgr/smb/tests/test_smb.py b/src/pybind/mgr/smb/tests/test_smb.py index cf788e15621..4ee55e0aa90 100644 --- a/src/pybind/mgr/smb/tests/test_smb.py +++ b/src/pybind/mgr/smb/tests/test_smb.py @@ -667,3 +667,73 @@ domain_settings: ref: foo """.strip() ) + + +def test_apply_invalid_res(tmodule): + result = tmodule.apply_resources( + """ +resource_type: ceph.smb.cluster +cluster_id: "" +auth_mode: doop +""" + ) + assert not result.success + assert 'doop' in result.to_simplified()['results'][0]['msg'] + + +def test_show_all(tmodule): + _example_cfg_1(tmodule) + out = tmodule.show() + assert 'resources' in out + res = out['resources'] + assert len(res) == 4 + assert {r['resource_type'] for r in res} == { + 'ceph.smb.cluster', + 'ceph.smb.share', + 'ceph.smb.join.auth', + } + + +def test_show_shares(tmodule): + _example_cfg_1(tmodule) + out = tmodule.show(['ceph.smb.share']) + assert 'resources' in out + res = out['resources'] + assert len(res) == 2 + assert {r['resource_type'] for r in res} == { + 'ceph.smb.share', + } + + +def test_show_shares_in_cluster(tmodule): + _example_cfg_1(tmodule) + out = tmodule.show(['ceph.smb.share.foo']) + assert 'resources' in out + res = out['resources'] + assert len(res) == 2 + assert {r['resource_type'] for r in res} == { + 'ceph.smb.share', + } + assert {r['cluster_id'] for r in res} == {'foo'} + + +def test_show_specific_share(tmodule): + _example_cfg_1(tmodule) + out = tmodule.show(['ceph.smb.share.foo.s1']) + assert 'resources' not in out + assert out['resource_type'] == 'ceph.smb.share' + assert out['cluster_id'] == 'foo' + assert out['share_id'] == 's1' + + +def test_show_nomatches(tmodule): + _example_cfg_1(tmodule) + out = tmodule.show(['ceph.smb.share.foo.whoops']) + assert 'resources' in out + assert out['resources'] == [] + + +def test_show_invalid_input(tmodule): + _example_cfg_1(tmodule) + with pytest.raises(smb.cli.InvalidInputValue): + tmodule.show(['ceph.smb.export']) -- 2.47.3