Check string interpolation

I am guessing the check function takes a lambda, but I’m a bit unsure why it’s not accepting string interpolation?

  import http from 'k6/http'
  import { check } from 'k6'
  
  export default function () {
    const base_url = "http://computer-database.gatling.io"
    get(url = base_url, status_code = 200)
  }
  
  private function get(url = "", status_code = 418) {
    const res = http.get(url)
    check(res, {
      `$url equals $status_code`: (r) => r.status === status_code,
    })  
  }

Many Thanks

Adrian

The second argument is an object/map of string to function(lambda alsos). But in order to make the key string when it’s a string template you need to wrap it in [] so but you also need to wrap the variables in {} so:

check(res, {
      `${url} equals ${status_code}`: (r) => r.status === status_code,
    })  

Hope this helps you
p.s. I have no idea what private is suppsoed to do and arguably get(url = base_url, status_code = 200) should just be get(base_url, 200)

1 Like