post image :date_long | 1 min Read

Create vim function to generate postman tests

function! CreateTest()
  let a = 0
  let names = ['name', 'vlan_id', 'subnet', 'mask', 'name_network', 'description']
  let values = ['"*"', 'true', '""', '"some_string"', '0', '-1', '100000', '3.543']

  put='['

  for n in names
    for v in values
      let a +=1

      if matchstr(v, '""') == '""'
        let _v = substitute(v,'"\+', '', 'g')
      elseif matchstr(v, '*') == '*'
        let _v = substitute(v,'"\+', '', 'g')
      elseif matchstr(v, '"some_string"') == '"some_string"'
        let _v = substitute(v,'"\+', '', 'g')
      else
        let _v = v
      endif

      put='{\"_query_key\": \"'.n.'\",
            \ \"_query_value\": '.v.',
            \ \"_response\": 200,
            \ \"_description\": \"Invalid search string for '.n.' with value of: '._v.'\",
            \ \"_reason\": \"\",
            \ \"_iteration\": '.a.'}, '
    endfor
  endfor

  put=']'

endfunction
author image

Jan Toth

I have been in DevOps related jobs for past 6 years dealing mainly with Kubernetes in AWS and on-premise as well. I spent quite a lot …

comments powered by Disqus