Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Templating issue in latest k6 release #134

Closed
varghesevv opened this issue Jul 29, 2022 · 1 comment
Closed

Templating issue in latest k6 release #134

varghesevv opened this issue Jul 29, 2022 · 1 comment

Comments

@varghesevv
Copy link

Javascript templating issue in latest version of k6

working - docker run -v ${PWD}:/test loadimpact/k6:0.39.0-24-g0127a508 run /test/test-1.js

not working - docker run -v ${PWD}:/test loadimpact/k6:0.39.0-25-ge2316a28 run /test/test-1.js

/* conf-test-1.js */
export const options = {
  stages: [
    { duration: '5s', target: 2 } 
  ],
  thresholds: {
    'http_req_duration': ['p(99)<1500']
  },
};

export function get_url(){
  return `${BASE_URL}/auth/token/login/`;
}

/* test-1.js */
import http from 'k6/http';
import { check, group, sleep } from 'k6';

import { get_url } from './conf-test-1.js'
export { options } from './conf-test-1.js'

const BASE_URL = 'https://test-api.k6.io';
const USERNAME = 'TestUser';
const PASSWORD = 'SuperCroc2020';

export default () => {
  const loginRes = http.post(get_url(), {
    username: USERNAME,
    password: PASSWORD,
  });

  const authHeaders = {
    headers: {
      Authorization: `Bearer ${loginRes.json('access')}`,
    },
  };

  const myObjects = http.get(`${BASE_URL}/my/crocodiles/`, authHeaders).json();
  check(myObjects, { 'retrieved crocodiles': (obj) => obj.length > 0 });

  sleep(1);
};
@varghesevv
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant