1 /*
2 * Copyright (C) 2025 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
17 #include "apexd_image_manager.h"
18
19 #include <android-base/result-gmock.h>
20 #include <gmock/gmock.h>
21 #include <gtest/gtest.h>
22
23 #include "apexd_test_utils.h"
24
25 using namespace std::literals;
26
27 using android::base::testing::HasValue;
28 using android::base::testing::Ok;
29 using testing::IsEmpty;
30
31 namespace android::apex {
32
TEST(ApexImageManagerTest,EmptyWhenDirectoriesAreNotReady)33 TEST(ApexImageManagerTest, EmptyWhenDirectoriesAreNotReady) {
34 // For the first boot, apexd-bootstrap starts without /data or /metadata
35 // directories.
36 auto image_manager =
37 ApexImageManager::Create("/no-metadata-images", "/no-data-images");
38 ASSERT_THAT(image_manager->GetAllImages(), IsEmpty());
39 }
40
TEST(ApexImageManagerTest,PinApexFiles)41 TEST(ApexImageManagerTest, PinApexFiles) {
42 TemporaryDir metadata_dir;
43 TemporaryDir data_dir;
44 auto image_manager =
45 ApexImageManager::Create(metadata_dir.path, data_dir.path);
46
47 auto apex1 = ApexFile::Open(GetTestFile("apex.apexd_test.apex"));
48 ASSERT_THAT(apex1, Ok());
49 auto apex2 =
50 ApexFile::Open(GetTestFile("apex.apexd_test_different_app.apex"));
51 ASSERT_THAT(apex2, Ok());
52 ASSERT_THAT(image_manager->PinApexFiles(std::vector{*apex1, *apex2}),
53 HasValue(std::vector{"com.android.apex.test_pack_0.apex"s,
54 "com.android.apex.test_pack_1.apex"s}));
55 }
56
57 } // namespace android::apex