Skip to content

Commit

Permalink
fix: Add a test for PullRequest.ListChanges in Gitea
Browse files Browse the repository at this point in the history
Signed-off-by: Andrew Bayer <[email protected]>
  • Loading branch information
abayer committed Sep 4, 2020
1 parent 3fa135d commit 229d843
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 4 deletions.
27 changes: 23 additions & 4 deletions scm/driver/gitea/pr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ package gitea
import (
"context"
"encoding/json"
"github.com/stretchr/testify/assert"
"io/ioutil"
"testing"

Expand Down Expand Up @@ -122,12 +123,30 @@ func TestPullRequestMerge(t *testing.T) {
// pull request change sub-tests
//

// TODO: Actually write a real test for generating changes from a patch
func TestPullRequestChanges(t *testing.T) {
defer gock.Off()

gock.New("https://try.gitea.io").
Get("/api/v1/repos/go-gitea/gitea/pulls/1.patch").
Reply(204).
Type("text/plain").
File("testdata/pr_changes.patch")


client, _ := New("https://try.gitea.io")
_, _, err := client.PullRequests.ListChanges(context.Background(), "go-gitea/gitea", 1, scm.ListOptions{})
if err == scm.ErrNotSupported {
t.Errorf("Didn't expect Not Supported error")
got, _, err := client.PullRequests.ListChanges(context.Background(), "go-gitea/gitea", 1, scm.ListOptions{})
if err != nil {
t.Error(err)
}

want := []*scm.Change{}
raw, _ := ioutil.ReadFile("testdata/pr_changes.json.golden")
err = json.Unmarshal(raw, &want)
assert.NoError(t, err)

if diff := cmp.Diff(got, want); diff != "" {
t.Errorf("Unexpected Results")
t.Log(diff)
}
}

Expand Down
13 changes: 13 additions & 0 deletions scm/driver/gitea/testdata/pr_changes.json.golden
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[
{
"Path": "README",
"Added": true,
"Additions": 1
},
{
"Path": "script.sh",
"PreviousPath": "script.sh",
"Additions": 1,
"Deletions": 1
}
]
30 changes: 30 additions & 0 deletions scm/driver/gitea/testdata/pr_changes.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
From 3c716f1eb086c9039745e3cadf873c9cbbb481e5 Mon Sep 17 00:00:00 2001
From: jenkins-x-bot <[email protected]>
Date: Fri, 4 Sep 2020 15:16:56 +0000
Subject: [PATCH] Adding for test PR

---
README | 1 +
script.sh | 2 +-
2 files changed, 2 insertions(+), 1 deletion(-)
create mode 100644 README

diff --git a/README b/README
new file mode 100644
index 0000000..70c379b
--- /dev/null
+++ b/README
@@ -0,0 +1 @@
+Hello world
\ No newline at end of file
diff --git a/script.sh b/script.sh
index 4915bcb..2c42f17 100644
--- a/script.sh
+++ b/script.sh
@@ -1,3 +1,3 @@
#!/bin/bash

-echo "This passes"
+echo "This has changed but still passes"
--
2.24.3

0 comments on commit 229d843

Please sign in to comment.