Skip to content

Commit 9e3a392

Browse files
committed
the last fix
1 parent 3c8f373 commit 9e3a392

File tree

1 file changed

+21
-10
lines changed

1 file changed

+21
-10
lines changed

internal/manager/telemetry/telemetry_test.go

+21-10
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"crypto/tls"
1111
"crypto/x509"
1212
"crypto/x509/pkix"
13+
"errors"
1314
"fmt"
1415
"math/big"
1516
"os"
@@ -332,17 +333,13 @@ func verifyTelemetryReport(t *testing.T, c *assert.CollectT, k8sVersion *version
332333

333334
// Report contains stanza like:
334335
// id=57a7a76c-25d0-4394-ab9a-954f7190e39a;
336+
// uptime=9;
335337
// 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)
337342
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:]
346343

347344
assert.Equal(
348345
c,
@@ -361,7 +358,6 @@ func verifyTelemetryReport(t *testing.T, c *assert.CollectT, k8sVersion *version
361358
"feature-konnect-sync=false;"+
362359
"hn=%s;"+
363360
"kv=3.3.0;"+
364-
"uptime=0;"+
365361
"v=NOT_SET;"+
366362
"k8s_arch=%s;"+
367363
"k8s_provider=UNKNOWN;"+
@@ -388,6 +384,21 @@ func verifyTelemetryReport(t *testing.T, c *assert.CollectT, k8sVersion *version
388384
)
389385
}
390386

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+
391402
func generateSelfSignedCert() (tls.Certificate, error) {
392403
// Generate a new RSA private key.
393404
privateKey, err := rsa.GenerateKey(rand.Reader, 2048)

0 commit comments

Comments
 (0)