mirror of
https://github.com/kubescape/kubescape.git
synced 2026-04-05 10:16:52 +00:00
* use go-gitlog as an alternative to git2go Signed-off-by: Matthias Bertschy <matthias.bertschy@gmail.com> * set RELEASE to something to avoid failing binary-build step Signed-off-by: Matthias Bertschy <matthias.bertschy@gmail.com> --------- Signed-off-by: Matthias Bertschy <matthias.bertschy@gmail.com>
59 lines
1.8 KiB
Go
59 lines
1.8 KiB
Go
package cautils
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func (s *LocalGitRepositoryTestSuite) TestGetLastCommit() {
|
|
if localRepo, err := NewLocalGitRepository(s.gitRepositoryPaths["localrepo"]); s.NoError(err) {
|
|
if commit, err := localRepo.GetLastCommit(); s.NoError(err) {
|
|
s.Equal("7e09312b8017695fadcd606882e3779f10a5c832", commit.SHA)
|
|
s.Equal("Amir Malka", commit.Author.Name)
|
|
s.Equal("amirm@armosec.io", commit.Author.Email)
|
|
s.Equal(int64(1653235917), commit.Author.Date.Unix())
|
|
s.Equal("added file B\n", commit.Message)
|
|
}
|
|
}
|
|
}
|
|
|
|
func (s *LocalGitRepositoryTestSuite) TestGetFileLastCommit() {
|
|
s.Run("fileA", func() {
|
|
if localRepo, err := NewLocalGitRepository(s.gitRepositoryPaths["localrepo"]); s.NoError(err) {
|
|
|
|
if commit, err := localRepo.GetFileLastCommit("fileA"); s.NoError(err) {
|
|
s.Equal("9fae4be19624297947d2b605cefbff516628612d", commit.SHA)
|
|
s.Equal("Amir Malka", commit.Author.Name)
|
|
s.Equal("amirm@armosec.io", commit.Author.Email)
|
|
s.Equal(int64(1653234948), commit.Author.Date.Unix())
|
|
s.Equal("added file A\n", commit.Message)
|
|
}
|
|
|
|
}
|
|
})
|
|
|
|
s.Run("fileB", func() {
|
|
if localRepo, err := NewLocalGitRepository(s.gitRepositoryPaths["localrepo"]); s.NoError(err) {
|
|
|
|
if commit, err := localRepo.GetFileLastCommit("dirA/fileB"); s.NoError(err) {
|
|
s.Equal("7e09312b8017695fadcd606882e3779f10a5c832", commit.SHA)
|
|
s.Equal("Amir Malka", commit.Author.Name)
|
|
s.Equal("amirm@armosec.io", commit.Author.Email)
|
|
s.Equal(int64(1653235917), commit.Author.Date.Unix())
|
|
s.Equal("added file B\n", commit.Message)
|
|
}
|
|
|
|
}
|
|
})
|
|
}
|
|
|
|
func BenchmarkBuildCommitMap(b *testing.B) {
|
|
localRepo, err := NewLocalGitRepository("testdata/temp/localrepo")
|
|
assert.NoError(b, err)
|
|
for i := 0; i < b.N; i++ {
|
|
localRepo.buildCommitMap()
|
|
}
|
|
b.ReportAllocs()
|
|
}
|