github.com/covergates/covergates@v0.2.2-0.20201009050117-42ef8a19fb95/modules/charts/treemap_test.go (about)

     1  package charts
     2  
     3  import (
     4  	"os"
     5  	"testing"
     6  
     7  	"github.com/covergates/covergates/core"
     8  )
     9  
    10  func TestCoverDiffTreeMap(t *testing.T) {
    11  	o := &core.Report{
    12  		Coverages: []*core.CoverageReport{
    13  			{
    14  				Files: []*core.File{
    15  					{
    16  						Name:              "A",
    17  						StatementCoverage: 0.5,
    18  						StatementHits:     make([]*core.StatementHit, 20),
    19  					},
    20  					{
    21  						Name:              "B",
    22  						StatementCoverage: 0.8,
    23  						StatementHits:     make([]*core.StatementHit, 10),
    24  					},
    25  					{
    26  						Name:              "C",
    27  						StatementCoverage: 1.0,
    28  						StatementHits:     make([]*core.StatementHit, 50),
    29  					},
    30  				},
    31  			},
    32  		},
    33  	}
    34  
    35  	n := &core.Report{
    36  		Coverages: []*core.CoverageReport{
    37  			{
    38  				Files: []*core.File{
    39  					{
    40  						Name:              "A",
    41  						StatementCoverage: 0.6,
    42  						StatementHits:     make([]*core.StatementHit, 20),
    43  					},
    44  					{
    45  						Name:              "B",
    46  						StatementCoverage: 0.4,
    47  						StatementHits:     make([]*core.StatementHit, 10),
    48  					},
    49  					{
    50  						Name:              "C",
    51  						StatementCoverage: 1.0,
    52  						StatementHits:     make([]*core.StatementHit, 50),
    53  					},
    54  				},
    55  			},
    56  		},
    57  	}
    58  	m := NewCoverageDiffTreeMap(o, n)
    59  	file, err := os.Create("treemap.svg")
    60  	if err != nil {
    61  		t.Error(err)
    62  		return
    63  	}
    64  	defer func() {
    65  		file.Close()
    66  		os.Remove(file.Name())
    67  	}()
    68  	if err := m.Render(file); err != nil {
    69  		t.Error(err)
    70  		return
    71  	}
    72  }