Chris Masone | f8d037f | 2014-02-19 01:53:00 +0000 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium OS Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include "update_engine/hwid_override.h" |
| 6 | |
| 7 | #include <string> |
| 8 | |
Alex Vakulenko | 75039d7 | 2014-03-25 12:36:28 -0700 | [diff] [blame] | 9 | #include <base/files/file_path.h> |
Ben Chan | 06c76a4 | 2014-09-05 08:21:06 -0700 | [diff] [blame] | 10 | #include <base/files/file_util.h> |
Chris Masone | f8d037f | 2014-02-19 01:53:00 +0000 | [diff] [blame] | 11 | #include <base/files/scoped_temp_dir.h> |
| 12 | #include <gtest/gtest.h> |
| 13 | |
| 14 | namespace chromeos_update_engine { |
| 15 | |
| 16 | class HwidOverrideTest : public ::testing::Test { |
| 17 | public: |
| 18 | HwidOverrideTest() {} |
Alex Deymo | 610277e | 2014-11-11 21:18:11 -0800 | [diff] [blame] | 19 | ~HwidOverrideTest() override = default; |
Chris Masone | f8d037f | 2014-02-19 01:53:00 +0000 | [diff] [blame] | 20 | |
Alex Deymo | 610277e | 2014-11-11 21:18:11 -0800 | [diff] [blame] | 21 | void SetUp() override { |
Chris Masone | f8d037f | 2014-02-19 01:53:00 +0000 | [diff] [blame] | 22 | ASSERT_TRUE(tempdir_.CreateUniqueTempDir()); |
Alex Vakulenko | 75039d7 | 2014-03-25 12:36:28 -0700 | [diff] [blame] | 23 | ASSERT_TRUE(base::CreateDirectory(tempdir_.path().Append("etc"))); |
Chris Masone | f8d037f | 2014-02-19 01:53:00 +0000 | [diff] [blame] | 24 | } |
| 25 | |
| 26 | protected: |
| 27 | base::ScopedTempDir tempdir_; |
| 28 | |
| 29 | private: |
| 30 | DISALLOW_COPY_AND_ASSIGN(HwidOverrideTest); |
| 31 | }; |
| 32 | |
| 33 | TEST_F(HwidOverrideTest, ReadGood) { |
| 34 | std::string expected_hwid("expected"); |
| 35 | std::string keyval(HwidOverride::kHwidOverrideKey); |
| 36 | keyval += ("=" + expected_hwid); |
Ben Chan | 736fcb5 | 2014-05-21 18:28:22 -0700 | [diff] [blame] | 37 | ASSERT_EQ(base::WriteFile(tempdir_.path().Append("etc/lsb-release"), |
| 38 | keyval.c_str(), keyval.length()), |
Chris Masone | f8d037f | 2014-02-19 01:53:00 +0000 | [diff] [blame] | 39 | keyval.length()); |
| 40 | EXPECT_EQ(expected_hwid, HwidOverride::Read(tempdir_.path())); |
| 41 | } |
| 42 | |
| 43 | TEST_F(HwidOverrideTest, ReadNothing) { |
| 44 | std::string keyval("SOMETHING_ELSE=UNINTERESTING"); |
Ben Chan | 736fcb5 | 2014-05-21 18:28:22 -0700 | [diff] [blame] | 45 | ASSERT_EQ(base::WriteFile(tempdir_.path().Append("etc/lsb-release"), |
| 46 | keyval.c_str(), keyval.length()), |
Chris Masone | f8d037f | 2014-02-19 01:53:00 +0000 | [diff] [blame] | 47 | keyval.length()); |
| 48 | EXPECT_EQ(std::string(), HwidOverride::Read(tempdir_.path())); |
| 49 | } |
| 50 | |
| 51 | TEST_F(HwidOverrideTest, ReadFailure) { |
| 52 | EXPECT_EQ(std::string(), HwidOverride::Read(tempdir_.path())); |
| 53 | } |
| 54 | |
| 55 | } // namespace chromeos_update_engine |