Skip to content

Commit

Permalink
add tests for additions and deletions
Browse files Browse the repository at this point in the history
  • Loading branch information
g14a committed Mar 6, 2021
1 parent f2489ed commit 1d8dd2f
Show file tree
Hide file tree
Showing 13 changed files with 59 additions and 11 deletions.
4 changes: 4 additions & 0 deletions pkg/cmd/pr/view/fixtures/prView.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
"headRepositoryOwner": {
"login": "hubot"
},
"additions": 100,
"deletions": 10,
"commits": {
"totalCount": 12
},
Expand All @@ -34,6 +36,8 @@
"author": {
"login": "nobody"
},
"additions": 100,
"deletions": 10,
"headRepositoryOwner": {
"login": "OWNER"
},
Expand Down
2 changes: 2 additions & 0 deletions pkg/cmd/pr/view/fixtures/prViewPreview.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
"author": {
"login": "nobody"
},
"additions": 100,
"deletions": 10,
"assignees": {
"nodes": [],
"totalcount": 0
Expand Down
2 changes: 2 additions & 0 deletions pkg/cmd/pr/view/fixtures/prViewPreviewClosedState.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
"author": {
"login": "nobody"
},
"additions": 100,
"deletions": 10,
"commits": {
"totalCount": 12
},
Expand Down
2 changes: 2 additions & 0 deletions pkg/cmd/pr/view/fixtures/prViewPreviewDraftState.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
"commits": {
"totalCount": 12
},
"additions": 100,
"deletions": 10,
"baseRefName": "master",
"headRefName": "blueberries",
"headRepositoryOwner": {
Expand Down
4 changes: 4 additions & 0 deletions pkg/cmd/pr/view/fixtures/prViewPreviewDraftStatebyBranch.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
"headRepositoryOwner": {
"login": "hubot"
},
"additions": 100,
"deletions": 10,
"commits": {
"totalCount": 12
},
Expand All @@ -37,6 +39,8 @@
"headRepositoryOwner": {
"login": "OWNER"
},
"additions": 100,
"deletions": 10,
"commits": {
"totalCount": 8
},
Expand Down
2 changes: 2 additions & 0 deletions pkg/cmd/pr/view/fixtures/prViewPreviewMergedState.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
"commits": {
"totalCount": 12
},
"additions": 100,
"deletions": 10,
"baseRefName": "master",
"headRefName": "blueberries",
"headRepositoryOwner": {
Expand Down
2 changes: 2 additions & 0 deletions pkg/cmd/pr/view/fixtures/prViewPreviewSingleComment.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
"author": {
"login": "nobody"
},
"additions": 100,
"deletions": 10,
"assignees": {
"nodes": [],
"totalcount": 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
"url": "https://github.com/OWNER/REPO/pull/12",
"headRefName": "blueberries",
"baseRefName": "master",
"additions": 100,
"deletions": 10,
"headRepositoryOwner": {
"login": "hubot"
},
Expand Down Expand Up @@ -49,6 +51,8 @@
"author": {
"login": "nobody"
},
"additions": 100,
"deletions": 10,
"assignees": {
"nodes": [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
"author": {
"login": "nobody"
},
"additions": 100,
"deletions": 10,
"reviewRequests": {
"nodes": [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
"author": {
"login": "nobody"
},
"additions": 100,
"deletions": 10,
"reviewRequests": {
"nodes": [
{
Expand Down
4 changes: 4 additions & 0 deletions pkg/cmd/pr/view/fixtures/prView_EmptyBody.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
"headRepositoryOwner": {
"login": "hubot"
},
"additions": 100,
"deletions": 10,
"commits": {
"totalCount": 12
},
Expand All @@ -30,6 +32,8 @@
"url": "https://github.com/OWNER/REPO/pull/10",
"baseRefName": "master",
"headRefName": "blueberries",
"additions": 100,
"deletions": 10,
"author": {
"login": "nobody"
},
Expand Down
4 changes: 2 additions & 2 deletions pkg/cmd/pr/view/view.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,8 @@ func printRawPrPreview(io *iostreams.IOStreams, pr *api.PullRequest) error {
fmt.Fprintf(out, "milestone:\t%s\n", pr.Milestone.Title)
fmt.Fprintf(out, "number:\t%d\n", pr.Number)
fmt.Fprintf(out, "url:\t%s\n", pr.URL)
fmt.Fprintf(out, "additions:\t+%s\n", cs.Green(strconv.Itoa(pr.Additions)))
fmt.Fprintf(out, "deletions:\t-%s\n", cs.Red(strconv.Itoa(pr.Deletions)))
fmt.Fprintf(out, "additions:\t%s\n", cs.Green(strconv.Itoa(pr.Additions)))
fmt.Fprintf(out, "deletions:\t%s\n", cs.Red(strconv.Itoa(pr.Deletions)))

fmt.Fprintln(out, "--")
fmt.Fprintln(out, pr.Body)
Expand Down
36 changes: 27 additions & 9 deletions pkg/cmd/pr/view/view_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,8 @@ func TestPRView_Preview_nontty(t *testing.T) {
`projects:\t\n`,
`milestone:\t\n`,
`url:\thttps://github.com/OWNER/REPO/pull/12\n`,
`additions:\t100\n`,
`deletions:\t10\n`,
`number:\t12\n`,
`blueberries taste good`,
},
Expand Down Expand Up @@ -221,6 +223,8 @@ func TestPRView_Preview_nontty(t *testing.T) {
`assignees:\t\n`,
`projects:\t\n`,
`milestone:\t\n`,
`additions:\t100\n`,
`deletions:\t10\n`,
`reviewers:\tDEF \(Commented\), def \(Changes requested\), ghost \(Approved\), hubot \(Commented\), xyz \(Approved\), 123 \(Requested\), Team 1 \(Requested\), abc \(Requested\)\n`,
`\*\*blueberries taste good\*\*`,
},
Expand All @@ -241,6 +245,8 @@ func TestPRView_Preview_nontty(t *testing.T) {
`labels:\tone, two, three, four, five\n`,
`projects:\tProject 1 \(column A\), Project 2 \(column B\), Project 3 \(column C\)\n`,
`milestone:\tuluru\n`,
`additions:\t100\n`,
`deletions:\t10\n`,
`blueberries taste good`,
},
},
Expand All @@ -260,6 +266,8 @@ func TestPRView_Preview_nontty(t *testing.T) {
`labels:\t\n`,
`projects:\t\n`,
`milestone:\t\n`,
`additions:\t100\n`,
`deletions:\t10\n`,
`\*\*blueberries taste good\*\*`,
},
},
Expand All @@ -279,6 +287,8 @@ func TestPRView_Preview_nontty(t *testing.T) {
`labels:\t\n`,
`projects:\t\n`,
`milestone:\t\n`,
`additions:\t100\n`,
`deletions:\t10\n`,
},
},
"Closed PR": {
Expand All @@ -296,6 +306,8 @@ func TestPRView_Preview_nontty(t *testing.T) {
`reviewers:\t\n`,
`projects:\t\n`,
`milestone:\t\n`,
`additions:\t100\n`,
`deletions:\t10\n`,
`\*\*blueberries taste good\*\*`,
},
},
Expand All @@ -314,6 +326,8 @@ func TestPRView_Preview_nontty(t *testing.T) {
`reviewers:\t\n`,
`projects:\t\n`,
`milestone:\t\n`,
`additions:\t100\n`,
`deletions:\t10\n`,
`\*\*blueberries taste good\*\*`,
},
},
Expand All @@ -333,6 +347,8 @@ func TestPRView_Preview_nontty(t *testing.T) {
`reviewers:`,
`projects:`,
`milestone:`,
`additions:\t100\n`,
`deletions:\t10\n`,
`\*\*blueberries taste good\*\*`,
},
},
Expand All @@ -352,6 +368,8 @@ func TestPRView_Preview_nontty(t *testing.T) {
`reviewers:`,
`projects:`,
`milestone:`,
`additions:\t100\n`,
`deletions:\t10\n`,
`\*\*blueberries taste good\*\*`,
},
},
Expand Down Expand Up @@ -395,7 +413,7 @@ func TestPRView_Preview(t *testing.T) {
},
expectedOutputs: []string{
`Blueberries are from a fork`,
`Open.*nobody wants to merge 12 commits into master from blueberries`,
`Open.*nobody wants to merge 12 commits into master from blueberries.+100.-10`,
`blueberries taste good`,
`View this pull request on GitHub: https://github.com/OWNER/REPO/pull/12`,
},
Expand All @@ -409,7 +427,7 @@ func TestPRView_Preview(t *testing.T) {
},
expectedOutputs: []string{
`Blueberries are from a fork`,
`Open.*nobody wants to merge 12 commits into master from blueberries`,
`Open.*nobody wants to merge 12 commits into master from blueberries.+100.-10`,
`Reviewers:.*1 \(.*Requested.*\)\n`,
`Assignees:.*marseilles, monaco\n`,
`Labels:.*one, two, three, four, five\n`,
Expand Down Expand Up @@ -442,7 +460,7 @@ func TestPRView_Preview(t *testing.T) {
},
expectedOutputs: []string{
`Blueberries are a good fruit`,
`Open.*nobody wants to merge 8 commits into master from blueberries`,
`Open.*nobody wants to merge 8 commits into master from blueberries.+100.-10`,
`Assignees:.*marseilles, monaco\n`,
`Labels:.*one, two, three, four, five\n`,
`Projects:.*Project 1 \(column A\), Project 2 \(column B\), Project 3 \(column C\)\n`,
Expand All @@ -460,7 +478,7 @@ func TestPRView_Preview(t *testing.T) {
},
expectedOutputs: []string{
`Blueberries are a good fruit`,
`Open.*nobody wants to merge 8 commits into master from blueberries`,
`Open.*nobody wants to merge 8 commits into master from blueberries.+100.-10`,
`blueberries taste good`,
`View this pull request on GitHub: https://github.com/OWNER/REPO/pull/10`,
},
Expand All @@ -474,7 +492,7 @@ func TestPRView_Preview(t *testing.T) {
},
expectedOutputs: []string{
`Blueberries are a good fruit`,
`Open.*nobody wants to merge 8 commits into master from blueberries`,
`Open.*nobody wants to merge 8 commits into master from blueberries.+100.-10`,
`View this pull request on GitHub: https://github.com/OWNER/REPO/pull/10`,
},
},
Expand All @@ -487,7 +505,7 @@ func TestPRView_Preview(t *testing.T) {
},
expectedOutputs: []string{
`Blueberries are from a fork`,
`Closed.*nobody wants to merge 12 commits into master from blueberries`,
`Closed.*nobody wants to merge 12 commits into master from blueberries.+100.-10`,
`blueberries taste good`,
`View this pull request on GitHub: https://github.com/OWNER/REPO/pull/12`,
},
Expand All @@ -501,7 +519,7 @@ func TestPRView_Preview(t *testing.T) {
},
expectedOutputs: []string{
`Blueberries are from a fork`,
`Merged.*nobody wants to merge 12 commits into master from blueberries`,
`Merged.*nobody wants to merge 12 commits into master from blueberries.+100.-10`,
`blueberries taste good`,
`View this pull request on GitHub: https://github.com/OWNER/REPO/pull/12`,
},
Expand All @@ -515,7 +533,7 @@ func TestPRView_Preview(t *testing.T) {
},
expectedOutputs: []string{
`Blueberries are from a fork`,
`Draft.*nobody wants to merge 12 commits into master from blueberries`,
`Draft.*nobody wants to merge 12 commits into master from blueberries.+100.-10`,
`blueberries taste good`,
`View this pull request on GitHub: https://github.com/OWNER/REPO/pull/12`,
},
Expand All @@ -529,7 +547,7 @@ func TestPRView_Preview(t *testing.T) {
},
expectedOutputs: []string{
`Blueberries are a good fruit`,
`Draft.*nobody wants to merge 8 commits into master from blueberries`,
`Draft.*nobody wants to merge 8 commits into master from blueberries.+100.-10`,
`blueberries taste good`,
`View this pull request on GitHub: https://github.com/OWNER/REPO/pull/10`,
},
Expand Down

0 comments on commit 1d8dd2f

Please sign in to comment.