github.com/gitbundle/modules@v0.0.0-20231025071548-85b91c5c3b01/git/repo_stats_test.go (about)

     1  // Copyright 2023 The GitBundle Inc. All rights reserved.
     2  // Copyright 2017 The Gitea Authors. All rights reserved.
     3  // Use of this source code is governed by a MIT-style
     4  // license that can be found in the LICENSE file.
     5  
     6  package git
     7  
     8  import (
     9  	"path/filepath"
    10  	"testing"
    11  	"time"
    12  
    13  	"github.com/stretchr/testify/assert"
    14  )
    15  
    16  func TestRepository_GetCodeActivityStats(t *testing.T) {
    17  	bareRepo1Path := filepath.Join(testReposDir, "repo1_bare")
    18  	bareRepo1, err := openRepositoryWithDefaultContext(bareRepo1Path)
    19  	assert.NoError(t, err)
    20  	defer bareRepo1.Close()
    21  
    22  	timeFrom, err := time.Parse(time.RFC3339, "2016-01-01T00:00:00+00:00")
    23  	assert.NoError(t, err)
    24  
    25  	code, err := bareRepo1.GetCodeActivityStats(timeFrom, "")
    26  	assert.NoError(t, err)
    27  	assert.NotNil(t, code)
    28  
    29  	assert.EqualValues(t, 9, code.CommitCount)
    30  	assert.EqualValues(t, 3, code.AuthorCount)
    31  	assert.EqualValues(t, 9, code.CommitCountInAllBranches)
    32  	assert.EqualValues(t, 10, code.Additions)
    33  	assert.EqualValues(t, 1, code.Deletions)
    34  	assert.Len(t, code.Authors, 3)
    35  	assert.EqualValues(t, "tris.git@shoddynet.org", code.Authors[1].Email)
    36  	assert.EqualValues(t, 3, code.Authors[1].Commits)
    37  	assert.EqualValues(t, 5, code.Authors[0].Commits)
    38  }