tests: convert test-hgsql-filenames.t

Summary:
Converts test-hgsql-filenames.t to be a -t.py test and converts the
hgsql test infra to work in -t.py tests.

Reviewed By: quark-zju

Differential Revision: D17611277

fbshipit-source-id: 8c75ad01a6af743e912312bdc603529dd0f2cf4b
This commit is contained in:
Durham Goode 2019-10-02 10:10:15 -07:00 committed by Facebook Github Bot
parent 396ce90580
commit 413b536a21
6 changed files with 151 additions and 28 deletions

1
.gitignore vendored
View File

@ -29,6 +29,7 @@ tests/*.err
fb/tests/*.err
tests/htmlcov
tests/getdb.sh
tests/testutil/getdb.py
contrib/chg/chg
contrib/chg/libchg.a
contrib/hgsh/hgsh

View File

@ -93,8 +93,5 @@ configureclient() {
cat >> $1/.hg/hgrc <<EOF
[ui]
ssh=python "$TESTDIR/dummyssh"
[extensions]
hgsql=
EOF
}

View File

@ -0,0 +1,34 @@
# Copyright (c) Facebook, Inc. and its affiliates.
#
# This software may be used and distributed according to the terms of the
# GNU General Public License version 2 or any later version.
from __future__ import absolute_import
from testutil.dott import feature, sh, testtmp # noqa: F401
sh % ". '$TESTDIR/hgsql/library.sh'"
sh % "initdb"
sh % "setconfig 'extensions.treemanifest=!'"
# Populate the db with an initial commit
sh % "initclient client"
sh % "cd client"
sh % "echo x" > "x"
sh % "hg commit -qAm x"
sh % "cd .."
sh % "initserver master masterrepo"
sh % "cd master"
sh % "hg log"
sh % "hg pull -q ../client"
# Verify committing odd filenames works (with % character)
sh % "hg up" == "1 files updated, 0 files merged, 0 files removed, 0 files unresolved"
sh % "echo a" > "bad%name"
sh % "hg commit -Am badname" == "adding bad%name"
sh % "echo b" > "bad%name"
sh % "hg commit -Am badname2"

View File

@ -1,25 +0,0 @@
$ . "$TESTDIR/hgsql/library.sh"
$ setconfig extensions.treemanifest=!
# Populate the db with an initial commit
$ initclient client
$ cd client
$ echo x > x
$ hg commit -qAm x
$ cd ..
$ initserver master masterrepo
$ cd master
$ hg log
$ hg pull -q ../client
# Verify committing odd filenames works (with % character)
$ hg up
1 files updated, 0 files merged, 0 files removed, 0 files unresolved
$ echo a > 'bad%name'
$ hg commit -Am badname
adding bad%name
$ echo b > 'bad%name'
$ hg commit -Am badname2

View File

@ -254,6 +254,11 @@ def source(path):
from . import remotefilelog
defs = remotefilelog.__dict__
elif name == "hgsql":
# hgsql helpers
from . import hgsql
defs = hgsql.__dict__
if defs:
for name, body in defs.items():
if callable(body):

View File

@ -0,0 +1,111 @@
# Copyright 2019 Facebook, Inc.
#
# This software may be used and distributed according to the terms of the
# GNU General Public License version 2 or any later version.
# Ported from tests/hgsql/library.sh
from __future__ import absolute_import
import os
import subprocess
from .. import shlib, testtmp
try:
from ... import getdb
except ImportError:
import sys
sys.exit(80)
dbconfig = None
def _createdatabase():
schema = open(
shlib.expandpath("$TESTDIR/hgsql/schema.%s.sql" % dbconfig["dbengine"]), "rb"
).read()
p = subprocess.Popen(
[
"mysql",
"-h%s" % dbconfig["dbhost"],
"-P%s" % dbconfig["dbport"],
"-u%s" % dbconfig["dbuser"],
"-p%s" % dbconfig["dbpass"],
],
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
)
stdout, stderr = p.communicate(
r"""
CREATE DATABASE IF NOT EXISTS {dbname};
USE {dbname};
DROP TABLE IF EXISTS revisions;
DROP TABLE IF EXISTS revision_references;
DROP TABLE IF EXISTS repo_lock;
{schema}
""".format(
dbname=dbconfig["dbname"], dbengine=dbconfig["dbengine"], schema=schema
)
)
if p.returncode != 0:
raise RuntimeError("failed to create mysql database: %s\n%s" % (stdout, stderr))
def initdb():
global dbconfig
dbconfig = getdb.get_db_config()
_createdatabase()
def initserver(servername, dbname):
shlib.hg("init", "--config=extensions.hgsql=", servername)
configureserver(servername, dbname)
def configureserver(servername, reponame):
config = dict(dbconfig)
config["reponame"] = reponame
open(os.path.join(servername, ".hg/hgrc"), "ab").write(
r"""
[extensions]
hgsql=
[hgsql]
enabled = True
host = {dbhost}
database = {dbname}
user = {dbuser}
password = {dbpass}
port = {dbport}
reponame = {reponame}
engine = {dbengine}
[server]
preferuncompressed=True
uncompressed=True
[ui]
ssh=python "$TESTDIR/dummyssh"
""".format(
**config
)
)
def initclient(name):
shlib.hg("init", name)
configureclient(name)
def configureclient(name):
open(os.path.join(name, ".hg/hgrc"), "ab").write(
r"""
[ui]
ssh=python "$TESTDIR/dummyssh"
"""
)