Skip to content

Commit

Permalink
Fix
Browse files Browse the repository at this point in the history
  • Loading branch information
k1LoW committed Sep 1, 2023
1 parent bbc3bee commit 0f28b46
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions report/custom.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ type CustomMetric struct {
type DiffCustomMetricSet struct {
Key string `json:"key"`
Name string `json:"name,omitempty"`
A *CustomMetricSet `json:"a"`
B *CustomMetricSet `json:"b"`
Metrics []*DiffCustomMetric `json:"metrics"`
reportA *Report
reportB *Report
Expand Down Expand Up @@ -88,19 +90,20 @@ func (s *CustomMetricSet) Out(w io.Writer) error {
}

func (s *CustomMetricSet) Compare(s2 *CustomMetricSet) *DiffCustomMetricSet {
if s2 == nil {
s2 = &CustomMetricSet{}
}
d := &DiffCustomMetricSet{
Key: s.Key,
Name: s.Name,
A: s,
B: s2,
Metrics: []*DiffCustomMetric{},
reportA: s.report,
reportB: s2.report,
}
for _, metric := range s.Metrics {
metric2 := s2.findMetricByKey(metric.Key)
d.Metrics = append(d.Metrics, metric.Compare(metric2))
if s2 != nil {
d.reportB = s2.report
for _, metric := range s.Metrics {
metric2 := s2.findMetricByKey(metric.Key)
d.Metrics = append(d.Metrics, metric.Compare(metric2))
}
}

return d
Expand Down Expand Up @@ -138,6 +141,9 @@ func (d *DiffCustomMetricSet) Table() string {
if len(d.Metrics) == 0 {
return ""
}
if d.B == nil {
return d.A.Table()
}
buf := new(bytes.Buffer)
_, _ = buf.WriteString(fmt.Sprintf("## %s\n\n", d.Name))
table := tablewriter.NewWriter(buf)
Expand Down

0 comments on commit 0f28b46

Please sign in to comment.