Skip to content

Commit

Permalink
cloudv2: Make sure to use the overwritten config
Browse files Browse the repository at this point in the history
  • Loading branch information
codebien committed Jul 13, 2023
1 parent ac448b0 commit 1278f6e
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 6 deletions.
20 changes: 14 additions & 6 deletions output/cloud/expv2/output.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"go.k6.io/k6/cloudapi/insights"
"go.k6.io/k6/errext"
"go.k6.io/k6/errext/exitcodes"
"go.k6.io/k6/lib/consts"
"go.k6.io/k6/lib/types"
"go.k6.io/k6/metrics"
"go.k6.io/k6/output"
Expand Down Expand Up @@ -63,13 +64,20 @@ type Output struct {
}

// New creates a new cloud output.
func New(logger logrus.FieldLogger, conf cloudapi.Config, cloudClient *cloudapi.Client) (*Output, error) {
func New(logger logrus.FieldLogger, conf cloudapi.Config, _ *cloudapi.Client) (*Output, error) {
return &Output{
config: conf,
logger: logger.WithField("output", "cloudv2"),
cloudClient: cloudClient,
abort: make(chan struct{}),
stop: make(chan struct{}),
config: conf,
logger: logger.WithField("output", "cloudv2"),
abort: make(chan struct{}),
stop: make(chan struct{}),

// TODO: move this creation operation to the centralized output. Reducing the probability to
// break the logic for the config overwriting.
//
// It creates a new client because in the case the backend has overwritten
// the config we need to use the new set.
cloudClient: cloudapi.NewClient(
logger, conf.Token.String, conf.Host.String, consts.Version, conf.Timeout.TimeDuration()),
}, nil
}

Expand Down
12 changes: 12 additions & 0 deletions output/cloud/expv2/output_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,18 @@ func TestNew(t *testing.T) {
assert.Equal(t, int64(99), o.config.APIVersion.Int64)
}

func TestNewWithConfigOverwritten(t *testing.T) {
t.Parallel()

logger := testutils.NewLogger(t)
c := cloudapi.NewClient(logger, "my-token", "the-host", "v/foo", 1*time.Second)
conf := cloudapi.Config{Host: null.StringFrom("the-new-host")}
o, err := New(logger, conf, c)
require.NoError(t, err)
require.NotNil(t, o)
assert.Equal(t, "the-new-host/v1", o.cloudClient.BaseURL())
}

func TestOutputSetTestRunID(t *testing.T) {
t.Parallel()
o := Output{}
Expand Down
8 changes: 8 additions & 0 deletions output/cloud/output.go
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,14 @@ func (out *Output) startVersionedOutput() error {
return errors.New("TestRunID is required")
}
var err error

// TODO: move here the creation of a new cloudapi.Client
// so in the case the config has been overwritten the client uses the correct
// value.
//
// This logic is handled individually by each single output, it has the downside
// that we could break the logic and not catch easly it.

switch out.config.APIVersion.Int64 {
case int64(apiVersion1):
out.versionedOutput, err = cloudv1.New(out.logger, out.config, out.client)
Expand Down

0 comments on commit 1278f6e

Please sign in to comment.