2016-12-29 05:14:32 +05:30
|
|
|
// Copyright 2016 The Gitea Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a MIT-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
2019-11-16 06:17:57 +05:30
|
|
|
package gitgraph
|
2016-12-29 05:14:32 +05:30
|
|
|
|
|
|
|
import (
|
2018-07-21 23:47:10 +05:30
|
|
|
"fmt"
|
2016-12-29 05:14:32 +05:30
|
|
|
"testing"
|
|
|
|
|
2019-03-27 15:03:00 +05:30
|
|
|
"code.gitea.io/gitea/modules/git"
|
2016-12-29 05:14:32 +05:30
|
|
|
)
|
|
|
|
|
|
|
|
func BenchmarkGetCommitGraph(b *testing.B) {
|
|
|
|
|
|
|
|
currentRepo, err := git.OpenRepository(".")
|
|
|
|
if err != nil {
|
|
|
|
b.Error("Could not open repository")
|
|
|
|
}
|
2019-11-13 12:31:19 +05:30
|
|
|
defer currentRepo.Close()
|
2016-12-29 05:14:32 +05:30
|
|
|
|
2017-01-03 08:22:09 +05:30
|
|
|
for i := 0; i < b.N; i++ {
|
2019-10-15 03:08:35 +05:30
|
|
|
graph, err := GetCommitGraph(currentRepo, 1)
|
2017-01-03 08:22:09 +05:30
|
|
|
if err != nil {
|
|
|
|
b.Error("Could get commit graph")
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(graph) < 100 {
|
|
|
|
b.Error("Should get 100 log lines.")
|
|
|
|
}
|
2016-12-29 05:14:32 +05:30
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func BenchmarkParseCommitString(b *testing.B) {
|
|
|
|
testString := "* DATA:||4e61bacab44e9b4730e44a6615d04098dd3a8eaf|2016-12-20 21:10:41 +0100|Kjell Kvinge|kjell@kvinge.biz|4e61bac|Add route for graph"
|
|
|
|
|
2017-01-03 08:22:09 +05:30
|
|
|
for i := 0; i < b.N; i++ {
|
|
|
|
graphItem, err := graphItemFromString(testString, nil)
|
|
|
|
if err != nil {
|
|
|
|
b.Error("could not parse teststring")
|
|
|
|
}
|
2016-12-29 05:14:32 +05:30
|
|
|
|
2017-01-03 08:22:09 +05:30
|
|
|
if graphItem.Author != "Kjell Kvinge" {
|
|
|
|
b.Error("Did not get expected data")
|
|
|
|
}
|
2016-12-29 05:14:32 +05:30
|
|
|
}
|
|
|
|
}
|
2018-07-21 23:47:10 +05:30
|
|
|
|
|
|
|
func TestCommitStringParsing(t *testing.T) {
|
|
|
|
dataFirstPart := "* DATA:||4e61bacab44e9b4730e44a6615d04098dd3a8eaf|2016-12-20 21:10:41 +0100|Author|user@mail.something|4e61bac|"
|
|
|
|
tests := []struct {
|
|
|
|
shouldPass bool
|
|
|
|
testName string
|
|
|
|
commitMessage string
|
|
|
|
}{
|
|
|
|
{true, "normal", "not a fancy message"},
|
|
|
|
{true, "extra pipe", "An extra pipe: |"},
|
|
|
|
{true, "extra 'Data:'", "DATA: might be trouble"},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, test := range tests {
|
|
|
|
|
|
|
|
t.Run(test.testName, func(t *testing.T) {
|
|
|
|
testString := fmt.Sprintf("%s%s", dataFirstPart, test.commitMessage)
|
|
|
|
graphItem, err := graphItemFromString(testString, nil)
|
|
|
|
if err != nil && test.shouldPass {
|
|
|
|
t.Errorf("Could not parse %s", testString)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if test.commitMessage != graphItem.Subject {
|
|
|
|
t.Errorf("%s does not match %s", test.commitMessage, graphItem.Subject)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|