Jae Hoon Kim | 38de3b1 | 2020-04-29 19:41:23 -0700 | [diff] [blame] | 1 | // |
| 2 | // Copyright (C) 2020 The Android Open Source Project |
| 3 | // |
| 4 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | // you may not use this file except in compliance with the License. |
| 6 | // You may obtain a copy of the License at |
| 7 | // |
| 8 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | // |
| 10 | // Unless required by applicable law or agreed to in writing, software |
| 11 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | // See the License for the specific language governing permissions and |
| 14 | // limitations under the License. |
| 15 | // |
| 16 | |
Amin Hassani | ec7bc11 | 2020-10-29 16:47:58 -0700 | [diff] [blame] | 17 | #include "update_engine/cros/excluder_chromeos.h" |
Jae Hoon Kim | 38de3b1 | 2020-04-29 19:41:23 -0700 | [diff] [blame] | 18 | |
Jae Hoon Kim | 38de3b1 | 2020-04-29 19:41:23 -0700 | [diff] [blame] | 19 | #include <gtest/gtest.h> |
| 20 | |
Amin Hassani | 90e9f19 | 2020-11-18 14:20:56 -0800 | [diff] [blame] | 21 | #include "update_engine/cros/fake_system_state.h" |
Jae Hoon Kim | 38de3b1 | 2020-04-29 19:41:23 -0700 | [diff] [blame] | 22 | |
| 23 | namespace chromeos_update_engine { |
| 24 | |
Amin Hassani | 90e9f19 | 2020-11-18 14:20:56 -0800 | [diff] [blame] | 25 | namespace { |
Tianjie | d60dc39 | 2020-07-29 11:27:35 -0700 | [diff] [blame] | 26 | constexpr char kFakeHash[] = |
Jae Hoon Kim | 38de3b1 | 2020-04-29 19:41:23 -0700 | [diff] [blame] | 27 | "71ff43d76e2488e394e46872f5b066cc25e394c2c3e3790dd319517883b33db1"; |
Amin Hassani | 90e9f19 | 2020-11-18 14:20:56 -0800 | [diff] [blame] | 28 | } // namespace |
Jae Hoon Kim | 38de3b1 | 2020-04-29 19:41:23 -0700 | [diff] [blame] | 29 | |
| 30 | class ExcluderChromeOSTest : public ::testing::Test { |
| 31 | protected: |
Amin Hassani | 90e9f19 | 2020-11-18 14:20:56 -0800 | [diff] [blame] | 32 | void SetUp() override { FakeSystemState::CreateInstance(); } |
Jae Hoon Kim | 38de3b1 | 2020-04-29 19:41:23 -0700 | [diff] [blame] | 33 | |
Amin Hassani | 90e9f19 | 2020-11-18 14:20:56 -0800 | [diff] [blame] | 34 | ExcluderChromeOS excluder_; |
Jae Hoon Kim | 38de3b1 | 2020-04-29 19:41:23 -0700 | [diff] [blame] | 35 | }; |
| 36 | |
| 37 | TEST_F(ExcluderChromeOSTest, ExclusionCheck) { |
Amin Hassani | 90e9f19 | 2020-11-18 14:20:56 -0800 | [diff] [blame] | 38 | EXPECT_FALSE(excluder_.IsExcluded(kFakeHash)); |
| 39 | EXPECT_TRUE(excluder_.Exclude(kFakeHash)); |
| 40 | EXPECT_TRUE(excluder_.IsExcluded(kFakeHash)); |
Jae Hoon Kim | 38de3b1 | 2020-04-29 19:41:23 -0700 | [diff] [blame] | 41 | } |
| 42 | |
| 43 | TEST_F(ExcluderChromeOSTest, ResetFlow) { |
Amin Hassani | 90e9f19 | 2020-11-18 14:20:56 -0800 | [diff] [blame] | 44 | EXPECT_TRUE(excluder_.Exclude("abc")); |
| 45 | EXPECT_TRUE(excluder_.Exclude(kFakeHash)); |
| 46 | EXPECT_TRUE(excluder_.IsExcluded("abc")); |
| 47 | EXPECT_TRUE(excluder_.IsExcluded(kFakeHash)); |
Jae Hoon Kim | 38de3b1 | 2020-04-29 19:41:23 -0700 | [diff] [blame] | 48 | |
Amin Hassani | 90e9f19 | 2020-11-18 14:20:56 -0800 | [diff] [blame] | 49 | EXPECT_TRUE(excluder_.Reset()); |
| 50 | EXPECT_FALSE(excluder_.IsExcluded("abc")); |
| 51 | EXPECT_FALSE(excluder_.IsExcluded(kFakeHash)); |
Jae Hoon Kim | 38de3b1 | 2020-04-29 19:41:23 -0700 | [diff] [blame] | 52 | } |
| 53 | |
| 54 | } // namespace chromeos_update_engine |