sapling/tests/test-fb-hgext-phabstatus.t
Francisco Massa 8efc997f51 phabricator-graphql: nice error message if ~/.arcrc is bad
Summary: When running hg ssl, if the .arcrc file is not proper JSON
(e.g., has a trailing comma), json.loads raises an exception that
was not being caught and lead to a stacktrace.

Test Plan: Locally run hg ssl with a bag .arcrc and the stack trace was gone.
Also write a test in test-fb-hgext-phabstatus.t

Reviewers: simonfar

Subscribers: luizmramos

Tasks: T24993088

Tags:
2018-01-12 10:46:25 +00:00

97 lines
3.4 KiB
Perl

Setup
$ PYTHONPATH=$TESTDIR/..:$PYTHONPATH
$ export PYTHONPATH
$ cat >> $HGRCPATH << EOF
> [extensions]
> arcconfig=$TESTDIR/../hgext/extlib/phabricator/arcconfig.py
> phabstatus=
> smartlog=
> EOF
$ hg init repo
$ cd repo
$ touch foo
$ hg ci -qAm 'Differential Revision: https://phabricator.fb.com/D1'
With an invalid arc configuration
$ hg log -T '{phabstatus}\n' -r .
arcconfig configuration problem. No diff information can be provided.
Error info: no .arcconfig found
Error
Configure arc...
$ echo '{}' > .arcrc
$ echo '{"config" : {"default" : "https://a.com/api"}, "hosts" : {"https://a.com/api/" : { "user" : "testuser", "cert" : "garbage_cert"}}}' > .arcconfig
And now with bad responses:
$ cat > $TESTTMP/mockduit << EOF
> [{"cmd": ["differential.querydiffhashes", {"revisionIDs": ["1"]}], "result": {}}]
> EOF
$ HG_ARC_CONDUIT_MOCK=$TESTTMP/mockduit hg log -T '{phabstatus}\n' -r .
Error
$ cat > $TESTTMP/mockduit << EOF
> [{"cmd": ["differential.querydiffhashes", {"revisionIDs": ["1"]}], "error_info": "failed, yo"}]
> EOF
$ HG_ARC_CONDUIT_MOCK=$TESTTMP/mockduit hg log -T '{phabstatus}\n' -r .
Error talking to phabricator. No diff information can be provided.
Error info: failed, yo
Error
Missing status field is treated as an error
$ cat > $TESTTMP/mockduit << EOF
> [{"cmd": ["differential.querydiffhashes", {"revisionIDs": ["1"]}],
> "result": {"1" : {"hash": "this is the best hash ewa"}}}]
> EOF
$ HG_ARC_CONDUIT_MOCK=$TESTTMP/mockduit hg log -T '{phabstatus}\n' -r .
Error
And finally, the success case
$ cat > $TESTTMP/mockduit << EOF
> [{"cmd": ["differential.querydiffhashes", {"revisionIDs": ["1"]}],
> "result": {"1" : {"count": 1, "status": "Needs Review", "hash": "lolwut"}}}]
> EOF
$ HG_ARC_CONDUIT_MOCK=$TESTTMP/mockduit hg log -T '{phabstatus}\n' -r .
Needs Review
Make sure the code works without the smartlog extensions
$ cat > $TESTTMP/mockduit << EOF
> [{"cmd": ["differential.querydiffhashes", {"revisionIDs": ["1"]}],
> "result": {"1" : {"count": 1, "status": "Needs Review", "hash": "lolwut"}}}]
> EOF
$ HG_ARC_CONDUIT_MOCK=$TESTTMP/mockduit hg --config 'extensions.smartlog=!' log -T '{phabstatus}\n' -r .
Needs Review
Make sure the template keywords are documented correctly
$ hg help templates | egrep 'phabstatus|syncstatus'
phabstatus String. Return the diff approval status for a given hg rev
syncstatus String. Return whether the local revision is in sync with
Make sure we get decent error messages when .arcrc is missing credential
information. We intentionally do not use HG_ARC_CONDUIT_MOCK for this test,
so it tries to parse the (empty) arc config files.
$ echo '{}' > .arcrc
$ echo '{}' > .arcconfig
$ hg log -T '{phabstatus}\n' -r .
arcconfig configuration problem. No diff information can be provided.
Error info: arcrc is missing user credentials for host None. use "arc install-certificate" to fix.
Error
Make sure we get an error message if .arcrc is not proper JSON (for example
due to trailing commas). We do not use HG_ARC_CONDUIT_MOCK for this test,
in order for it to parse the badly formatted arc config file.
$ echo '{,}' > ../.arcrc
$ hg log -T '{phabstatus}\n' -r .
arcconfig configuration problem. No diff information can be provided.
Error info: Configuration file $TESTTMP/.arcrc is not a proper JSON file.
Error