Skip to content

Commit

Permalink
cloud/output: Renamed field referenceID to testRunID
Browse files Browse the repository at this point in the history
  • Loading branch information
codebien committed Jun 26, 2023
1 parent d884925 commit 6eb8324
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 23 deletions.
32 changes: 16 additions & 16 deletions output/cloud/output.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ const (
type Output struct {
versionedOutput

logger logrus.FieldLogger
config cloudapi.Config
referenceID string
logger logrus.FieldLogger
config cloudapi.Config
testRunID string

executionPlan []lib.ExecutionStep
duration int64 // in seconds
Expand Down Expand Up @@ -157,8 +157,8 @@ func validateRequiredSystemTags(scriptTags *metrics.SystemTagSet) error {
// goroutine that would listen for metric samples and send them to the cloud.
func (out *Output) Start() error {
if out.config.PushRefID.Valid {
out.referenceID = out.config.PushRefID.String
out.logger.WithField("referenceId", out.referenceID).Debug("directly pushing metrics without init")
out.testRunID = out.config.PushRefID.String
out.logger.WithField("testRunID", out.testRunID).Debug("directly pushing metrics without init")
return out.startVersionedOutput()
}

Expand All @@ -181,7 +181,7 @@ func (out *Output) Start() error {
if err != nil {
return err
}
out.referenceID = response.ReferenceID
out.testRunID = response.ReferenceID

if response.ConfigOverride != nil {
out.logger.WithFields(logrus.Fields{
Expand All @@ -196,17 +196,17 @@ func (out *Output) Start() error {
}

out.logger.WithFields(logrus.Fields{
"name": out.config.Name,
"projectId": out.config.ProjectID,
"duration": out.duration,
"referenceId": out.referenceID,
"name": out.config.Name,
"projectId": out.config.ProjectID,
"duration": out.duration,
"testRunId": out.testRunID,
}).Debug("Started!")
return nil
}

// Description returns the URL with the test run results.
func (out *Output) Description() string {
return fmt.Sprintf("cloud (%s)", cloudapi.URLForResults(out.referenceID, out.config))
return fmt.Sprintf("cloud (%s)", cloudapi.URLForResults(out.testRunID, out.config))
}

// SetThresholds receives the thresholds before the output is Start()-ed.
Expand Down Expand Up @@ -252,7 +252,7 @@ func (out *Output) StopWithTestError(testErr error) error {
}

func (out *Output) testFinished(testErr error) error {
if out.referenceID == "" || out.config.PushRefID.Valid {
if out.testRunID == "" || out.config.PushRefID.Valid {
return nil
}

Expand All @@ -270,12 +270,12 @@ func (out *Output) testFinished(testErr error) error {

runStatus := out.getRunStatus(testErr)
out.logger.WithFields(logrus.Fields{
"ref": out.referenceID,
"ref": out.testRunID,
"tainted": testTainted,
"run_status": runStatus,
}).Debug("Sending test finished")

return out.client.TestFinished(out.referenceID, thresholdResults, testTainted, runStatus)
return out.client.TestFinished(out.testRunID, thresholdResults, testTainted, runStatus)
}

// getRunStatus determines the run status of the test based on the error.
Expand Down Expand Up @@ -328,7 +328,7 @@ func (out *Output) getRunStatus(testErr error) cloudapi.RunStatus {
}

func (out *Output) startVersionedOutput() error {
if out.referenceID == "" {
if out.testRunID == "" {
return errors.New("ReferenceID is required")
}
var err error
Expand All @@ -345,7 +345,7 @@ func (out *Output) startVersionedOutput() error {
return err
}

out.versionedOutput.SetTestRunID(out.referenceID)
out.versionedOutput.SetTestRunID(out.testRunID)
out.versionedOutput.SetTestRunStopCallback(out.testStopFunc)
return out.versionedOutput.Start()
}
14 changes: 7 additions & 7 deletions output/cloud/output_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ func TestOutputStartVersionError(t *testing.T) {
})
require.NoError(t, err)

o.referenceID = "123"
o.testRunID = "123"
err = o.startVersionedOutput()
require.ErrorContains(t, err, "v99 is an unexpected version")
}
Expand All @@ -159,8 +159,8 @@ func TestOutputStartVersionedOutputV2(t *testing.T) {
t.Parallel()

o := Output{
logger: testutils.NewLogger(t),
referenceID: "123",
logger: testutils.NewLogger(t),
testRunID: "123",
config: cloudapi.Config{
APIVersion: null.IntFrom(2),
Host: null.StringFrom("fake-cloud-url"),
Expand All @@ -186,7 +186,7 @@ func TestOutputStartVersionedOutputV1(t *testing.T) {
t.Parallel()

o := Output{
referenceID: "123",
testRunID: "123",
config: cloudapi.Config{
APIVersion: null.IntFrom(1),
// Here, we are enabling but silencing the related async op
Expand Down Expand Up @@ -233,13 +233,13 @@ func TestCloudOutputDescription(t *testing.T) {

t.Run("WithTestRunDetails", func(t *testing.T) {
t.Parallel()
o := Output{referenceID: "74"}
o := Output{testRunID: "74"}
o.config.TestRunDetails = null.StringFrom("my-custom-string")
assert.Equal(t, "cloud (my-custom-string)", o.Description())
})
t.Run("WithWebAppURL", func(t *testing.T) {
t.Parallel()
o := Output{referenceID: "74"}
o := Output{testRunID: "74"}
o.config.WebAppURL = null.StringFrom("mywebappurl.com")
assert.Equal(t, "cloud (mywebappurl.com/runs/74)", o.Description())
})
Expand Down Expand Up @@ -282,7 +282,7 @@ func TestOutputStopWithTestError(t *testing.T) {
require.NoError(t, err)

calledStopFn := false
out.referenceID = "test-ref-id-1234"
out.testRunID = "test-ref-id-1234"
out.versionedOutput = versionedOutputMock{
callback: func(fn string) {
if fn == "StopWithTestError" {
Expand Down

0 comments on commit 6eb8324

Please sign in to comment.