@@ -5464,6 +5464,77 @@ def test_resume_repository_success(self):
54645464 self .assertIn ('Repository was resumed' , self .str_output )
54655465
54665466
5467+ class TestBackupServiceRepoWORM (CommandTest ):
5468+ """Test the backup-service repo-worm subcommand"""
5469+
5470+ def setUp (self ):
5471+ self .server_args = {'enterprise' : True , 'init' : True , 'is_admin' : True ,
5472+ '/pools/default/nodeServices' : {'nodesExt' : [{
5473+ 'hostname' : host ,
5474+ 'services' : {
5475+ 'backupAPI' : port ,
5476+ },
5477+ }]}}
5478+ self .command = ['couchbase-cli' , 'backup-service' ] + cluster_connect_args + ['repo-worm' ]
5479+ super (TestBackupServiceRepoWORM , self ).setUp ()
5480+
5481+ def test_missing_id (self ):
5482+ """Test that the command fails if --id is not provided"""
5483+ self .system_exit_run (self .command + ['--period' , '30' ], self .server_args )
5484+ self .assertIn ('--id' , self .str_error )
5485+ self .assertIn ('required' , self .str_error )
5486+
5487+ def test_missing_period_or_disable (self ):
5488+ """Test that the command fails if neither --period nor --disable is provided"""
5489+ self .system_exit_run (self .command + ['--id' , 'myrepo' ], self .server_args )
5490+ self .assertIn ('--period' , self .str_error )
5491+ self .assertIn ('--disable' , self .str_error )
5492+ self .assertIn ('required' , self .str_error )
5493+
5494+ def test_period_and_disable_mutually_exclusive (self ):
5495+ """Test that the command fails if both --period and --disable are provided"""
5496+ self .system_exit_run (self .command + ['--id' , 'myrepo' , '--period' , '30' , '--disable' ], self .server_args )
5497+ self .assertIn ('not allowed with argument' , self .str_error )
5498+
5499+ def test_period_below_minimum (self ):
5500+ """Test that the command fails if --period is less than 3"""
5501+ self .system_exit_run (self .command + ['--id' , 'myrepo' , '--period' , '2' ], self .server_args )
5502+ self .assertIn ('the provided period must be in the [3, 36525] range' , self .str_output )
5503+
5504+ def test_period_above_maximum (self ):
5505+ """Test that the command fails if --period is greater than 36525"""
5506+ self .system_exit_run (self .command + ['--id' , 'myrepo' , '--period' , '36526' ], self .server_args )
5507+ self .assertIn ('the provided period must be in the [3, 36525] range' , self .str_output )
5508+
5509+ def test_set_worm_period_success (self ):
5510+ """Test that the command successfully sets WORM period for a repository"""
5511+ self .no_error_run (self .command + ['--id' , 'myrepo' , '--period' , '30' ], self .server_args )
5512+ self .assertIn ('POST:/api/v1/cluster/self/repository/active/myrepo/worm' , self .server .trace )
5513+ self .rest_parameter_match ([json .dumps ({'disable' : False , 'period' : 30 }, sort_keys = True )])
5514+ self .assertIn ('Repository WORM config was set' , self .str_output )
5515+
5516+ def test_set_worm_period_minimum (self ):
5517+ """Test that the command accepts the minimum period of 3 days"""
5518+ self .no_error_run (self .command + ['--id' , 'myrepo' , '--period' , '3' ], self .server_args )
5519+ self .assertIn ('POST:/api/v1/cluster/self/repository/active/myrepo/worm' , self .server .trace )
5520+ self .rest_parameter_match ([json .dumps ({'disable' : False , 'period' : 3 }, sort_keys = True )])
5521+ self .assertIn ('Repository WORM config was set' , self .str_output )
5522+
5523+ def test_set_worm_period_maximum (self ):
5524+ """Test that the command accepts the maximum period of 36525 days"""
5525+ self .no_error_run (self .command + ['--id' , 'myrepo' , '--period' , '36525' ], self .server_args )
5526+ self .assertIn ('POST:/api/v1/cluster/self/repository/active/myrepo/worm' , self .server .trace )
5527+ self .rest_parameter_match ([json .dumps ({'disable' : False , 'period' : 36525 }, sort_keys = True )])
5528+ self .assertIn ('Repository WORM config was set' , self .str_output )
5529+
5530+ def test_disable_worm_success (self ):
5531+ """Test that the command successfully disables WORM for a repository"""
5532+ self .no_error_run (self .command + ['--id' , 'myrepo' , '--disable' ], self .server_args )
5533+ self .assertIn ('POST:/api/v1/cluster/self/repository/active/myrepo/worm' , self .server .trace )
5534+ self .rest_parameter_match ([json .dumps ({'disable' : True }, sort_keys = True )])
5535+ self .assertIn ('Repository WORM config was set' , self .str_output )
5536+
5537+
54675538class TestBackupServiceSettings (CommandTest ):
54685539 """Test the backup-service settings subcommand"""
54695540
0 commit comments