Skip to content

Commit

Permalink
the last fix
Browse files Browse the repository at this point in the history
  • Loading branch information
programmer04 committed May 31, 2023
1 parent 3c8f373 commit 9e3a392
Showing 1 changed file with 21 additions and 10 deletions.
31 changes: 21 additions & 10 deletions internal/manager/telemetry/telemetry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"crypto/tls"
"crypto/x509"
"crypto/x509/pkix"
"errors"
"fmt"
"math/big"
"os"
Expand Down Expand Up @@ -332,17 +333,13 @@ func verifyTelemetryReport(t *testing.T, c *assert.CollectT, k8sVersion *version

// Report contains stanza like:
// id=57a7a76c-25d0-4394-ab9a-954f7190e39a;
// uptime=9;
// that is not stable across runs, so we need to remove it.
reportToAssert := string(report)
reportToAssert, err := rmStanzaFromReport(string(report), "id")
assert.NoError(c, err)
reportToAssert, err = rmStanzaFromReport(reportToAssert, "uptime")
assert.NoError(c, err)
t.Log(">>>> Report to assert:", reportToAssert)
const idStanzaStart, idStanzaEnd = "id=", ";"
assert.Contains(c, reportToAssert, idStanzaStart)
idStart := strings.Index(reportToAssert, idStanzaStart)
assert.Greater(c, idStart, -1)
idEnd := strings.Index(reportToAssert[idStart:], idStanzaEnd)
assert.Greater(c, idEnd, -1)
idEnd += idStart
reportToAssert = reportToAssert[:idStart] + reportToAssert[idEnd+1:]

assert.Equal(
c,
Expand All @@ -361,7 +358,6 @@ func verifyTelemetryReport(t *testing.T, c *assert.CollectT, k8sVersion *version
"feature-konnect-sync=false;"+
"hn=%s;"+
"kv=3.3.0;"+
"uptime=0;"+
"v=NOT_SET;"+
"k8s_arch=%s;"+
"k8s_provider=UNKNOWN;"+
Expand All @@ -388,6 +384,21 @@ func verifyTelemetryReport(t *testing.T, c *assert.CollectT, k8sVersion *version
)
}

func rmStanzaFromReport(report string, stanza string) (string, error) {
const idStanzaEnd = ";"
stanza = stanza + "="
idStart := strings.Index(report, stanza)
if idStart == -1 {
return "", errors.New("stanza not found in report")
}
idEnd := strings.Index(report[idStart:], idStanzaEnd)
if idStart == -1 {
return "", errors.New("stanza end not found in report")
}
idEnd += idStart
return report[:idStart] + report[idEnd+1:], nil
}

func generateSelfSignedCert() (tls.Certificate, error) {
// Generate a new RSA private key.
privateKey, err := rsa.GenerateKey(rand.Reader, 2048)
Expand Down

0 comments on commit 9e3a392

Please sign in to comment.