sapling/eden/fs/inodes/test/InodeBaseTest.cpp
Adam Simpkins 7100eecdaa additional refactoring of unit test initialization code
Summary:
The FakeTreeBuilder class in D4609587 provides a lot of the same functionality
as the TestMountBuilder class, but is not restricted to being used only at
mount initialization time.  (It also provides more powerful functionality for
controlling the ordering of events when loading data from the ObjectStore.)

This switches all of the existing tests to use FakeTreeBuilder rather than
TestMountBuilder, and removes the TestMountBuilder class.

One difference is that FakeTreeBuilder adds data to the FakeBackingStore, while
TestMountBuilder previously put data directly into the LocalStore.  This
shouldn't really make much difference for the behavior of the code.  Putting
data in the FakeBackingStore gives us more control over when data is available
during load operations, and exercises slightly more of the normal ObjectStore
code path.

Reviewed By: wez

Differential Revision: D4641288

fbshipit-source-id: ca2b45bf69bd373848c12a7b739b286aabe6aa9b
2017-03-02 14:24:10 -08:00

71 lines
2.5 KiB
C++

/*
* Copyright (c) 2016-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
*/
#include <gtest/gtest.h>
#include "eden/fs/inodes/FileInode.h"
#include "eden/fs/inodes/InodeBase.h"
#include "eden/fs/inodes/TreeInode.h"
#include "eden/fs/testharness/FakeTreeBuilder.h"
#include "eden/fs/testharness/TestMount.h"
using namespace facebook::eden;
using folly::StringPiece;
using std::dynamic_pointer_cast;
TEST(InodeBase, getPath) {
FakeTreeBuilder builder;
builder.setFiles({
{"a/b/c/noop.c", "int main() { return 0; }\n"},
});
TestMount testMount{builder};
auto root = testMount.getEdenMount()->getRootInode();
EXPECT_EQ(RelativePathPiece(), root->getPath().value());
EXPECT_EQ("<root>", root->getLogPath());
auto getChild = [](const TreeInodePtr& parent, StringPiece name) {
return parent->getChildByName(PathComponentPiece{name}).get();
};
auto childTree = [&getChild](const TreeInodePtr& parent, StringPiece name) {
return getChild(parent, name).asTreePtr();
};
auto childFile = [&getChild](const TreeInodePtr& parent, StringPiece name) {
return getChild(parent, name).asFilePtr();
};
auto a = childTree(root, "a");
EXPECT_EQ(RelativePath{"a"}, a->getPath().value());
EXPECT_EQ("a", a->getLogPath());
auto ab = childTree(a, "b");
EXPECT_EQ(RelativePath{"a/b"}, ab->getPath().value());
EXPECT_EQ("a/b", ab->getLogPath());
auto abc = childTree(ab, "c");
EXPECT_EQ(RelativePath{"a/b/c"}, abc->getPath().value());
EXPECT_EQ("a/b/c", abc->getLogPath());
auto noopC = childFile(abc, "noop.c");
EXPECT_EQ(RelativePath{"a/b/c/noop.c"}, noopC->getPath().value());
EXPECT_EQ("a/b/c/noop.c", noopC->getLogPath());
// TODO: Test that the path gets updated after unlink() and rename()
// operations.
//
// Currently calling TreeInode::unlink() and TreeInode::rename() here does
// not work. (TreeInode::getChildByName() does not correctly register new
// inodes it creates in the EdenDispatcher's inode map. The unlink() and
// rename() operations require that the inode exist in the dispatcher map.)
//
// I am currently working on refactoring the inode map in a subsequent diff.
// My refactoring ensures that inodes always get registered correctly,
// regardless of how they are created. I'll come back and work on test cases
// here once my refactored InodeMap code lands.
}