Permalink
Browse files

Merge pull request #3421 from gaborigloi/alcotest_vm_check

Convert Test_vm_check_operation_error to alcotest
  • Loading branch information...
lindig committed Jan 31, 2018
2 parents 7579faa + 2101c98 commit 76ed723c516dbd3ed0e0c8a9025508abcb176530
Showing with 14 additions and 11 deletions.
  1. +0 −1 ocaml/xapi/suite.ml
  2. +1 −0 ocaml/xapi/suite_alcotest.ml
  3. +13 −10 ocaml/xapi/test_vm_check_operation_error.ml
View
@@ -45,7 +45,6 @@ let base_suite =
Test_storage_migrate_state.test;
Test_vm.test;
Test_vm_helpers.test;
- Test_vm_check_operation_error.test;
Test_vm_migrate.test;
Test_xenopsd_metadata.test;
Test_workload_balancing.test;
@@ -7,4 +7,5 @@ let () =
Alcotest.run "Base suite"
[ "Test_valid_ref_list", Test_valid_ref_list.test
; "Test_vdi_allowed_operations", Test_vdi_allowed_operations.test
+ ; "Test_vm_check_operation_error", Test_vm_check_operation_error.test
]
@@ -67,13 +67,18 @@ let test_null_vdi () =
all_vm_operations
)
+let compare_errors = Alcotest.(check (option (pair string (list string)))) "same error codes"
+
(* Operations that check the validity of other VM operations should
always be allowed *)
let test_operation_checks_allowed () =
with_test_vm (fun __context vm_ref ->
[`assert_operation_valid; `update_allowed_operations] |>
List.iter
- (fun op -> OUnit.assert_equal None (Xapi_vm_lifecycle.check_operation_error ~__context ~ref:vm_ref ~op ~strict:true))
+ (fun op ->
+ compare_errors
+ None
+ (Xapi_vm_lifecycle.check_operation_error ~__context ~ref:vm_ref ~op ~strict:true))
)
(* The check_operation_error function, which is called from the message
@@ -86,7 +91,7 @@ let test_migration_allowed_when_cbt_enabled_vdis_are_not_moved () =
with_test_vm (fun __context vM ->
let vDI = Test_common.make_vdi ~__context ~cbt_enabled:true () in
let _: _ API.Ref.t = Test_common.make_vbd ~__context ~vM ~vDI () in
- OUnit.assert_equal
+ compare_errors
None
(Xapi_vm_lifecycle.check_operation_error ~__context ~ref:vM ~op:`migrate_send ~strict:true)
)
@@ -96,20 +101,18 @@ let test_sxm_disallowed_when_rum () =
let master = Test_common.make_host __context () in
let pool = Test_common.make_pool ~__context ~master () in
Db.Pool.add_to_other_config ~__context ~self:pool ~key:Xapi_globs.rolling_upgrade_in_progress ~value:"x";
- OUnit.assert_equal
+ compare_errors
(Some(Api_errors.not_supported_during_upgrade, [ ]))
(Xapi_vm_lifecycle.check_operation_error ~__context ~ref:vm_ref ~op:`migrate_send ~strict:false);
Db.Pool.remove_from_other_config ~__context ~self:pool ~key:Xapi_globs.rolling_upgrade_in_progress;
- OUnit.assert_equal
+ compare_errors
None
(Xapi_vm_lifecycle.check_operation_error ~__context ~ref:vm_ref ~op:`migrate_send ~strict:false)
)
let test =
- let open OUnit in
- "test_vm_check_operation_error" >:::
- [ "test_null_vdi" >:: test_null_vdi
- ; "test_operation_checks_allowed" >:: test_operation_checks_allowed
- ; "test_migration_allowed_when_cbt_enabled_vdis_are_not_moved" >:: test_migration_allowed_when_cbt_enabled_vdis_are_not_moved
- ; "test_sxm_disallowed_when_rum" >:: test_sxm_disallowed_when_rum
+ [ "test_null_vdi", `Quick, test_null_vdi
+ ; "test_operation_checks_allowed", `Quick, test_operation_checks_allowed
+ ; "test_migration_allowed_when_cbt_enabled_vdis_are_not_moved", `Quick, test_migration_allowed_when_cbt_enabled_vdis_are_not_moved
+ ; "test_sxm_disallowed_when_rum", `Quick, test_sxm_disallowed_when_rum
]

0 comments on commit 76ed723

Please sign in to comment.