Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
test(vcs): GetDiffFileList (#3442)
Yilong Libf067ba9344b
diff --git a/plugin/vcs/github/github_test.go b/plugin/vcs/github/github_test.goindex 8e56d0cacb..39640d989b 100644--- a/plugin/vcs/github/github_test.go+++ b/plugin/vcs/github/github_test.go@@ -1308,6 +1308,46 @@ func TestProvider_ListPullRequestFile(t *testing.T) {assert.Equal(t, want, got)}+func TestProvider_GetDiffFileList(t *testing.T) {+ p := newMockProvider(func(r *http.Request) (*http.Response, error) {+ assert.Equal(t, "/api/v3/repos/1/compare/before_sha...after_sha", r.URL.Path)+ return &http.Response{+ StatusCode: http.StatusOK,+ // Example response taken from https://docs.github.com/en/rest/commits/commits#compare-two-commits+ Body: io.NopCloser(strings.NewReader(`+{+ "files": [+ {+ "sha": "bbcd538c8e72b8c175046e27cc8f907076331401",+ "filename": "file1.txt",+ "status": "added",+ "additions": 103,+ "deletions": 21,+ "changes": 124,+ "blob_url": "https://github.com/octocat/Hello-World/blob/6dcb09b5b57875f334f61aebed695e2e4193db5e/file1.txt",+ "raw_url": "https://github.com/octocat/Hello-World/raw/6dcb09b5b57875f334f61aebed695e2e4193db5e/file1.txt",+ "contents_url": "https://api.github.com/repos/octocat/Hello-World/contents/file1.txt?ref=6dcb09b5b57875f334f61aebed695e2e4193db5e",+ "patch": "@@ -132,7 +132,7 @@ module Test @@ -1000,7 +1000,7 @@ module Test"+ }+ ]+}+`)),+ }, nil+ },+ )+ ctx := context.Background()+ got, err := p.GetDiffFileList(ctx, common.OauthContext{}, "", "1", "before_sha", "after_sha")+ require.NoError(t, err)++ want := []vcs.FileDiff{+ {+ Path: "file1.txt",+ Type: vcs.FileDiffTypeAdded,+ },+ }+ assert.Equal(t, want, got)+}+func newMockProvider(mockRoundTrip func(r *http.Request) (*http.Response, error)) vcs.Provider {return newProvider(vcs.ProviderConfig{diff --git a/plugin/vcs/gitlab/gitlab_test.go b/plugin/vcs/gitlab/gitlab_test.goindex 22564517f8..ea29da2b88 100644--- a/plugin/vcs/gitlab/gitlab_test.go+++ b/plugin/vcs/gitlab/gitlab_test.go@@ -1031,6 +1031,62 @@ func TestProvider_ListPullRequestFile(t *testing.T) {assert.Equal(t, want, got)}+func TestProvider_GetDiffFileList(t *testing.T) {+ p := newMockProvider(func(r *http.Request) (*http.Response, error) {+ assert.Equal(t, "/api/v4/projects/1/repository/compare", r.URL.Path)+ assert.Equal(t, "from=before_sha&to=after_sha", r.URL.RawQuery)+ return &http.Response{+ StatusCode: http.StatusOK,+ // Example response taken from https://docs.gitlab.com/ee/api/repositories.html#compare-branches-tags-or-commits+ Body: io.NopCloser(strings.NewReader(`+{+ "commit": {+ "id": "12d65c8dd2b2676fa3ac47d955accc085a37a9c1",+ "short_id": "12d65c8dd2b",+ "title": "JS fix",+ "author_name": "Example User",+ "author_email": "[email protected]",+ "created_at": "2014-02-27T10:27:00+02:00"+ },+ "commits": [{+ "id": "12d65c8dd2b2676fa3ac47d955accc085a37a9c1",+ "short_id": "12d65c8dd2b",+ "title": "JS fix",+ "author_name": "Example User",+ "author_email": "[email protected]",+ "created_at": "2014-02-27T10:27:00+02:00"+ }],+ "diffs": [{+ "old_path": "files/js/application.js",+ "new_path": "files/js/application.js",+ "a_mode": null,+ "b_mode": "100644",+ "diff": "--- a/files/js/application.js\n+++ b/files/js/application.js\n@@ -24,8 +24,10 @@\n //= require g.raphael-min\n //= require g.bar-min\n //= require branch-graph\n-//= require highlightjs.min\n-//= require ace/ace\n //= require_tree .\n //= require d3\n //= require underscore\n+\n+function fix() { \n+ alert(\"Fixed\")\n+}",+ "new_file": false,+ "renamed_file": false,+ "deleted_file": false+ }],+ "compare_timeout": false,+ "compare_same_ref": false,+ "web_url": "https://gitlab.example.com/janedoe/gitlab-foss/-/compare/ae73cb07c9eeaf35924a10f713b364d32b2dd34f...0b4bc9a49b562e85de7cc9e834518ea6828729b9"+}+`)),+ }, nil+ },+ )+ ctx := context.Background()+ got, err := p.GetDiffFileList(ctx, common.OauthContext{}, "", "1", "before_sha", "after_sha")+ require.NoError(t, err)++ want := []vcs.FileDiff{+ {+ Path: "files/js/application.js",+ Type: vcs.FileDiffTypeModified,+ },+ }+ assert.Equal(t, want, got)+}+func newMockProvider(mockRoundTrip func(r *http.Request) (*http.Response, error)) vcs.Provider {return newProvider(vcs.ProviderConfig{