git p4 test: run as user "author"

The tests use author@example.com as the canonical submitter, but he does not have an entry in the p4 users database. This causes the generated change description to complain that the git and p4 users disagree. The complaint message is still valid, but isn't useful in tests. It was introduced in 848de9c (git-p4: warn if git authorship won't be retained, 2011-05-13). Fix t9813 to use @example.com instead of @localhost due to change in p4_add_user(). Move the function into the git p4 test library so author can be added at initialization time. Signed-off-by: Pete Wyckoff <pw@padd.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Pete Wyckoff committed Jan 21, 2014 at 18:16 UTC 0055b56e10f77b1b5f5521b8ba3614f962a09288
2 files changed +28 -25
t/lib-git-p4.sh
+14 -1
@@ -47,9 +47,10 @@ P4DPORT=$((10669 + ($testid - $git_p4_test_start)))
47
48 P4PORT=localhost:$P4DPORT
49 P4CLIENT=client
50 +P4USER=author
51 P4EDITOR=:
52 unset P4CHARSET
52 -export P4PORT P4CLIENT P4EDITOR P4CHARSET
53 +export P4PORT P4CLIENT P4USER P4EDITOR P4CHARSET
54
55 db="$TRASH_DIRECTORY/db"
56 cli="$TRASH_DIRECTORY/cli"
@@ -96,12 +97,24 @@ start_p4d() {
97 return 1
98 fi
99
100 + # build a p4 user so author@example.com has an entry
101 + p4_add_user author
102 +
103 # build a client
104 client_view "//depot/... //client/..." &&
105
106 return 0
107 }
108
109 +p4_add_user() {
110 + name=$1 &&
111 + p4 user -f -i <<-EOF
112 + User: $name
113 + Email: $name@example.com
114 + FullName: Dr. $name
115 + EOF
116 +}
117 +
118 kill_p4d() {
119 pid=$(cat "$pidfile")
120 # it had better exist for the first kill
t/t9813-git-p4-preserve-users.sh
+14 -24
@@ -19,16 +19,6 @@ test_expect_success 'create files' '
19 )
20 '
21
22 -p4_add_user() {
23 - name=$1 fullname=$2 &&
24 - p4 user -f -i <<-EOF &&
25 - User: $name
26 - Email: $name@localhost
27 - FullName: $fullname
28 - EOF
29 - p4 passwd -P secret $name
30 -}
31 -
22 p4_grant_admin() {
23 name=$1 &&
24 {
@@ -51,8 +41,8 @@ make_change_by_user() {
41
42 # Test username support, submitting as user 'alice'
43 test_expect_success 'preserve users' '
54 - p4_add_user alice Alice &&
55 - p4_add_user bob Bob &&
44 + p4_add_user alice &&
45 + p4_add_user bob &&
46 p4_grant_admin alice &&
47 git p4 clone --dest="$git" //depot &&
48 test_when_finished cleanup_git &&
@@ -60,8 +50,8 @@ test_expect_success 'preserve users' '
50 cd "$git" &&
51 echo "username: a change by alice" >>file1 &&
52 echo "username: a change by bob" >>file2 &&
63 - git commit --author "Alice <alice@localhost>" -m "a change by alice" file1 &&
64 - git commit --author "Bob <bob@localhost>" -m "a change by bob" file2 &&
53 + git commit --author "Alice <alice@example.com>" -m "a change by alice" file1 &&
54 + git commit --author "Bob <bob@example.com>" -m "a change by bob" file2 &&
55 git config git-p4.skipSubmitEditCheck true &&
56 P4EDITOR=touch P4USER=alice P4PASSWD=secret git p4 commit --preserve-user &&
57 p4_check_commit_author file1 alice &&
@@ -78,7 +68,7 @@ test_expect_success 'refuse to preserve users without perms' '
68 cd "$git" &&
69 git config git-p4.skipSubmitEditCheck true &&
70 echo "username-noperms: a change by alice" >>file1 &&
81 - git commit --author "Alice <alice@localhost>" -m "perms: a change by alice" file1 &&
71 + git commit --author "Alice <alice@example.com>" -m "perms: a change by alice" file1 &&
72 P4EDITOR=touch P4USER=bob P4PASSWD=secret &&
73 export P4EDITOR P4USER P4PASSWD &&
74 test_must_fail git p4 commit --preserve-user &&
@@ -94,9 +84,9 @@ test_expect_success 'preserve user where author is unknown to p4' '
84 cd "$git" &&
85 git config git-p4.skipSubmitEditCheck true &&
86 echo "username-bob: a change by bob" >>file1 &&
97 - git commit --author "Bob <bob@localhost>" -m "preserve: a change by bob" file1 &&
87 + git commit --author "Bob <bob@example.com>" -m "preserve: a change by bob" file1 &&
88 echo "username-unknown: a change by charlie" >>file1 &&
99 - git commit --author "Charlie <charlie@localhost>" -m "preserve: a change by charlie" file1 &&
89 + git commit --author "Charlie <charlie@example.com>" -m "preserve: a change by charlie" file1 &&
90 P4EDITOR=touch P4USER=alice P4PASSWD=secret &&
91 export P4EDITOR P4USER P4PASSWD &&
92 test_must_fail git p4 commit --preserve-user &&
@@ -121,24 +111,24 @@ test_expect_success 'not preserving user with mixed authorship' '
111 (
112 cd "$git" &&
113 git config git-p4.skipSubmitEditCheck true &&
124 - p4_add_user derek Derek &&
114 + p4_add_user derek &&
115
126 - make_change_by_user usernamefile3 Derek derek@localhost &&
116 + make_change_by_user usernamefile3 Derek derek@example.com &&
117 P4EDITOR=cat P4USER=alice P4PASSWD=secret &&
118 export P4EDITOR P4USER P4PASSWD &&
119 git p4 commit |\
130 - grep "git author derek@localhost does not match" &&
120 + grep "git author derek@example.com does not match" &&
121
132 - make_change_by_user usernamefile3 Charlie charlie@localhost &&
122 + make_change_by_user usernamefile3 Charlie charlie@example.com &&
123 git p4 commit |\
134 - grep "git author charlie@localhost does not match" &&
124 + grep "git author charlie@example.com does not match" &&
125
136 - make_change_by_user usernamefile3 alice alice@localhost &&
126 + make_change_by_user usernamefile3 alice alice@example.com &&
127 git p4 commit |\
128 test_must_fail grep "git author.*does not match" &&
129
130 git config git-p4.skipUserNameCheck true &&
141 - make_change_by_user usernamefile3 Charlie charlie@localhost &&
131 + make_change_by_user usernamefile3 Charlie charlie@example.com &&
132 git p4 commit |\
133 test_must_fail grep "git author.*does not match" &&
134