@@ -10,6 +10,7 @@ import (
10
10
"crypto/tls"
11
11
"crypto/x509"
12
12
"crypto/x509/pkix"
13
+ "errors"
13
14
"fmt"
14
15
"math/big"
15
16
"os"
@@ -332,17 +333,13 @@ func verifyTelemetryReport(t *testing.T, c *assert.CollectT, k8sVersion *version
332
333
333
334
// Report contains stanza like:
334
335
// id=57a7a76c-25d0-4394-ab9a-954f7190e39a;
336
+ // uptime=9;
335
337
// that is not stable across runs, so we need to remove it.
336
- reportToAssert := string (report )
338
+ reportToAssert , err := rmStanzaFromReport (string (report ), "id" )
339
+ assert .NoError (c , err )
340
+ reportToAssert , err = rmStanzaFromReport (reportToAssert , "uptime" )
341
+ assert .NoError (c , err )
337
342
t .Log (">>>> Report to assert:" , reportToAssert )
338
- const idStanzaStart , idStanzaEnd = "id=" , ";"
339
- assert .Contains (c , reportToAssert , idStanzaStart )
340
- idStart := strings .Index (reportToAssert , idStanzaStart )
341
- assert .Greater (c , idStart , - 1 )
342
- idEnd := strings .Index (reportToAssert [idStart :], idStanzaEnd )
343
- assert .Greater (c , idEnd , - 1 )
344
- idEnd += idStart
345
- reportToAssert = reportToAssert [:idStart ] + reportToAssert [idEnd + 1 :]
346
343
347
344
assert .Equal (
348
345
c ,
@@ -361,7 +358,6 @@ func verifyTelemetryReport(t *testing.T, c *assert.CollectT, k8sVersion *version
361
358
"feature-konnect-sync=false;" +
362
359
"hn=%s;" +
363
360
"kv=3.3.0;" +
364
- "uptime=0;" +
365
361
"v=NOT_SET;" +
366
362
"k8s_arch=%s;" +
367
363
"k8s_provider=UNKNOWN;" +
@@ -388,6 +384,21 @@ func verifyTelemetryReport(t *testing.T, c *assert.CollectT, k8sVersion *version
388
384
)
389
385
}
390
386
387
+ func rmStanzaFromReport (report string , stanza string ) (string , error ) {
388
+ const idStanzaEnd = ";"
389
+ stanza = stanza + "="
390
+ idStart := strings .Index (report , stanza )
391
+ if idStart == - 1 {
392
+ return "" , errors .New ("stanza not found in report" )
393
+ }
394
+ idEnd := strings .Index (report [idStart :], idStanzaEnd )
395
+ if idStart == - 1 {
396
+ return "" , errors .New ("stanza end not found in report" )
397
+ }
398
+ idEnd += idStart
399
+ return report [:idStart ] + report [idEnd + 1 :], nil
400
+ }
401
+
391
402
func generateSelfSignedCert () (tls.Certificate , error ) {
392
403
// Generate a new RSA private key.
393
404
privateKey , err := rsa .GenerateKey (rand .Reader , 2048 )
0 commit comments