diff --git a/cloudapi/config.go b/cloudapi/config.go index e113ff59645..e5590babb39 100644 --- a/cloudapi/config.go +++ b/cloudapi/config.go @@ -188,6 +188,9 @@ func (c Config) Apply(cfg Config) Config { if cfg.DeprecatedToken.Valid { c.DeprecatedToken = cfg.DeprecatedToken } + if cfg.ProjectID.Valid && cfg.ProjectID.Int64 > 0 { + c.ProjectID = cfg.ProjectID + } if cfg.Name.Valid && cfg.Name.String != "" { c.Name = cfg.Name } @@ -197,21 +200,25 @@ func (c Config) Apply(cfg Config) Config { if cfg.LogsTailURL.Valid && cfg.LogsTailURL.String != "" { c.LogsTailURL = cfg.LogsTailURL } + if cfg.PushRefID.Valid { + c.PushRefID = cfg.PushRefID + } if cfg.WebAppURL.Valid { c.WebAppURL = cfg.WebAppURL } if cfg.NoCompress.Valid { c.NoCompress = cfg.NoCompress } - if cfg.ProjectID.Valid && cfg.ProjectID.Int64 > 0 { - c.ProjectID = cfg.ProjectID + if cfg.MaxMetricSamplesPerPackage.Valid { + c.MaxMetricSamplesPerPackage = cfg.MaxMetricSamplesPerPackage } if cfg.MetricPushInterval.Valid { c.MetricPushInterval = cfg.MetricPushInterval } - if cfg.MaxMetricSamplesPerPackage.Valid { - c.MaxMetricSamplesPerPackage = cfg.MaxMetricSamplesPerPackage + if cfg.MetricPushConcurrency.Valid { + c.MetricPushConcurrency = cfg.MetricPushConcurrency } + if cfg.AggregationPeriod.Valid { c.AggregationPeriod = cfg.AggregationPeriod } diff --git a/cloudapi/config_test.go b/cloudapi/config_test.go new file mode 100644 index 00000000000..577d27ac992 --- /dev/null +++ b/cloudapi/config_test.go @@ -0,0 +1,70 @@ +/* + * + * k6 - a next-generation load testing tool + * Copyright (C) 2021 Load Impact + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * + */ +package cloudapi + +import ( + "testing" + "time" + + "github.com/loadimpact/k6/lib/types" + "github.com/stretchr/testify/assert" + "gopkg.in/guregu/null.v3" +) + +func TestConfigApply(t *testing.T) { + empty := Config{} + defaults := NewConfig() + + assert.Equal(t, empty, empty.Apply(empty)) + assert.Equal(t, empty, empty.Apply(defaults)) + assert.Equal(t, defaults, defaults.Apply(defaults)) + assert.Equal(t, defaults, defaults.Apply(empty)) + assert.Equal(t, defaults, defaults.Apply(empty).Apply(empty)) + + full := Config{ + Token: null.NewString("Token", true), + DeprecatedToken: null.NewString("DeprecatedToken", true), + ProjectID: null.NewInt(1, true), + Name: null.NewString("Name", true), + Host: null.NewString("Host", true), + LogsTailURL: null.NewString("LogsTailURL", true), + PushRefID: null.NewString("PushRefID", true), + WebAppURL: null.NewString("foo", true), + NoCompress: null.NewBool(true, true), + MaxMetricSamplesPerPackage: null.NewInt(2, true), + MetricPushInterval: types.NewNullDuration(1*time.Second, true), + MetricPushConcurrency: null.NewInt(3, true), + AggregationPeriod: types.NewNullDuration(2*time.Second, true), + AggregationCalcInterval: types.NewNullDuration(3*time.Second, true), + AggregationWaitPeriod: types.NewNullDuration(4*time.Second, true), + AggregationMinSamples: null.NewInt(4, true), + AggregationSkipOutlierDetection: null.NewBool(true, true), + AggregationOutlierAlgoThreshold: null.NewInt(5, true), + AggregationOutlierIqrRadius: null.NewFloat(6, true), + AggregationOutlierIqrCoefLower: null.NewFloat(7, true), + AggregationOutlierIqrCoefUpper: null.NewFloat(8, true), + } + + assert.Equal(t, full, full.Apply(empty)) + assert.Equal(t, full, full.Apply(defaults)) + assert.Equal(t, full, full.Apply(full)) + assert.Equal(t, full, empty.Apply(full)) + assert.Equal(t, full, defaults.Apply(full)) +} diff --git a/cmd/config.go b/cmd/config.go index 8ad10b75faf..a0b3e80bd58 100644 --- a/cmd/config.go +++ b/cmd/config.go @@ -80,6 +80,9 @@ func (c Config) Apply(cfg Config) Config { if cfg.NoUsageReport.Valid { c.NoUsageReport = cfg.NoUsageReport } + if len(cfg.Collectors) > 0 { + c.Collectors = cfg.Collectors + } return c } diff --git a/output/types.go b/output/types.go index efac5014aeb..dfe074c4f50 100644 --- a/output/types.go +++ b/output/types.go @@ -83,7 +83,7 @@ type WithThresholds interface { // TODO: add some way for outputs to report mid-test errors and potentially // abort the whole test run -// WithRunStatusUpdates means the output can receivetest run status updates. +// WithRunStatusUpdates means the output can receive test run status updates. type WithRunStatusUpdates interface { Output SetRunStatus(latestStatus lib.RunStatus)