From 6423d0971d3684176544904684bb175287c42b2d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Gonz=C3=A1lez=20Lopes?= Date: Fri, 3 Jan 2025 13:38:43 +0100 Subject: [PATCH] Simplify cloud logic MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Daniel González Lopes --- cmd/new.go | 5 ++--- cmd/newtemplates/browser.js | 9 ++++----- cmd/newtemplates/minimal.js | 9 ++++----- cmd/newtemplates/protocol.js | 12 ++++++------ cmd/newtemplates/templates.go | 5 ++--- 5 files changed, 18 insertions(+), 22 deletions(-) diff --git a/cmd/new.go b/cmd/new.go index 466325094ce..9cd8c2a5025 100644 --- a/cmd/new.go +++ b/cmd/new.go @@ -54,9 +54,8 @@ func (c *newScriptCmd) run(cmd *cobra.Command, args []string) error { } argsStruct := templates.TemplateArgs{ - ScriptName: target, - EnableCloud: c.projectID != "", - ProjectID: c.projectID, + ScriptName: target, + ProjectID: c.projectID, } if err := templates.ExecuteTemplate(fd, tmpl, argsStruct); err != nil { diff --git a/cmd/newtemplates/browser.js b/cmd/newtemplates/browser.js index 46dbc00f15a..5ef80094e7b 100644 --- a/cmd/newtemplates/browser.js +++ b/cmd/newtemplates/browser.js @@ -14,12 +14,11 @@ export const options = { }, }, }, - }, {{ if .EnableCloud }} - cloud: { {{ if .ProjectID }} - projectID: {{ .ProjectID }}, {{ else }} - // projectID: 12345, // Replace this with your own projectID {{ end }} + },{{ if .ProjectID }} + cloud: { + projectID: {{ .ProjectID }}, name: "{{ .ScriptName }}", - }, {{ end }} + },{{ end }} }; export function setup() { diff --git a/cmd/newtemplates/minimal.js b/cmd/newtemplates/minimal.js index 191ced04806..716c08802ea 100644 --- a/cmd/newtemplates/minimal.js +++ b/cmd/newtemplates/minimal.js @@ -3,12 +3,11 @@ import { sleep, check } from 'k6'; export const options = { vus: 10, - duration: '30s',{{ if .EnableCloud }} - cloud: { {{ if .ProjectID }} - projectID: {{ .ProjectID }}, {{ else }} - // projectID: 12345, // Replace this with your own projectID {{ end }} + duration: '30s',{{ if .ProjectID }} + cloud: { + projectID: {{ .ProjectID }}, name: "{{ .ScriptName }}", - }, {{ end }} + },{{ end }} }; export default function() { diff --git a/cmd/newtemplates/protocol.js b/cmd/newtemplates/protocol.js index 623be6fabe5..f2781c2d7c1 100644 --- a/cmd/newtemplates/protocol.js +++ b/cmd/newtemplates/protocol.js @@ -9,15 +9,15 @@ export const options = { { duration: "10s", target: 5 }, { duration: "20s", target: 10 }, { duration: "1s", target: 0 }, - ], thresholds: { + ], + thresholds: { http_req_failed: ["rate<0.01"], http_req_duration: ["p(95)<500", "p(99)<1000"], - },{{ if .EnableCloud }} - cloud: { {{ if .ProjectID }} - projectID: {{ .ProjectID }}, {{ else }} - // projectID: 12345, // Replace this with your own projectID {{ end }} + },{{ if .ProjectID }} + cloud: { + projectID: {{ .ProjectID }}, name: "{{ .ScriptName }}", - }, {{ end }} + },{{ end }} }; export function setup() { diff --git a/cmd/newtemplates/templates.go b/cmd/newtemplates/templates.go index 538480f6b4b..4b14ffc8a6f 100644 --- a/cmd/newtemplates/templates.go +++ b/cmd/newtemplates/templates.go @@ -28,9 +28,8 @@ var ( // TemplateArgs represents arguments passed to templates type TemplateArgs struct { - ScriptName string - EnableCloud bool - ProjectID string + ScriptName string + ProjectID string } // GetTemplate selects the appropriate template based on the type