mirror of
https://github.com/tendermint/tendermint.git
synced 2026-02-04 11:02:06 +00:00
change output and related tests
This commit is contained in:
@@ -168,14 +168,15 @@ func (m metricsList) Swap(i, j int) { m[i], m[j] = m[j], m[i] }
|
||||
|
||||
func (m Diff) String() string {
|
||||
var s strings.Builder
|
||||
if len(m.Adds) > 0 || len(m.Removes) > 0 {
|
||||
fmt.Fprintln(&s, "Metric changes:")
|
||||
}
|
||||
if len(m.Adds) > 0 {
|
||||
fmt.Fprintln(&s, "Adds:")
|
||||
for _, add := range m.Adds {
|
||||
fmt.Fprintf(&s, "+++ %s\n", add)
|
||||
}
|
||||
}
|
||||
if len(m.Removes) > 0 {
|
||||
fmt.Fprintln(&s, "Removes:")
|
||||
for _, rem := range m.Removes {
|
||||
fmt.Fprintf(&s, "--- %s\n", rem)
|
||||
}
|
||||
@@ -183,7 +184,7 @@ func (m Diff) String() string {
|
||||
if len(m.Changes) > 0 {
|
||||
fmt.Fprintln(&s, "Label changes:")
|
||||
for _, ld := range m.Changes {
|
||||
fmt.Fprintf(&s, "Label: %s\n", ld.Metric)
|
||||
fmt.Fprintf(&s, "Metric: %s\n", ld.Metric)
|
||||
for _, add := range ld.Adds {
|
||||
fmt.Fprintf(&s, "+++ %s\n", add)
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@ func TestDiff(t *testing.T) {
|
||||
aContents string
|
||||
bContents string
|
||||
|
||||
want metricsdiff.Diff
|
||||
want string
|
||||
}{
|
||||
{
|
||||
name: "labels",
|
||||
@@ -25,15 +25,13 @@ func TestDiff(t *testing.T) {
|
||||
bContents: `
|
||||
metric_one{label_three="content", label_four="content"} 0
|
||||
`,
|
||||
want: metricsdiff.Diff{
|
||||
Changes: []metricsdiff.LabelDiff{
|
||||
{
|
||||
Metric: "metric_one",
|
||||
Adds: []string{"label_three", "label_four"},
|
||||
Removes: []string{"label_one", "label_two"},
|
||||
},
|
||||
},
|
||||
},
|
||||
want: `Label changes:
|
||||
Metric: metric_one
|
||||
+++ label_three
|
||||
+++ label_four
|
||||
--- label_one
|
||||
--- label_two
|
||||
`,
|
||||
},
|
||||
{
|
||||
name: "metrics",
|
||||
@@ -43,10 +41,10 @@ func TestDiff(t *testing.T) {
|
||||
bContents: `
|
||||
metric_two{label_two="content"} 0
|
||||
`,
|
||||
want: metricsdiff.Diff{
|
||||
Adds: []string{"metric_two"},
|
||||
Removes: []string{"metric_one"},
|
||||
},
|
||||
want: `Metric changes:
|
||||
+++ metric_two
|
||||
--- metric_one
|
||||
`,
|
||||
},
|
||||
} {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
@@ -58,7 +56,7 @@ func TestDiff(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
md, err := metricsdiff.DiffFromReaders(bufA, bufB)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, tc.want, md)
|
||||
require.Equal(t, tc.want, md.String())
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user