You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

graph_test.go 1.9KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. // Copyright 2016 The Gitea Authors. All rights reserved.
  2. // Use of this source code is governed by a MIT-style
  3. // license that can be found in the LICENSE file.
  4. package models
  5. import (
  6. "fmt"
  7. "testing"
  8. "code.gitea.io/gitea/modules/git"
  9. )
  10. func BenchmarkGetCommitGraph(b *testing.B) {
  11. currentRepo, err := git.OpenRepository(".")
  12. if err != nil {
  13. b.Error("Could not open repository")
  14. }
  15. defer currentRepo.Close()
  16. for i := 0; i < b.N; i++ {
  17. graph, err := GetCommitGraph(currentRepo)
  18. if err != nil {
  19. b.Error("Could get commit graph")
  20. }
  21. if len(graph) < 100 {
  22. b.Error("Should get 100 log lines.")
  23. }
  24. }
  25. }
  26. func BenchmarkParseCommitString(b *testing.B) {
  27. testString := "* DATA:||4e61bacab44e9b4730e44a6615d04098dd3a8eaf|2016-12-20 21:10:41 +0100|Kjell Kvinge|kjell@kvinge.biz|4e61bac|Add route for graph"
  28. for i := 0; i < b.N; i++ {
  29. graphItem, err := graphItemFromString(testString, nil)
  30. if err != nil {
  31. b.Error("could not parse teststring")
  32. }
  33. if graphItem.Author != "Kjell Kvinge" {
  34. b.Error("Did not get expected data")
  35. }
  36. }
  37. }
  38. func TestCommitStringParsing(t *testing.T) {
  39. dataFirstPart := "* DATA:||4e61bacab44e9b4730e44a6615d04098dd3a8eaf|2016-12-20 21:10:41 +0100|Author|user@mail.something|4e61bac|"
  40. tests := []struct {
  41. shouldPass bool
  42. testName string
  43. commitMessage string
  44. }{
  45. {true, "normal", "not a fancy message"},
  46. {true, "extra pipe", "An extra pipe: |"},
  47. {true, "extra 'Data:'", "DATA: might be trouble"},
  48. }
  49. for _, test := range tests {
  50. t.Run(test.testName, func(t *testing.T) {
  51. testString := fmt.Sprintf("%s%s", dataFirstPart, test.commitMessage)
  52. graphItem, err := graphItemFromString(testString, nil)
  53. if err != nil && test.shouldPass {
  54. t.Errorf("Could not parse %s", testString)
  55. return
  56. }
  57. if test.commitMessage != graphItem.Subject {
  58. t.Errorf("%s does not match %s", test.commitMessage, graphItem.Subject)
  59. }
  60. })
  61. }
  62. }