fix(k6): config reading

This commit is contained in:
Tine 2024-02-21 14:16:22 +01:00
parent 4a36c60d9e
commit 33e8d2091d
Signed by: mentos1386
SSH key fingerprint: SHA256:MNtTsLbihYaWF8j1fkOHfkKNlnN1JQfxEU/rBU8nCGw
4 changed files with 34 additions and 6 deletions

View file

@ -22,7 +22,7 @@ func Healthcheck(ctx context.Context, param HealtcheckParam) (*HealthcheckResult
execution := k6.NewExecution(slog.Default(), param.Script)
err := execution.Start(ctx)
err := execution.Run(ctx)
if err != nil {
return nil, err
}

View file

@ -136,7 +136,7 @@ func (e *Execution) setupTracerProvider(ctx context.Context, test *loadedAndConf
return nil
}
func (e *Execution) Start(ctx context.Context) error {
func (e *Execution) Run(ctx context.Context) error {
var err error
var logger logrus.FieldLogger = logrus.StandardLogger()

View file

@ -6,7 +6,7 @@ import (
"testing"
)
func TestK6(t *testing.T) {
func TestK6Success(t *testing.T) {
ctx := context.Background()
logger := slog.Default()
@ -16,7 +16,7 @@ import { sleep } from 'k6';
export const options = {
vus: 10,
duration: '30s',
duration: '5s',
};
export default function () {
@ -27,7 +27,35 @@ export default function () {
execution := NewExecution(logger, script)
err := execution.Start(ctx)
err := execution.Run(ctx)
if err != nil {
t.Errorf("Error starting execution: %v", err)
}
}
func TestK6Fail(t *testing.T) {
ctx := context.Background()
logger := slog.Default()
script := `
import http from 'k6/http';
import { sleep } from 'k6';
export const options = {
thresholds: {
http_req_failed: ['rate<0.01'], // http errors should be less than 1%
},
};
export default function () {
http.get('https://fail.broken.example');
sleep(1);
}
`
execution := NewExecution(logger, script)
err := execution.Run(ctx)
if err != nil {
t.Errorf("Error starting execution: %v", err)
}

View file

@ -52,8 +52,8 @@ func (lt *loadedTest) consolidateDeriveAndValidateConfig() (*loadedAndConfigured
lt.logger.Debug("Consolidating config layers...")
config := lib.Options{}
config = config.Apply(lt.initRunner.GetOptions())
config.Apply(lt.initRunner.GetOptions())
if config.SystemTags == nil {
config.SystemTags = &metrics.DefaultSystemTagSet
}