github.com/graybobo/golang.org-package-offline-cache@v0.0.0-20200626051047-6608995c132f/x/review/git-codereview/mail_test.go (about) 1 // Copyright 2014 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 package main 6 7 import ( 8 "fmt" 9 "testing" 10 ) 11 12 func TestMail(t *testing.T) { 13 gt := newGitTest(t) 14 defer gt.done() 15 gt.work(t) 16 17 h := CurrentBranch().Pending()[0].ShortHash 18 19 // fake auth information to avoid Gerrit error 20 auth.host = "gerrit.fake" 21 auth.user = "not-a-user" 22 defer func() { 23 auth.host = "" 24 auth.user = "" 25 }() 26 27 testMain(t, "mail") 28 testRan(t, 29 "git push -q origin HEAD:refs/for/master", 30 "git tag -f work.mailed "+h) 31 } 32 33 func TestMailGitHub(t *testing.T) { 34 gt := newGitTest(t) 35 defer gt.done() 36 gt.work(t) 37 38 trun(t, gt.client, "git", "config", "remote.origin.url", "https://github.com/golang/go") 39 40 testMainDied(t, "mail") 41 testPrintedStderr(t, "git origin must be a Gerrit host, not GitHub: https://github.com/golang/go") 42 } 43 44 func TestMailAmbiguousRevision(t *testing.T) { 45 gt := newGitTest(t) 46 defer gt.done() 47 gt.work(t) 48 49 t.Logf("creating file that conflicts with revision parameter") 50 b := CurrentBranch() 51 mkdir(t, gt.client+"/origin") 52 write(t, gt.client+"/"+b.Branchpoint()+"..HEAD", "foo") 53 54 testMain(t, "mail", "-diff") 55 } 56 57 var reviewerLog = []string{ 58 "Fake 1 <r1@fake.com>", 59 "Fake 1 <r1@fake.com>", 60 "Fake 1 <r1@fake.com>", 61 "Reviewer 1 <r1@golang.org>", 62 "Reviewer 1 <r1@golang.org>", 63 "Reviewer 1 <r1@golang.org>", 64 "Reviewer 1 <r1@golang.org>", 65 "Reviewer 1 <r1@golang.org>", 66 "Other <other@golang.org>", 67 "<anon@golang.org>", 68 } 69 70 func TestMailShort(t *testing.T) { 71 gt := newGitTest(t) 72 defer gt.done() 73 74 // fake auth information to avoid Gerrit error 75 auth.host = "gerrit.fake" 76 auth.user = "not-a-user" 77 defer func() { 78 auth.host = "" 79 auth.user = "" 80 }() 81 82 // Seed commit history with reviewers. 83 for i, addr := range reviewerLog { 84 write(t, gt.server+"/file", fmt.Sprintf("v%d", i)) 85 trun(t, gt.server, "git", "commit", "-a", "-m", "msg\n\nReviewed-by: "+addr+"\n") 86 } 87 trun(t, gt.client, "git", "pull") 88 89 // Do some work. 90 gt.work(t) 91 92 h := CurrentBranch().Pending()[0].ShortHash 93 94 testMain(t, "mail") 95 testRan(t, 96 "git push -q origin HEAD:refs/for/master", 97 "git tag -f work.mailed "+h) 98 99 testMain(t, "mail", "-r", "r1") 100 testRan(t, 101 "git push -q origin HEAD:refs/for/master%r=r1@golang.org", 102 "git tag -f work.mailed "+h) 103 104 testMain(t, "mail", "-r", "other,anon", "-cc", "r1,full@email.com") 105 testRan(t, 106 "git push -q origin HEAD:refs/for/master%r=other@golang.org,r=anon@golang.org,cc=r1@golang.org,cc=full@email.com", 107 "git tag -f work.mailed "+h) 108 109 testMainDied(t, "mail", "-r", "other", "-r", "anon,r1,missing") 110 testPrintedStderr(t, "unknown reviewer: missing") 111 } 112 113 func TestMailTopic(t *testing.T) { 114 gt := newGitTest(t) 115 defer gt.done() 116 gt.work(t) 117 118 h := CurrentBranch().Pending()[0].ShortHash 119 120 // fake auth information to avoid Gerrit error 121 auth.host = "gerrit.fake" 122 auth.user = "not-a-user" 123 defer func() { 124 auth.host = "" 125 auth.user = "" 126 }() 127 128 testMainDied(t, "mail", "-topic", "contains,comma") 129 testPrintedStderr(t, "topic may not contain a comma") 130 131 testMain(t, "mail", "-topic", "test-topic") 132 testRan(t, 133 "git push -q origin HEAD:refs/for/master%topic=test-topic", 134 "git tag -f work.mailed "+h) 135 }