aboutsummaryrefslogtreecommitdiffstats
path: root/pkg
diff options
context:
space:
mode:
authorTaras Madan <tarasmadan@google.com>2024-07-12 10:58:12 +0200
committerTaras Madan <tarasmadan@google.com>2024-07-15 20:31:23 +0000
commit31605b3e1a107ab83d814ec4183cec07bb670655 (patch)
tree73e2c7320938fd91d4c02e57ffca208282d35a1c /pkg
parent626375c87b8c76fa305742f4dceefccde55245b2 (diff)
pkg/cover: add heatmap_test.go
Diffstat (limited to 'pkg')
-rw-r--r--pkg/cover/heatmap_test.go113
1 files changed, 113 insertions, 0 deletions
diff --git a/pkg/cover/heatmap_test.go b/pkg/cover/heatmap_test.go
new file mode 100644
index 000000000..c40d14ccc
--- /dev/null
+++ b/pkg/cover/heatmap_test.go
@@ -0,0 +1,113 @@
+// Copyright 2024 syzkaller project authors. All rights reserved.
+// Use of this source code is governed by Apache 2 LICENSE that can be found in the LICENSE file.
+
+package cover
+
+import (
+ "testing"
+ "time"
+
+ "cloud.google.com/go/civil"
+ "github.com/stretchr/testify/assert"
+)
+
+func TestFilesCoverageToTemplateData(t *testing.T) {
+ tests := []struct {
+ name string
+ input []*fileCoverageAndDate
+ want *templateHeatmap
+ }{
+ {
+ name: "empty input",
+ input: []*fileCoverageAndDate{},
+ want: &templateHeatmap{
+ Root: &templateHeatmapRow{
+ Items: []*templateHeatmapRow{},
+ },
+ },
+ },
+ {
+ name: "single file",
+ input: []*fileCoverageAndDate{
+ {
+ Filepath: "file1",
+ Instrumented: 1,
+ Covered: 1,
+ Dateto: civil.Date{Year: 2024, Month: time.July, Day: 1},
+ },
+ },
+ want: &templateHeatmap{
+ Root: &templateHeatmapRow{
+ Items: []*templateHeatmapRow{
+ {
+ Items: []*templateHeatmapRow{},
+ Name: "file1",
+ Coverage: []int64{100},
+ IsDir: false,
+ Depth: 0,
+ },
+ },
+ Name: "",
+ Coverage: []int64{100},
+ IsDir: false,
+ Depth: 0,
+ },
+ Dates: []string{"2024-07-01"},
+ },
+ },
+ {
+ name: "tree data",
+ input: []*fileCoverageAndDate{
+ {
+ Filepath: "dir/file2",
+ Instrumented: 1,
+ Covered: 0,
+ Dateto: civil.Date{Year: 2024, Month: time.July, Day: 2},
+ },
+ {
+ Filepath: "dir/file1",
+ Instrumented: 1,
+ Covered: 1,
+ Dateto: civil.Date{Year: 2024, Month: time.July, Day: 1},
+ },
+ },
+ want: &templateHeatmap{
+ Root: &templateHeatmapRow{
+ Items: []*templateHeatmapRow{
+ {
+ Items: []*templateHeatmapRow{
+ {
+ Items: []*templateHeatmapRow{},
+ Name: "file1",
+ Coverage: []int64{100, 0},
+ IsDir: false,
+ Depth: 1,
+ },
+ {
+ Items: []*templateHeatmapRow{},
+ Name: "file2",
+ Coverage: []int64{0, 0},
+ IsDir: false,
+ Depth: 1,
+ },
+ },
+ Name: "dir",
+ Coverage: []int64{100, 0},
+ IsDir: true,
+ Depth: 0,
+ },
+ },
+ Name: "",
+ Coverage: []int64{100, 0},
+ },
+ Dates: []string{"2024-07-01", "2024-07-02"},
+ },
+ },
+ }
+ for _, test := range tests {
+ t.Run(test.name, func(t *testing.T) {
+ got := filesCoverageToTemplateData(test.input)
+ assert.EqualExportedValues(t, test.want, got)
+ })
+ }
+}