Skip to content

Commit

Permalink
Simplify cloud logic
Browse files Browse the repository at this point in the history
Signed-off-by: Daniel González Lopes <[email protected]>
  • Loading branch information
dgzlopes committed Jan 3, 2025
1 parent b3e99b8 commit 6423d09
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 22 deletions.
5 changes: 2 additions & 3 deletions cmd/new.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
9 changes: 4 additions & 5 deletions cmd/newtemplates/browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
9 changes: 4 additions & 5 deletions cmd/newtemplates/minimal.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
12 changes: 6 additions & 6 deletions cmd/newtemplates/protocol.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
5 changes: 2 additions & 3 deletions cmd/newtemplates/templates.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 6423d09

Please sign in to comment.