diff options
author | Ahmad Sherif <me@ahmadsherif.com> | 2017-04-26 19:15:58 +0300 |
---|---|---|
committer | Ahmad Sherif <me@ahmadsherif.com> | 2017-05-01 19:17:36 +0300 |
commit | 48390182fd5ec232f3c12269d767b1f3c3bb3467 (patch) | |
tree | 53cb0e4d847fb0ca1ca93f0692062b9a2058bce6 | |
parent | 518e0219acabd5570b2fc865b91ee76d0ee2e0a9 (diff) |
Extend Paths and IgnoreWhitespaceChange CommitDiff tests
-rw-r--r-- | internal/service/diff/commit_test.go | 127 | ||||
-rw-r--r-- | internal/service/diff/testdata/contributing-md-chunks.txt | 9 | ||||
-rw-r--r-- | internal/service/diff/testdata/maintenance-md-chunks.txt | 9 |
3 files changed, 140 insertions, 5 deletions
diff --git a/internal/service/diff/commit_test.go b/internal/service/diff/commit_test.go index 56a7b1563..e04b30cd6 100644 --- a/internal/service/diff/commit_test.go +++ b/internal/service/diff/commit_test.go @@ -192,13 +192,16 @@ func TestSuccessfulCommitDiffRequestWithPaths(t *testing.T) { client := newDiffClient(t) repo := &pb.Repository{Path: testRepoPath} - rightCommit := "41ae11ba5d091d73d5de671f6fa7d1a4539e979e" - leftCommit := rightCommit + "~~~" // Third ancestor of rightCommit + rightCommit := "e4003da16c1c2c3fc4567700121b17bf8e591c6c" + leftCommit := "8a0f2ee90d940bfb0ba1e14e8214b0649056e4ab" rpcRequest := &pb.CommitDiffRequest{ - Repository: repo, - RightCommitId: rightCommit, - LeftCommitId: leftCommit, + Repository: repo, + RightCommitId: rightCommit, + LeftCommitId: leftCommit, + IgnoreWhitespaceChange: false, Paths: [][]byte{ + []byte("CONTRIBUTING.md"), + []byte("README.md"), []byte("gitaly/named-file-with-mods"), []byte("gitaly/mode-file-with-mods"), }, @@ -212,6 +215,120 @@ func TestSuccessfulCommitDiffRequestWithPaths(t *testing.T) { expectedDiffs := []expectedDiff{ { Diff: diff.Diff{ + FromID: "c1788657b95998a2f177a4f86d68a60f2a80117f", + ToID: "b87f61fe2d7b2e208b340a1f3cafea916bd27f75", + OldMode: 0100644, + NewMode: 0100644, + FromPath: []byte("CONTRIBUTING.md"), + ToPath: []byte("CONTRIBUTING.md"), + Binary: false, + }, + ChunksCombined: testhelper.MustReadFile(t, "testdata/contributing-md-chunks.txt"), + }, + { + Diff: diff.Diff{ + FromID: "faaf198af3a36dbf41961466703cc1d47c61d051", + ToID: "877cee6ab11f9094e1bcdb7f1fd9c0001b572185", + OldMode: 0100644, + NewMode: 0100644, + FromPath: []byte("README.md"), + ToPath: []byte("README.md"), + Binary: false, + }, + ChunksCombined: testhelper.MustReadFile(t, "testdata/readme-md-chunks.txt"), + }, + { + Diff: diff.Diff{ + FromID: "357406f3075a57708d0163752905cc1576fceacc", + ToID: "8e5177d718c561d36efde08bad36b43687ee6bf0", + OldMode: 0100644, + NewMode: 0100755, + FromPath: []byte("gitaly/mode-file-with-mods"), + ToPath: []byte("gitaly/mode-file-with-mods"), + Binary: false, + }, + ChunksCombined: testhelper.MustReadFile(t, "testdata/mode-file-with-mods-chunks.txt"), + }, + { + Diff: diff.Diff{ + FromID: "43d24af4e22580f36b1ca52647c1aff75a766a33", + ToID: "0000000000000000000000000000000000000000", + OldMode: 0100644, + NewMode: 0, + FromPath: []byte("gitaly/named-file-with-mods"), + ToPath: []byte("gitaly/named-file-with-mods"), + Binary: false, + }, + ChunksCombined: testhelper.MustReadFile(t, "testdata/named-file-with-mods-chunks.txt"), + }, + } + + assertExactReceivedDiffs(t, c, expectedDiffs) +} + +func TestSuccessfulCommitDiffRequestWithIgnoreWhitespaceChange(t *testing.T) { + server := runDiffServer(t) + defer server.Stop() + + client := newDiffClient(t) + repo := &pb.Repository{Path: testRepoPath} + rightCommit := "e4003da16c1c2c3fc4567700121b17bf8e591c6c" + leftCommit := "8a0f2ee90d940bfb0ba1e14e8214b0649056e4ab" + rpcRequest := &pb.CommitDiffRequest{ + Repository: repo, + RightCommitId: rightCommit, + LeftCommitId: leftCommit, + IgnoreWhitespaceChange: true, + Paths: [][]byte{ + []byte("CONTRIBUTING.md"), + []byte("MAINTENANCE.md"), + []byte("README.md"), + []byte("gitaly/named-file-with-mods"), + []byte("gitaly/mode-file-with-mods"), + }, + } + + c, err := client.CommitDiff(context.Background(), rpcRequest) + if err != nil { + t.Fatal(err) + } + + expectedDiffs := []expectedDiff{ + { + Diff: diff.Diff{ + FromID: "c1788657b95998a2f177a4f86d68a60f2a80117f", + ToID: "b87f61fe2d7b2e208b340a1f3cafea916bd27f75", + OldMode: 0100644, + NewMode: 0100644, + FromPath: []byte("CONTRIBUTING.md"), + ToPath: []byte("CONTRIBUTING.md"), + Binary: false, + }, + }, + { + Diff: diff.Diff{ + FromID: "95d9f0a5e7bb054e9dd3975589b8dfc689e20e88", + ToID: "5d9c7c0470bf368d61d9b6cd076300dc9d061f14", + OldMode: 0100644, + NewMode: 0100644, + FromPath: []byte("MAINTENANCE.md"), + ToPath: []byte("MAINTENANCE.md"), + Binary: false, + }, + }, + { + Diff: diff.Diff{ + FromID: "faaf198af3a36dbf41961466703cc1d47c61d051", + ToID: "877cee6ab11f9094e1bcdb7f1fd9c0001b572185", + OldMode: 0100644, + NewMode: 0100644, + FromPath: []byte("README.md"), + ToPath: []byte("README.md"), + Binary: false, + }, + }, + { + Diff: diff.Diff{ FromID: "357406f3075a57708d0163752905cc1576fceacc", ToID: "8e5177d718c561d36efde08bad36b43687ee6bf0", OldMode: 0100644, diff --git a/internal/service/diff/testdata/contributing-md-chunks.txt b/internal/service/diff/testdata/contributing-md-chunks.txt new file mode 100644 index 000000000..fda1df647 --- /dev/null +++ b/internal/service/diff/testdata/contributing-md-chunks.txt @@ -0,0 +1,9 @@ +@@ -64,7 +64,7 @@ If you can, please submit a merge request with the fix or improvements including + 1. The MR title should describes the change you want to make + 1. The MR description should give a motive for your change and the method you used to achieve it + 1. If the MR changes the UI it should include before and after screenshots +-1. Link relevant [issues](https://gitlab.com/gitlab-org/gitlab-ce/issues) and/or [feedback items](http://feedback.gitlab.com/) from the merge request description and leave a comment on them with a link back to the MR ++1. Link relevant [issues](https://gitlab.com/gitlab-org/gitlab-ce/issues) and/or [feedback items](http://feedback.gitlab.com/) from the merge request description and leave a comment on them with a link back to the MR + 1. Be prepared to answer questions and incorporate feedback even if requests for this arrive weeks or months after your MR submittion + 1. If your MR touches code that executes shell commands, make sure it adheres to the [shell command guidelines]( doc/development/shell_commands.md). + diff --git a/internal/service/diff/testdata/maintenance-md-chunks.txt b/internal/service/diff/testdata/maintenance-md-chunks.txt new file mode 100644 index 000000000..093586fb0 --- /dev/null +++ b/internal/service/diff/testdata/maintenance-md-chunks.txt @@ -0,0 +1,9 @@ +@@ -16,7 +16,7 @@ GitLab follows the [Semantic Versioning](http://semver.org/) for its releases: + incorrect behavior. + + The current stable release will receive security patches and bug fixes +-(eg. `5.0` -> `5.0.1`). Feature releases will mark the next supported stable ++(eg. `5.0` -> `5.0.1`). Feature releases will mark the next supported stable + release where the minor version is increased numerically by increments of one + (eg. `5.0 -> 5.1`). + |