def testInstallAdditionalComponents(self):
     driver.Init(additional_components=['foo'])
     root_directory = os.environ[constants.DRIVER_LOCATION_ENV]
     self.assertCalledOnceWithArgsIgnoringKwargs(self.popen_patch, [
         './install.sh', '--disable-installation-options',
         '--bash-completion=false', '--path-update=false',
         '--usage-reporting=false', '--rc-path={path}/.bashrc'.format(
             path=root_directory), '--additional-components', 'foo'
     ])
    def testRunTwiceNoDestroy(self):
        # Forgetting to call Destroy mainly means that the installation location is
        # not cleaned up. By default this would leave files in the temp directory.
        # It's best not to leave such files around taking up disk space, but they
        # shouldn't hurt anything if the disk's not full.

        # After Init, imitate forgetting to call Destroy by removing the environment
        # variable tracking the installation location.
        driver.Init()
        self.location = os.environ[constants.DRIVER_LOCATION_ENV]
        del os.environ[constants.DRIVER_LOCATION_ENV]
        self.addCleanup(self.cleanup)

        # Verify that things still work.
        with driver.Manager():
            sdk = driver.DefaultSDK()
            _, _, ret = sdk.RunGcloud(['config', 'list'])
            self.assertEqual(0, ret)
    def testRunTwiceNoDestroyFixedPath(self):
        # If you're using a fixed root directory, not calling Destroy will behave a
        # little differently. Instead of leaking the previous installation, it will
        # just reuse it.
        root_directory = tempfile.mkdtemp()

        # After Init, imitate forgetting to call Destroy by removing the environment
        # variable tracking the installation location.
        driver.Init(root_directory=root_directory)
        self.location = os.environ[constants.DRIVER_LOCATION_ENV]
        del os.environ[constants.DRIVER_LOCATION_ENV]
        self.addCleanup(self.cleanup)

        # If the root directory was set, the driver should be using it
        self.assertEqual(root_directory, self.location)

        # Verify that things still work.
        with driver.Manager(root_directory=root_directory):
            sdk = driver.DefaultSDK()
            _, _, ret = sdk.RunGcloud(['config', 'list'])
            self.assertEqual(0, ret)

            self.assertEqual(root_directory,
                             os.environ[constants.DRIVER_LOCATION_ENV])
 def testDestroy(self):
     driver.Init()
     root_directory = os.environ[constants.DRIVER_LOCATION_ENV]
     driver.Destroy()
     self.assertNotIn(constants.DRIVER_LOCATION_ENV, os.environ)
     self.rm_patch.assert_called_once_with(root_directory)
 def testInstallFailed(self):
     self.dir_patch.return_value = False
     with self.assertRaises(error.InitError):
         driver.Init()
 def testNoPython(self):
     self.StartObjectPatch(sys, 'executable', new=None)
     with self.assertRaises(error.InitError):
         driver.Init()
 def testInstallTwice(self):
     driver.Init()
     with self.assertRaises(error.InitError):
         driver.Init()