| // Copyright 2022 The Chromium Authors. All rights reserved. |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| #include "util/atomic_write.h" |
| #include "base/files/file_util.h" |
| #include "base/files/scoped_temp_dir.h" |
| #include "util/test/test.h" |
| class ImportantFileWriterTest : public testing::Test { |
| ImportantFileWriterTest() = default; |
| ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
| file_ = temp_dir_.GetPath().AppendASCII("test-file"); |
| base::ScopedTempDir temp_dir_; |
| // Test that WriteFileAtomically works. |
| TEST_F(ImportantFileWriterTest, Basic) { |
| const std::string data = "Test string for writing."; |
| EXPECT_FALSE(base::PathExists(file_)); |
| EXPECT_TRUE(util::WriteFileAtomically(file_, data.data(), data.size())); |
| EXPECT_TRUE(ReadFileToString(file_, &actual)); |