src/sys/appmgr/storage_unittest.cc
// Test the storage directory path for a component when it has a component ID.
Test the storage directory path for a component when it has a component ID.
Test the storage directory path for a component when it has a component ID .
TEST_F(StorageTest, DirPathWithInstanceId) {
  auto root_realm = CreateRootRealm(
      root_storage_dir(), MakeAppmgrConfigDirWithIndex(fxl::Substitute(R"(
        {
          "instances": [
            {
              "instance_id": "$0",
              "appmgr_moniker": {
                "realm_path": ["app", "child_realm"],
                "url": "fuchsia-pkg://fuchsia.com/my_pkg#meta/my_component.cmx"
              }
            }
          ]
        }
      )",
                                                                       kExampleInstanceId)));
  fuchsia::sys::EnvironmentControllerPtr child_env_ctrl;
  auto child_realm = CreateChildRealm(root_realm.get(), "child_realm", child_env_ctrl.NewRequest());
  FuchsiaPkgUrl url;
  ZX_ASSERT(url.Parse("fuchsia-pkg://fuchsia.com/my_pkg#meta/my_component.cmx"));
  auto actual_storage_path =
      child_realm->IsolatedPathForComponentInstance(url, internal::StorageType::DATA);
  EXPECT_EQ(actual_storage_path,
            files::JoinPath(root_storage_dir(),
                            fxl::Substitute("data/persistent/$0", kExampleInstanceId)));
  EXPECT_TRUE(files::IsDirectory(files::JoinPath(
      root_storage_dir(), fxl::Substitute("data/persistent/$0", kExampleInstanceId))));
  EXPECT_FALSE(files::IsDirectory(files::JoinPath(
      root_storage_dir(), "data/r/child_realm/fuchsia.com:my_pkg:0#meta:my_component.cmx")));
}
TEST_F ( StorageTest , DirPathWithInstanceId ) { auto root_realm = CreateRootRealm ( root_storage_dir ( ) , MakeAppmgrConfigDirWithIndex ( fxl :: Substitute ( R" ( 
        {
          "instances": [
            {
              "instance_id": "$0",
              "appmgr_moniker": {
                "realm_path": ["app", "child_realm"],
                "url": "fuchsia-pkg://fuchsia.com/my_pkg#meta/my_component.cmx"
              }
            }
          ]
        }
       ) " , kExampleInstanceId ) ) ) ; fuchsia :: sys :: EnvironmentControllerPtr child_env_ctrl ; auto child_realm = CreateChildRealm ( root_realm . get ( ) , " " , child_env_ctrl . NewRequest ( ) ) ; FuchsiaPkgUrl url ; ZX_ASSERT ( url . Parse ( " " ) ) ; auto actual_storage_path = child_realm -> IsolatedPathForComponentInstance ( url , internal :: StorageType :: DATA ) ; EXPECT_EQ ( actual_storage_path , files :: JoinPath ( root_storage_dir ( ) , fxl :: Substitute ( " " , kExampleInstanceId ) ) ) ; EXPECT_TRUE ( files :: IsDirectory ( files :: JoinPath ( root_storage_dir ( ) , fxl :: Substitute ( " " , kExampleInstanceId ) ) ) ) ; EXPECT_FALSE ( files :: IsDirectory ( files :: JoinPath ( root_storage_dir ( ) , " " ) ) ) ; }
Test the storage directory path for a component when it has a component ID.
Test the storage directory path for a component when it has a component ID .
// Ensure that the instance ID based directory is created. // Ensure that the moniker based directory does not exist.