diff options
author | 6543 <6543@obermui.de> | 2020-12-21 17:27:23 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-12-21 18:27:23 +0100 |
commit | 9271040c21580963a6f26a13cf4510893242c572 (patch) | |
tree | 75c8ce0d79b2641c6b638082528121455ae2dd69 | |
parent | 09304db9a5d88c035a96f74a4544572bc8c5dac0 (diff) | |
download | gitea-9271040c21580963a6f26a13cf4510893242c572.tar.gz gitea-9271040c21580963a6f26a13cf4510893242c572.zip |
Add Test for Fix #14040 (#14045)
Add Test for Fix #14040
-rw-r--r-- | modules/git/commit_test.go | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/modules/git/commit_test.go b/modules/git/commit_test.go index bbe12b5aec..9b5fc8f660 100644 --- a/modules/git/commit_test.go +++ b/modules/git/commit_test.go @@ -6,6 +6,7 @@ package git import ( "path/filepath" + "strings" "testing" "github.com/stretchr/testify/assert" @@ -36,3 +37,71 @@ func TestGetFullCommitIDError(t *testing.T) { assert.EqualError(t, err, "object does not exist [id: unknown, rel_path: ]") } } + +func TestCommitFromReader(t *testing.T) { + commitString := `feaf4ba6bc635fec442f46ddd4512416ec43c2c2 commit 1074 +tree f1a6cb52b2d16773290cefe49ad0684b50a4f930 +parent 37991dec2c8e592043f47155ce4808d4580f9123 +author silverwind <me@silverwind.io> 1563741793 +0200 +committer silverwind <me@silverwind.io> 1563741793 +0200 +gpgsig -----BEGIN PGP SIGNATURE----- +` + " " + ` + iQIzBAABCAAdFiEEWPb2jX6FS2mqyJRQLmK0HJOGlEMFAl00zmEACgkQLmK0HJOG + lEMDFBAAhQKKqLD1VICygJMEB8t1gBmNLgvziOLfpX4KPWdPtBk3v/QJ7OrfMrVK + xlC4ZZyx6yMm1Q7GzmuWykmZQJ9HMaHJ49KAbh5MMjjV/+OoQw9coIdo8nagRUld + vX8QHzNZ6Agx77xHuDJZgdHKpQK3TrMDsxzoYYMvlqoLJIDXE1Sp7KYNy12nhdRg + R6NXNmW8oMZuxglkmUwayMiPS+N4zNYqv0CXYzlEqCOgq9MJUcAMHt+KpiST+sm6 + FWkJ9D+biNPyQ9QKf1AE4BdZia4lHfPYU/C/DEL/a5xQuuop/zMQZoGaIA4p2zGQ + /maqYxEIM/yRBQpT1jlODKPJrMEgx7SgY2hRU47YZ4fj6350fb6fNBtiiMAfJbjL + S3Gh85E9fm3hJaNSPKAaJFYL1Ya2svuWfgHj677C56UcmYis7fhiiy1aJuYdHnSm + sD53z/f0J+We4VZjY+pidvA9BGZPFVdR3wd3xGs8/oH6UWaLJAMGkLG6dDb3qDLm + 1LFZwsX8sdD32i1SiWanYQYSYMyFWr0awi4xdoMtYCL7uKBYtwtPyvq3cj4IrJlb + mfeFhT57UbE4qukTDIQ0Y0WM40UYRTakRaDY7ubhXgLgx09Cnp9XTVMsHgT6j9/i + 1pxsB104XLWjQHTjr1JtiaBQEwFh9r2OKTcpvaLcbNtYpo7CzOs= + =FRsO + -----END PGP SIGNATURE----- + +empty commit` + + sha := SHA1{0xfe, 0xaf, 0x4b, 0xa6, 0xbc, 0x63, 0x5f, 0xec, 0x44, 0x2f, 0x46, 0xdd, 0xd4, 0x51, 0x24, 0x16, 0xec, 0x43, 0xc2, 0xc2} + gitRepo, err := OpenRepository(filepath.Join(testReposDir, "repo1_bare")) + assert.NoError(t, err) + assert.NotNil(t, gitRepo) + + commitFromReader, err := CommitFromReader(gitRepo, sha, strings.NewReader(commitString)) + assert.NoError(t, err) + if !assert.NotNil(t, commitFromReader) { + return + } + assert.EqualValues(t, sha, commitFromReader.ID) + assert.EqualValues(t, `-----BEGIN PGP SIGNATURE----- + +iQIzBAABCAAdFiEEWPb2jX6FS2mqyJRQLmK0HJOGlEMFAl00zmEACgkQLmK0HJOG +lEMDFBAAhQKKqLD1VICygJMEB8t1gBmNLgvziOLfpX4KPWdPtBk3v/QJ7OrfMrVK +xlC4ZZyx6yMm1Q7GzmuWykmZQJ9HMaHJ49KAbh5MMjjV/+OoQw9coIdo8nagRUld +vX8QHzNZ6Agx77xHuDJZgdHKpQK3TrMDsxzoYYMvlqoLJIDXE1Sp7KYNy12nhdRg +R6NXNmW8oMZuxglkmUwayMiPS+N4zNYqv0CXYzlEqCOgq9MJUcAMHt+KpiST+sm6 +FWkJ9D+biNPyQ9QKf1AE4BdZia4lHfPYU/C/DEL/a5xQuuop/zMQZoGaIA4p2zGQ +/maqYxEIM/yRBQpT1jlODKPJrMEgx7SgY2hRU47YZ4fj6350fb6fNBtiiMAfJbjL +S3Gh85E9fm3hJaNSPKAaJFYL1Ya2svuWfgHj677C56UcmYis7fhiiy1aJuYdHnSm +sD53z/f0J+We4VZjY+pidvA9BGZPFVdR3wd3xGs8/oH6UWaLJAMGkLG6dDb3qDLm +1LFZwsX8sdD32i1SiWanYQYSYMyFWr0awi4xdoMtYCL7uKBYtwtPyvq3cj4IrJlb +mfeFhT57UbE4qukTDIQ0Y0WM40UYRTakRaDY7ubhXgLgx09Cnp9XTVMsHgT6j9/i +1pxsB104XLWjQHTjr1JtiaBQEwFh9r2OKTcpvaLcbNtYpo7CzOs= +=FRsO +-----END PGP SIGNATURE----- +`, commitFromReader.Signature.Signature) + assert.EqualValues(t, `tree f1a6cb52b2d16773290cefe49ad0684b50a4f930 +parent 37991dec2c8e592043f47155ce4808d4580f9123 +author silverwind <me@silverwind.io> 1563741793 +0200 +committer silverwind <me@silverwind.io> 1563741793 +0200 + +empty commit`, commitFromReader.Signature.Payload) + assert.EqualValues(t, "silverwind <me@silverwind.io>", commitFromReader.Author.String()) + + commitFromReader2, err := CommitFromReader(gitRepo, sha, strings.NewReader(commitString+"\n\n")) + assert.NoError(t, err) + commitFromReader.CommitMessage += "\n\n" + commitFromReader.Signature.Payload += "\n\n" + assert.EqualValues(t, commitFromReader, commitFromReader2) +} |