sapling/eden/fs/integration/xattr_test.py
Adam Simpkins ed58335598 minor refactoring of integration tests
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
2016-06-20 13:40:02 -07:00

53 lines
1.6 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.
from .lib import testcase
from .lib import fs
import hashlib
import os
def sha1(value):
return hashlib.sha1(value).hexdigest()
class XattrTest(testcase.EdenTestCase):
def test_get_sha1_xattr(self):
eden = self.init_git_eden()
filename = os.path.join(eden.mount_path, 'hello')
xattr = fs.getxattr(filename, 'user.sha1')
contents = open(filename, 'rb').read()
expected_sha1 = sha1(contents)
self.assertEqual(expected_sha1, xattr)
# and test what happens as we replace the file contents.
with open(filename, 'w') as f:
f.write('foo')
f.flush()
self.assertEqual(sha1(b'foo'),
fs.getxattr(filename, 'user.sha1'))
f.write('bar')
f.flush()
self.assertEqual(sha1(b'foobar'),
fs.getxattr(filename, 'user.sha1'))
f.write('baz')
self.assertEqual(sha1(b'foobarbaz'),
fs.getxattr(filename, 'user.sha1'))
def test_listxattr(self):
eden = self.init_git_eden()
filename = os.path.join(eden.mount_path, 'hello')
xattrs = fs.listxattr(filename)
contents = open(filename, 'rb').read()
expected_sha1 = sha1(contents)
self.assertEqual({'user.sha1': expected_sha1}, xattrs)