@@ -22,6 +22,7 @@ import (
2222 "strings"
2323 "testing"
2424 "text/tabwriter"
25+ "time"
2526
2627 "github.com/prometheus/tsdb"
2728 testutildb "github.com/prometheus/tsdb/testutil/db"
@@ -112,7 +113,7 @@ func TestPrintBlocks(t *testing.T) {
112113 expected = strings .Replace (expected , "\n " , "" , - 1 )
113114
114115 if expected != actual {
115- t .Errorf ("expected (%#v) != actual (%#v)" , expected , actual )
116+ t .Errorf ("expected (%#v) != actual (%#v)" , b . String (), actualStdout . String () )
116117 }
117118}
118119
@@ -150,7 +151,7 @@ func TestExtractBlock(t *testing.T) {
150151 analyzeBlockID = "foo"
151152 block , err = extractBlock (blocks , & analyzeBlockID )
152153 if err == nil {
153- t .Errorf ("Analyzing block %q should throw error" , analyzeBlockID )
154+ t .Errorf ("Analyzing block ID %q should throw error" , analyzeBlockID )
154155 }
155156 if block != nil {
156157 t .Error ("block should be nil" )
@@ -180,9 +181,48 @@ func TestAnalyzeBlocks(t *testing.T) {
180181 t .Error (err )
181182 }
182183
183- var actual bytes.Buffer
184+ var (
185+ expected bytes.Buffer
186+ actual bytes.Buffer
187+ )
188+
189+ // Actual output.
184190 err = analyzeBlock (& actual , block , dal )
185191 if err != nil {
186192 t .Error (err )
187193 }
194+
195+ act := actual .String ()
196+ act = strings .Replace (act , " " , "" , - 1 )
197+ act = strings .Replace (act , "\t " , "" , - 1 )
198+ act = strings .Replace (act , "\n " , "" , - 1 )
199+
200+ // Expected output.
201+ meta := block .Meta ()
202+ fmt .Fprintf (& expected , "Block ID: %s\n " , meta .ULID )
203+ fmt .Fprintf (& expected , "Duration: %s\n " , (time .Duration (meta .MaxTime - meta .MinTime ) * 1e6 ).String ())
204+ fmt .Fprintf (& expected , "Series: %d\n " , 1 )
205+ fmt .Fprintf (& expected , "Label names: %d\n " , 1 )
206+ fmt .Fprintf (& expected , "Postings (unique label pairs): %d\n " , 1 )
207+ fmt .Fprintf (& expected , "Postings entries (total label pairs): %d\n " , 1 )
208+ fmt .Fprintf (& expected , "\n Label pairs most involved in churning:\n " )
209+ fmt .Fprintf (& expected , "1 %s=0" , testutildb .DefaultLabelName )
210+ fmt .Fprintf (& expected , "\n Label names most involved in churning:\n " )
211+ fmt .Fprintf (& expected , "1 %s" , testutildb .DefaultLabelName )
212+ fmt .Fprintf (& expected , "\n Most common label pairs:\n " )
213+ fmt .Fprintf (& expected , "1 %s=0" , testutildb .DefaultLabelName )
214+ fmt .Fprintf (& expected , "\n Label names with highest cumulative label value length:\n " )
215+ fmt .Fprintf (& expected , "1 %s" , testutildb .DefaultLabelName )
216+ fmt .Fprintf (& expected , "\n Highest cardinality labels:\n " )
217+ fmt .Fprintf (& expected , "1 %s" , testutildb .DefaultLabelName )
218+ fmt .Fprintf (& expected , "\n Highest cardinality metric names:\n " )
219+
220+ exp := expected .String ()
221+ exp = strings .Replace (exp , " " , "" , - 1 )
222+ exp = strings .Replace (exp , "\t " , "" , - 1 )
223+ exp = strings .Replace (exp , "\n " , "" , - 1 )
224+
225+ if exp != act {
226+ t .Errorf ("expected (%#v) != actual (%#v)" , expected .String (), actual .String ())
227+ }
188228}
0 commit comments