mirror of
https://github.com/facebook/sapling.git
synced 2024-10-11 01:07:15 +03:00
ed58335598
Summary: This moves all of the test library code into a lib/ subdirectory, just to help distinguish tests from utility code. This also changes the test so that we no longer pack the eden CLI and daemon binaries into the python archives. This results in very large archives when building in dbg and opt modes, and isn't really necessary. Instead edenclient.py simply finds the CLI and daemon binaries relative to the test binary. We pass in an EDENFS_SUFFIX variable to tell it which flavor of the daemon to use. Additionally, this changes the tests to run with python 3. Reviewed By: bolinfest Differential Revision: D3449013 fbshipit-source-id: 82533137090325766a52cd067aa97dd8391ae088
166 lines
5.4 KiB
Python
166 lines
5.4 KiB
Python
#!/usr/bin/env python3
|
|
#
|
|
# Copyright (c) 2016, 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.
|
|
|
|
import errno
|
|
import os
|
|
import stat
|
|
from .lib import testcase
|
|
|
|
|
|
class BasicTest(testcase.EdenTestCase):
|
|
'''Exercise some fundamental properties of the filesystem.
|
|
|
|
Listing directories, checking stat information, asserting
|
|
that the filesystem is reporting the basic information
|
|
about the sample git repo and that it is correct are all
|
|
things that are appropriate to include in this test case.
|
|
'''
|
|
def test_fileList(self):
|
|
eden = self.init_git_eden()
|
|
|
|
entries = sorted(os.listdir(eden.mount_path))
|
|
self.assertEqual(['adir', 'hello', 'slink'], entries)
|
|
|
|
adir = os.path.join(eden.mount_path, 'adir')
|
|
st = os.lstat(adir)
|
|
self.assertTrue(stat.S_ISDIR(st.st_mode))
|
|
self.assertEqual(st.st_uid, os.getuid())
|
|
self.assertEqual(st.st_gid, os.getgid())
|
|
|
|
hello = os.path.join(eden.mount_path, 'hello')
|
|
st = os.lstat(hello)
|
|
self.assertTrue(stat.S_ISREG(st.st_mode))
|
|
|
|
slink = os.path.join(eden.mount_path, 'slink')
|
|
st = os.lstat(slink)
|
|
self.assertTrue(stat.S_ISLNK(st.st_mode))
|
|
|
|
def test_symlinks(self):
|
|
eden = self.init_git_eden()
|
|
|
|
slink = os.path.join(eden.mount_path, 'slink')
|
|
self.assertEqual(os.readlink(slink), 'hello')
|
|
|
|
def test_regular(self):
|
|
eden = self.init_git_eden()
|
|
|
|
hello = os.path.join(eden.mount_path, 'hello')
|
|
with open(hello, 'r') as f:
|
|
self.assertEqual('hola\n', f.read())
|
|
|
|
def test_dir(self):
|
|
eden = self.init_git_eden()
|
|
|
|
entries = sorted(os.listdir(os.path.join(eden.mount_path, 'adir')))
|
|
self.assertEqual(['file'], entries)
|
|
|
|
filename = os.path.join(eden.mount_path, 'adir', 'file')
|
|
with open(filename, 'r') as f:
|
|
self.assertEqual('foo!\n', f.read())
|
|
|
|
def test_create(self):
|
|
eden = self.init_git_eden()
|
|
|
|
filename = os.path.join(eden.mount_path, 'notinrepo')
|
|
with open(filename, 'w') as f:
|
|
f.write('created\n')
|
|
|
|
entries = sorted(os.listdir(eden.mount_path))
|
|
self.assertEqual(['adir', 'hello', 'notinrepo', 'slink'], entries)
|
|
|
|
with open(filename, 'r') as f:
|
|
self.assertEqual(f.read(), 'created\n')
|
|
|
|
st = os.lstat(filename)
|
|
self.assertEqual(st.st_size, 8)
|
|
self.assertTrue(stat.S_ISREG(st.st_mode))
|
|
|
|
def test_overwrite(self):
|
|
eden = self.init_git_eden()
|
|
|
|
hello = os.path.join(eden.mount_path, 'hello')
|
|
with open(hello, 'w') as f:
|
|
f.write('replaced\n')
|
|
|
|
st = os.lstat(hello)
|
|
self.assertEqual(st.st_size, len('replaced\n'))
|
|
|
|
def test_materialize(self):
|
|
eden = self.init_git_eden()
|
|
|
|
hello = os.path.join(eden.mount_path, 'hello')
|
|
# Opening for write should materialize the file with the same
|
|
# contents that we expect
|
|
with open(hello, 'r+') as f:
|
|
self.assertEqual('hola\n', f.read())
|
|
|
|
st = os.lstat(hello)
|
|
self.assertEqual(st.st_size, len('hola\n'))
|
|
|
|
def test_mkdir(self):
|
|
eden = self.init_git_eden()
|
|
|
|
# Can't create a directory inside a file that is in the store
|
|
with self.assertRaises(OSError) as context:
|
|
os.mkdir(os.path.join(eden.mount_path, 'hello', 'world'))
|
|
self.assertEqual(context.exception.errno, errno.ENOTDIR)
|
|
|
|
# Can't create a directory when a file of that name already exists
|
|
with self.assertRaises(OSError) as context:
|
|
os.mkdir(os.path.join(eden.mount_path, 'hello'))
|
|
self.assertEqual(context.exception.errno, errno.EEXIST)
|
|
|
|
# Can't create a directory when a directory of that name already exists
|
|
with self.assertRaises(OSError) as context:
|
|
os.mkdir(os.path.join(eden.mount_path, 'adir'))
|
|
self.assertEqual(context.exception.errno, errno.EEXIST)
|
|
|
|
buckout = os.path.join(eden.mount_path, 'buck-out')
|
|
os.mkdir(buckout)
|
|
st = os.lstat(buckout)
|
|
self.assertTrue(stat.S_ISDIR(st.st_mode))
|
|
|
|
entries = sorted(os.listdir(eden.mount_path))
|
|
self.assertEqual(['adir', 'buck-out', 'hello', 'slink'], entries)
|
|
|
|
# Prove that we can recursively build out a directory tree
|
|
deep_name = os.path.join(buckout, 'foo', 'bar', 'baz')
|
|
os.makedirs(deep_name)
|
|
st = os.lstat(deep_name)
|
|
self.assertTrue(stat.S_ISDIR(st.st_mode))
|
|
|
|
# And that we can create a file in there too
|
|
deep_file = os.path.join(deep_name, 'file')
|
|
with open(deep_file, 'w') as f:
|
|
f.write('w00t')
|
|
st = os.lstat(deep_file)
|
|
self.assertTrue(stat.S_ISREG(st.st_mode))
|
|
|
|
def test_unmount(self):
|
|
eden = self.init_git_eden()
|
|
|
|
entries = sorted(os.listdir(eden.mount_path))
|
|
self.assertEqual(['adir', 'hello', 'slink'], entries)
|
|
|
|
self.assertTrue(eden.in_proc_mounts())
|
|
|
|
eden.unmount_cmd()
|
|
|
|
entries = sorted(os.listdir(eden.mount_path))
|
|
self.assertEqual([], entries)
|
|
|
|
self.assertFalse(eden.in_proc_mounts())
|
|
|
|
eden.mount_cmd()
|
|
|
|
entries = sorted(os.listdir(eden.mount_path))
|
|
self.assertEqual(['adir', 'hello', 'slink'], entries)
|
|
|
|
self.assertTrue(eden.in_proc_mounts())
|