Skip to content

Commit

Permalink
Fix bugs with output configs (#1881)
Browse files Browse the repository at this point in the history
* Fix bugs with output configs
  • Loading branch information
na-- authored Mar 4, 2021
1 parent a5d8841 commit a44f5dc
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 5 deletions.
15 changes: 11 additions & 4 deletions cloudapi/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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
}
Expand Down
70 changes: 70 additions & 0 deletions cloudapi/config_test.go
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/>.
*
*/
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))
}
3 changes: 3 additions & 0 deletions cmd/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
2 changes: 1 addition & 1 deletion output/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit a44f5dc

Please sign in to comment.