aboutsummaryrefslogtreecommitdiffstats
path: root/models/graph_test.go
blob: 47c9dbb084ddb57a0b02f8a04da8d7a2f3b61ca1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
// 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.

package models

import (
	"testing"

	"code.gitea.io/git"
)

func BenchmarkGetCommitGraph(b *testing.B) {

	currentRepo, err := git.OpenRepository(".")
	if err != nil {
		b.Error("Could not open repository")
	}

	for i := 0; i < b.N; i++ {
		graph, err := GetCommitGraph(currentRepo)
		if err != nil {
			b.Error("Could get commit graph")
		}

		if len(graph) < 100 {
			b.Error("Should get 100 log lines.")
		}
	}
}

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"

	for i := 0; i < b.N; i++ {
		graphItem, err := graphItemFromString(testString, nil)
		if err != nil {
			b.Error("could not parse teststring")
		}

		if graphItem.Author != "Kjell Kvinge" {
			b.Error("Did not get expected data")
		}
	}
}