From 2bf68614de1620ef12f086d9e86d5c8b334bf32d Mon Sep 17 00:00:00 2001 From: Taras Madan Date: Thu, 23 Jan 2025 21:54:41 +0100 Subject: dashboard/app: test coverage /file link 1. Init coveragedb client once and propagate it through context to enable mocking. 2. Always init coverage handlers. It simplifies testing. 3. Read webGit and coveragedb client from ctx to make it mockable. 4. Use int for file line number and int64 for merged coverage. 5. Add tests. --- pkg/cover/heatmap_test.go | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'pkg/cover/heatmap_test.go') diff --git a/pkg/cover/heatmap_test.go b/pkg/cover/heatmap_test.go index ad1f9bf64..0f66256e4 100644 --- a/pkg/cover/heatmap_test.go +++ b/pkg/cover/heatmap_test.go @@ -65,7 +65,7 @@ func TestFilesCoverageWithDetails(t *testing.T) { client: func() spannerclient.SpannerClient { return fullCoverageDBFixture( t, - []*fileCoverageWithLineInfo{ + []*FileCoverageWithLineInfo{ { fileCoverageWithDetails: fileCoverageWithDetails{ Filepath: "file1", @@ -98,7 +98,7 @@ func TestFilesCoverageWithDetails(t *testing.T) { client: func() spannerclient.SpannerClient { return fullCoverageDBFixture( t, - []*fileCoverageWithLineInfo{ + []*FileCoverageWithLineInfo{ { fileCoverageWithDetails: fileCoverageWithDetails{ Filepath: "file1", @@ -109,7 +109,7 @@ func TestFilesCoverageWithDetails(t *testing.T) { HitCounts: []int64{1, 1, 1}, }, }, - []*fileCoverageWithLineInfo{ + []*FileCoverageWithLineInfo{ { fileCoverageWithDetails: fileCoverageWithDetails{ Filepath: "file1", @@ -141,7 +141,7 @@ func TestFilesCoverageWithDetails(t *testing.T) { client: func() spannerclient.SpannerClient { return fullCoverageDBFixture( t, - []*fileCoverageWithLineInfo{ + []*FileCoverageWithLineInfo{ { fileCoverageWithDetails: fileCoverageWithDetails{ Filepath: "file1", @@ -152,7 +152,7 @@ func TestFilesCoverageWithDetails(t *testing.T) { HitCounts: []int64{3, 4, 5, 6, 7}, }, }, - []*fileCoverageWithLineInfo{ + []*FileCoverageWithLineInfo{ { fileCoverageWithDetails: fileCoverageWithDetails{ Filepath: "file1", @@ -212,7 +212,7 @@ func emptyCoverageDBFixture(t *testing.T, times int) spannerclient.SpannerClient } func fullCoverageDBFixture( - t *testing.T, full, partial []*fileCoverageWithLineInfo, + t *testing.T, full, partial []*FileCoverageWithLineInfo, ) spannerclient.SpannerClient { mPartialTran := mocks.NewReadOnlyTransaction(t) mPartialTran.On("Query", mock.Anything, mock.Anything). @@ -230,7 +230,7 @@ func fullCoverageDBFixture( return m } -func newRowIteratorMock(t *testing.T, events []*fileCoverageWithLineInfo, +func newRowIteratorMock(t *testing.T, events []*FileCoverageWithLineInfo, ) *mocks.RowIterator { m := mocks.NewRowIterator(t) m.On("Stop").Once().Return() @@ -238,7 +238,7 @@ func newRowIteratorMock(t *testing.T, events []*fileCoverageWithLineInfo, mRow := mocks.NewRow(t) mRow.On("ToStruct", mock.Anything). Run(func(args mock.Arguments) { - arg := args.Get(0).(*fileCoverageWithLineInfo) + arg := args.Get(0).(*FileCoverageWithLineInfo) *arg = *item }). Return(nil).Once() -- cgit mrf-deployment