def testOutsideChrootDifferentTokenFile(self): mocked_outsidechroot = self._MockOutsideChroot('foo') self.mox.StubOutWithMock(cgt, '_ChrootPathToExternalPath') self.mox.StubOutWithMock(os.path, 'exists') self.mox.StubOutWithMock(shutil, 'copy2') self.mox.StubOutWithMock(filecmp, 'cmp') self.mox.StubOutWithMock(build_lib, 'RunCommand') cmd = ['check_gdata_token', 'foo'] run_result = cros_test_lib.EasyAttr(returncode=0) # Create replay script. build_lib.RunCommand(cmd, enter_chroot=True, print_cmd=False, error_code_ok=True).AndReturn(run_result) cgt._ChrootPathToExternalPath(cgt.TOKEN_FILE).AndReturn('chr-tok') os.path.exists('chr-tok').AndReturn(True) os.path.exists(cgt.TOKEN_FILE).AndReturn(True) filecmp.cmp(cgt.TOKEN_FILE, 'chr-tok').AndReturn(False) shutil.copy2('chr-tok', cgt.TOKEN_FILE) self.mox.ReplayAll() # Run test verification. with self.OutputCapturer(): cgt.OutsideChroot.Run(mocked_outsidechroot) self.mox.VerifyAll()
def testOutsideChrootNoTokenFile(self): mocked_outsidechroot = self._MockOutsideChroot('foo') self.mox.StubOutWithMock(cgt, '_ChrootPathToExternalPath') self.mox.StubOutWithMock(os.path, 'exists') self.mox.StubOutWithMock(build_lib, 'RunCommand') cmd = ['check_gdata_token', 'foo'] run_result = cros_test_lib.EasyAttr(returncode=0) # Create replay script. build_lib.RunCommand(cmd, enter_chroot=True, print_cmd=False, error_code_ok=True).AndReturn(run_result) cgt._ChrootPathToExternalPath(cgt.TOKEN_FILE).AndReturn('chr-tok') os.path.exists('chr-tok').AndReturn(False) self.mox.ReplayAll() # Run test verification. with self.OutputCapturer(): # Test should exit with failure. self.AssertFuncSystemExitNonZero(cgt.OutsideChroot.Run, mocked_outsidechroot) self.mox.VerifyAll() self.AssertOutputContainsError()
def testOutsideChrootNoChangeInTokenFile(self): mocked_outsidechroot = self._MockOutsideChroot('foo') self.mox.StubOutWithMock(cgt, '_ChrootPathToExternalPath') self.mox.StubOutWithMock(os.path, 'exists') self.mox.StubOutWithMock(filecmp, 'cmp') self.mox.StubOutWithMock(build_lib, 'RunCommand') cmd = ['check_gdata_token', 'foo'] run_result = cros_test_lib.EasyAttr(returncode=0) # Create replay script. build_lib.RunCommand(cmd, enter_chroot=True, print_cmd=False, error_code_ok=True).AndReturn(run_result) cgt._ChrootPathToExternalPath(cgt.TOKEN_FILE).AndReturn('chr-tok') os.path.exists('chr-tok').AndReturn(True) os.path.exists(cgt.TOKEN_FILE).AndReturn(True) filecmp.cmp(cgt.TOKEN_FILE, 'chr-tok').AndReturn(True) self.mox.ReplayAll() # Run test verification. with self.OutputCapturer(): cgt.OutsideChroot.Run(mocked_outsidechroot) self.mox.VerifyAll()
def testOutsideChrootNoChangeInTokenFile(self): mocked_outsidechroot = self._MockOutsideChroot("foo") self.mox.StubOutWithMock(cgt, "_ChrootPathToExternalPath") self.mox.StubOutWithMock(os.path, "exists") self.mox.StubOutWithMock(filecmp, "cmp") self.mox.StubOutWithMock(build_lib, "RunCommand") cmd = ["check_gdata_token", "foo"] run_result = cros_test_lib.EasyAttr(returncode=0) # Create replay script. build_lib.RunCommand(cmd, enter_chroot=True, print_cmd=False, error_code_ok=True).AndReturn(run_result) cgt._ChrootPathToExternalPath(cgt.TOKEN_FILE).AndReturn("chr-tok") os.path.exists("chr-tok").AndReturn(True) os.path.exists(cgt.TOKEN_FILE).AndReturn(True) filecmp.cmp(cgt.TOKEN_FILE, "chr-tok").AndReturn(True) self.mox.ReplayAll() # Run test verification. with self.OutputCapturer(): cgt.OutsideChroot.Run(mocked_outsidechroot) self.mox.VerifyAll()