blob: fd7081869d61e2af5ea31c1205742e8975510adf [file] [log] [blame]
Jae Hoon Kim38de3b12020-04-29 19:41:23 -07001//
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 Hassaniec7bc112020-10-29 16:47:58 -070017#include "update_engine/cros/excluder_chromeos.h"
Jae Hoon Kim38de3b12020-04-29 19:41:23 -070018
Jae Hoon Kim38de3b12020-04-29 19:41:23 -070019#include <gtest/gtest.h>
20
Amin Hassani90e9f192020-11-18 14:20:56 -080021#include "update_engine/cros/fake_system_state.h"
Jae Hoon Kim38de3b12020-04-29 19:41:23 -070022
23namespace chromeos_update_engine {
24
Amin Hassani90e9f192020-11-18 14:20:56 -080025namespace {
Tianjied60dc392020-07-29 11:27:35 -070026constexpr char kFakeHash[] =
Jae Hoon Kim38de3b12020-04-29 19:41:23 -070027 "71ff43d76e2488e394e46872f5b066cc25e394c2c3e3790dd319517883b33db1";
Amin Hassani90e9f192020-11-18 14:20:56 -080028} // namespace
Jae Hoon Kim38de3b12020-04-29 19:41:23 -070029
30class ExcluderChromeOSTest : public ::testing::Test {
31 protected:
Amin Hassani90e9f192020-11-18 14:20:56 -080032 void SetUp() override { FakeSystemState::CreateInstance(); }
Jae Hoon Kim38de3b12020-04-29 19:41:23 -070033
Amin Hassani90e9f192020-11-18 14:20:56 -080034 ExcluderChromeOS excluder_;
Jae Hoon Kim38de3b12020-04-29 19:41:23 -070035};
36
37TEST_F(ExcluderChromeOSTest, ExclusionCheck) {
Amin Hassani90e9f192020-11-18 14:20:56 -080038 EXPECT_FALSE(excluder_.IsExcluded(kFakeHash));
39 EXPECT_TRUE(excluder_.Exclude(kFakeHash));
40 EXPECT_TRUE(excluder_.IsExcluded(kFakeHash));
Jae Hoon Kim38de3b12020-04-29 19:41:23 -070041}
42
43TEST_F(ExcluderChromeOSTest, ResetFlow) {
Amin Hassani90e9f192020-11-18 14:20:56 -080044 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 Kim38de3b12020-04-29 19:41:23 -070048
Amin Hassani90e9f192020-11-18 14:20:56 -080049 EXPECT_TRUE(excluder_.Reset());
50 EXPECT_FALSE(excluder_.IsExcluded("abc"));
51 EXPECT_FALSE(excluder_.IsExcluded(kFakeHash));
Jae Hoon Kim38de3b12020-04-29 19:41:23 -070052}
53
54} // namespace chromeos_update_engine