@@ -61,29 +61,43 @@ func Test_RepairGoTruncatedStacktraces(t *testing.T) {
6161 }
6262}
6363
64+ var goTruncatedStacktracesFixtures = []string {
65+ "testdata/gotruncatefix/heap_go_truncated_1.pb.gz" , // Cortex.
66+ "testdata/gotruncatefix/heap_go_truncated_2.pb.gz" , // Cortex.
67+ "testdata/gotruncatefix/heap_go_truncated_3.pb.gz" , // Loki. Pathological.
68+ "testdata/gotruncatefix/heap_go_truncated_4.pb.gz" , // Pyroscope.
69+ "testdata/gotruncatefix/cpu_go_truncated_1.pb.gz" , // Cloudwatch Exporter
70+ }
71+
6472func Test_UpdateFixtures_RepairGoTruncatedStacktraces (t * testing.T ) {
6573 if os .Getenv ("UPDATE_FIXTURES" ) != "true" {
6674 t .Skip ()
6775 }
68- t .Helper ()
69- paths := []string {
70- "testdata/gotruncatefix/heap_go_truncated_1.pb.gz" , // Cortex.
71- "testdata/gotruncatefix/heap_go_truncated_2.pb.gz" , // Cortex.
72- "testdata/gotruncatefix/heap_go_truncated_3.pb.gz" , // Loki. Pathological.
73- "testdata/gotruncatefix/heap_go_truncated_4.pb.gz" , // Pyroscope.
74- "testdata/gotruncatefix/cpu_go_truncated_1.pb.gz" , // Cloudwatch Exporter
76+ for _ , path := range goTruncatedStacktracesFixtures {
77+ p , err := OpenFile (path )
78+ require .NoError (t , err , path )
79+ total := samplesTotal (p .Profile )
80+
81+ p .Profile = FixGoProfile (p .Profile )
82+ RepairGoTruncatedStacktraces (p .Profile )
83+ assert .Equal (t , total , samplesTotal (p .Profile ))
84+
85+ fixed , err := os .Create (path + ".fixed" )
86+ require .NoError (t , err , path )
87+ _ , err = p .WriteTo (fixed )
88+ require .NoError (t , fixed .Close (), path )
89+ require .NoError (t , err , path )
7590 }
76- for _ , path := range paths {
77- func () {
78- p , err := OpenFile (path )
79- require .NoError (t , err , path )
80- f , err := os .Create (path + ".fixed" )
81- require .NoError (t , err , path )
82- defer f .Close ()
83- p .Profile = FixGoProfile (p .Profile )
84- RepairGoTruncatedStacktraces (p .Profile )
85- _ , err = p .WriteTo (f )
86- require .NoError (t , err , path )
87- }()
91+ }
92+
93+ func Test_RepairGoTruncatedStacktraces_Fixtures (t * testing.T ) {
94+ for _ , path := range goTruncatedStacktracesFixtures {
95+ p , err := OpenFile (path )
96+ require .NoError (t , err , path )
97+ total := samplesTotal (p .Profile )
98+
99+ fixed , err := OpenFile (path + ".fixed" )
100+ require .NoError (t , err )
101+ assert .Equal (t , total , samplesTotal (fixed .Profile ))
88102 }
89103}
0 commit comments