Skip to content

Commit

Permalink
Merge pull request #64 from k1LoW/trim-file-coverages
Browse files Browse the repository at this point in the history
Flush the block coverages from the report to handle `Error 413 (Request Entity Too Large)!!1` error.
  • Loading branch information
k1LoW authored Sep 15, 2021
2 parents 3f839f0 + b91522f commit 5c98c02
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
1 change: 1 addition & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,7 @@ var rootCmd = &cobra.Command{
if err := c.BuildReportConfig(); err != nil {
return err
}
r.Coverage.FlushBlockCoverages()
datastores := []datastore.Datastore{}
for _, s := range c.Report.Datastores {
d, err := datastore.New(ctx, s, c.Root())
Expand Down
8 changes: 7 additions & 1 deletion pkg/coverage/coverage.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ type FileCoverage struct {
File string `json:"file"`
Total int `json:"total"`
Covered int `json:"covered"`
Blocks BlockCoverages `json:"blocks"`
Blocks BlockCoverages `json:"blocks,omitempty"`
cache map[int]BlockCoverages
}

Expand Down Expand Up @@ -63,6 +63,12 @@ func NewFileCoverage(file string) *FileCoverage {
}
}

func (c *Coverage) FlushBlockCoverages() {
for _, f := range c.Files {
f.Blocks = BlockCoverages{}
}
}

func (coverages FileCoverages) FindByFile(file string) (*FileCoverage, error) {
for _, c := range coverages {
if c.File == file {
Expand Down
6 changes: 6 additions & 0 deletions report/report_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ func TestTable(t *testing.T) {
if got := r.Table(); got != tt.want {
t.Errorf("got\n%v\nwant\n%v", got, tt.want)
}
orig := r.String()
r.Coverage.FlushBlockCoverages()
flushed := r.String()
if len(orig) <= len(flushed) {
t.Error("FlushBlockCoverages error")
}
}
}

Expand Down

0 comments on commit 5c98c02

Please sign in to comment.