// Tests the archive APIs for archiving/unarchiving a directory for GZIP // compression. This test specifically tests for the use case of changing // directory before archiving. TEST_F(TarTest, GZIPChangeDirectory) { // Create a top directory where the directory to be archived will be placed. const Path topDir("top_dir"); const Path testDir("test_dir"); const Path testFile(path::join(testDir, "testfile")); // Create a test file in the test directory. ASSERT_SOME(createTestFile(testFile, topDir)); // Archive the test directory. const Path outputTarFile("test_dir.tar"); AWAIT_ASSERT_READY(command::tar( testDir, outputTarFile, topDir, command::Compression::GZIP)); ASSERT_TRUE(os::exists(outputTarFile)); // Remove the top directory to make sure untar process creates new directory. ASSERT_SOME(os::rmdir(topDir)); ASSERT_FALSE(os::exists(topDir)); // Untar the tarball and verify that the original file is created. AWAIT_ASSERT_READY(command::untar(outputTarFile)); ASSERT_TRUE(os::exists(testDir)); // Verify that the top directory was not created. ASSERT_FALSE(os::exists(topDir)); // Verify that the content is same as original file. EXPECT_SOME_EQ("test", os::read(testFile)); }
// Tests the archive APIs for archiving/unarchiving a simple file for BZIP2 // compression. TEST_F(TarTest, BZIP2CompressFile) { // Create a test file. const Path testFile("testfile"); ASSERT_SOME(createTestFile(testFile)); // Archive the test file. const Path outputTarFile("test.tar"); AWAIT_ASSERT_READY(command::tar( testFile, outputTarFile, None(), command::Compression::BZIP2)); ASSERT_TRUE(os::exists(outputTarFile)); // Remove the test file to make sure untar process creates new test file. ASSERT_SOME(os::rm(testFile)); ASSERT_FALSE(os::exists(testFile)); // Untar the tarball and verify that the original file is created. AWAIT_ASSERT_READY(command::untar(outputTarFile)); ASSERT_TRUE(os::exists(testFile)); // Verify that the content is same as original file. EXPECT_SOME_EQ("test", os::read(testFile)); }
virtual void TearDown() override { runtime.terminate(); AWAIT_ASSERT_READY(runtime.wait()); ASSERT_SOME(plugin.Shutdown()); }
TEST_F(ShasumTest, SHA512SimpleFile) { const Path testFile(path::join(os::getcwd(), "test")); Try<Nothing> write = os::write(testFile, "hello world"); ASSERT_SOME(write); Future<string> sha512 = command::sha512(testFile); AWAIT_ASSERT_READY(sha512); ASSERT_EQ( sha512.get(), "309ecc489c12d6eb4cc40f50c902f2b4d0ed77ee511a7c7a9bcd3ca86d4cd86f989dd35bc5ff499670da34255b45b0cfd830e81f605dcf7dc5542e93ae9cd76f"); // NOLINT(whitespace/line_length) }
// Tests the archive APIs for a simple directory. TEST_F(TarTest, Directory) { const Path testDir("test_dir"); const Path testFile(path::join(testDir, "testfile")); // Create a test file in the test directory. ASSERT_SOME(createTestFile(testFile)); // Archive the test directory. const Path outputTarFile("test_dir.tar"); AWAIT_ASSERT_READY(command::tar(testDir, outputTarFile, None())); ASSERT_TRUE(os::exists(outputTarFile)); // Remove the test directory to make sure untar process creates new test file. ASSERT_SOME(os::rmdir(testDir)); ASSERT_FALSE(os::exists(testDir)); // Untar the tarball and verify that the original directory is created. AWAIT_ASSERT_READY(command::untar(outputTarFile)); ASSERT_TRUE(os::exists(testDir)); // Verify that the content is same as original file. EXPECT_SOME_EQ("test", os::read(testFile)); }
TEST_F(MesosContainerizerLaunchTest, ROOT_ChangeRootfs) { Try<Owned<Rootfs>> rootfs = LinuxRootfs::create(path::join(os::getcwd(), "rootfs")); ASSERT_SOME(rootfs); // Add /usr/bin/stat into the rootfs. ASSERT_SOME(rootfs.get()->add("/usr/bin/stat")); Clock::pause(); Try<Subprocess> s = run( "/usr/bin/stat -c %i / >" + path::join("/", "stat.output"), rootfs.get()->root); ASSERT_SOME(s); // Advance time until the internal reaper reaps the subprocess. while (s.get().status().isPending()) { Clock::advance(process::MAX_REAP_INTERVAL()); Clock::settle(); } AWAIT_ASSERT_READY(s.get().status()); ASSERT_SOME(s.get().status().get()); int status = s.get().status().get().get(); ASSERT_TRUE(WIFEXITED(status)); ASSERT_EQ(0, WEXITSTATUS(status)); // Check the rootfs has a different root by comparing the inodes. Try<ino_t> self = os::stat::inode("/"); ASSERT_SOME(self); Try<string> read = os::read(path::join(rootfs.get()->root, "stat.output")); ASSERT_SOME(read); Try<ino_t> other = numify<ino_t>(strings::trim(read.get())); ASSERT_SOME(other); EXPECT_NE(self.get(), other.get()); }