Skip to content

Commit

Permalink
get rid of report.Topologies()
Browse files Browse the repository at this point in the history
The three report.Walk* functions are quite enough.
  • Loading branch information
rade committed Dec 24, 2017
1 parent fcc26d0 commit 760862c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 14 deletions.
14 changes: 2 additions & 12 deletions report/report.go
Original file line number Diff line number Diff line change
Expand Up @@ -273,16 +273,6 @@ func (r Report) Merge(other Report) Report {
return newReport
}

// Topologies returns a slice of Topologies in this report
func (r Report) Topologies() []Topology {
result := make([]Topology, len(topologyNames))
for i, name := range topologyNames {
t, _ := r.Topology(name)
result[i] = t
}
return result
}

// WalkTopologies iterates through the Topologies of the report,
// potentially modifying them
func (r *Report) WalkTopologies(f func(*Topology)) {
Expand Down Expand Up @@ -362,11 +352,11 @@ func (r Report) Topology(name string) (Topology, bool) {
// Validate checks the report for various inconsistencies.
func (r Report) Validate() error {
var errs []string
for _, topology := range r.Topologies() {
r.WalkTopologies(func(topology *Topology) {
if err := topology.Validate(); err != nil {
errs = append(errs, err.Error())
}
}
})
if r.Sampling.Count > r.Sampling.Total {
errs = append(errs, fmt.Sprintf("sampling count (%d) bigger than total (%d)", r.Sampling.Count, r.Sampling.Total))
}
Expand Down
8 changes: 6 additions & 2 deletions report/report_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,18 @@ func TestReportTopologies(t *testing.T) {
topologyType = reflect.TypeOf(report.MakeTopology())
)

var want int
var want, have int
for i := 0; i < reportType.NumField(); i++ {
if reportType.Field(i).Type == topologyType {
want++
}
}

if have := len(report.MakeReport().Topologies()); want != have {
r := report.MakeReport()
r.WalkTopologies(func(_ *report.Topology) {
have++
})
if want != have {
t.Errorf("want %d, have %d", want, have)
}
}
Expand Down

0 comments on commit 760862c

Please sign in to comment.