Skip to content

Commit

Permalink
Add a test for when name is invalid
Browse files Browse the repository at this point in the history
  • Loading branch information
ankur22 committed Oct 17, 2024
1 parent 5a7dea5 commit c9d2182
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion tests/page_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1914,6 +1914,7 @@ func TestPageOnMetric(t *testing.T) {
fun string
want string
wantRegex string
wantErr string
}{
{
// Just a single page.on.
Expand Down Expand Up @@ -2022,6 +2023,20 @@ func TestPageOnMetric(t *testing.T) {
});`,
wantRegex: `http://127\.0\.0\.1:[0-9]+/ping\?h=[0-9a-z]+`,
},
{
// We should get an error back when the name is invalid (empty string)
name: "with_invalid_name",
fun: `page.on('metric', (metric) => {
metric.tag({
name:' ',
matches: [
{url: /^http:\/\/127\.0\.0\.1\:[0-9]+\/ping\?h=[0-9a-z]+$/, method: 'GET'},
]
});
});`,
wantRegex: `http://127\.0\.0\.1:[0-9]+/ping\?h=[0-9a-z]+`,
wantErr: `name " " is invalid`,
},
}

for _, tt := range tests {
Expand Down Expand Up @@ -2077,7 +2092,7 @@ func TestPageOnMetric(t *testing.T) {
// Some of the business logic is in the mapping layer unfortunately.
// To test everything is wried up correctly, we're required to work
// with RunPromise.
got := vu.RunPromise(t, `
gv, err := vu.RunAsync(t, `
const page = await browser.newPage()
%s
Expand All @@ -2086,6 +2101,15 @@ func TestPageOnMetric(t *testing.T) {
await page.close()
`, tt.fun, tb.url("/home"))

if tt.wantErr != "" {
assert.ErrorContains(t, err, tt.wantErr)
} else {
assert.NoError(t, err)
}

got := k6test.ToPromise(t, gv)

assert.True(t, got.Result().Equals(sobek.Null()))

close(samples)
Expand Down

0 comments on commit c9d2182

Please sign in to comment.