diff --git a/tests/test_vagrant.py b/tests/test_vagrant.py index c9788cc..55c563b 100644 --- a/tests/test_vagrant.py +++ b/tests/test_vagrant.py @@ -269,7 +269,10 @@ def test_vm_status(vm_dir): def test_vm_lifecycle(vm_dir): - """Test methods controlling the VM - init(), up(), halt(), destroy().""" + """Test methods controlling the VM - init(), up(), suspend(), halt(), destroy().""" + VAGRANT_DIR = f"{os.environ['HOME']}/.vagrant.d" + VAGRANTFILE_CREATED = False + v = vagrant.Vagrant(vm_dir) # Test init by removing Vagrantfile, since v.init() will create one. @@ -278,9 +281,24 @@ def test_vm_lifecycle(vm_dir): except FileNotFoundError: pass + try: + os.mkdir(VAGRANT_DIR, mode=0o755) + except FileExistsError: + pass + + if not os.path.isfile(f"{VAGRANT_DIR}/Vagrantfile"): + with open(f"{VAGRANT_DIR}/Vagrantfile", "w", encoding="UTF-8") as config: + config.write( + 'Vagrant.configure("2") do |config|\n config.vbguest.auto_update = false if Vagrant.has_plugin?("vagrant-vbguest")\nend\n' + ) + VAGRANTFILE_CREATED = True + v.init(TEST_BOX_NAME) assert v.NOT_CREATED == v.status()[0].state + validation = v.validate(vm_dir) + assert validation.returncode == 0 + v.up() assert v.RUNNING == v.status()[0].state @@ -293,12 +311,14 @@ def test_vm_lifecycle(vm_dir): v.destroy() assert v.NOT_CREATED == v.status()[0].state + if VAGRANTFILE_CREATED: + os.unlink(f"{VAGRANT_DIR}/Vagrantfile") + def test_valid_config(vm_dir): v = vagrant.Vagrant(vm_dir) v.up() validation = v.validate(vm_dir) - assert validation.returncode == 0