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

feat: clear and delete cookies [#2476] #2509

Merged
merged 9 commits into from
May 18, 2022

Conversation

Maksimall89
Copy link
Contributor

Realized feature #2476.

  • clear all cookies for a particular URL
  • delete cookies for a particular URL

Demo script:

import http from 'k6/http';

export default function () {
  http.get('https://httpbin.test.k6.io/cookies/set?one=1&two=2');
  const jar = http.cookieJar();  // get the VU specific jar
  jar.set('https://httpbin.test.k6.io/cookies', 'three', "3");

  jar.delete('https://httpbin.test.k6.io/cookies', 'one');
  const resDelete = http.get('https://httpbin.test.k6.io/cookies');
  console.log(JSON.stringify(resDelete.json().cookies));

  jar.clear('https://httpbin.test.k6.io/cookies');
  const resClear = http.get('https://httpbin.test.k6.io/cookies');
  console.log(JSON.stringify(resClear.json().cookies));

  const resAll = http.get('https://httpbin.test.k6.io/cookies/set?one=1&two=2');
  console.log(JSON.stringify(resAll.json().cookies));

}

Output:

          /\      |‾‾| /‾‾/   /‾‾/   
     /\  /  \     |  |/  /   /  /    
    /  \/    \    |     (   /   ‾‾\  
   /          \   |  |\  \ |  (‾)  | 
  / __________ \  |__| \__\ \_____/ .io

  execution: local
     script: test.js
     output: -

  scenarios: (100.00%) 1 scenario, 1 max VUs, 10m30s max duration (incl. graceful stop):
           * default: 1 iterations for each of 1 VUs (maxDuration: 10m0s, gracefulStop: 30s)

INFO[0001] {"two":"2","three":"3"}                       source=console
INFO[0002] {}                                            source=console
INFO[0002] {"two":"2","one":"1"}                         source=console

running (00m02.3s), 0/1 VUs, 1 complete and 0 interrupted iterations
default ✓ [======================================] 1 VUs  00m02.3s/10m0s  1/1 iters, 1 per VU

@CLAassistant
Copy link

CLAassistant commented May 2, 2022

CLA assistant check
All committers have signed the CLA.

@github-actions github-actions bot requested review from codebien and olegbespalov May 2, 2022 13:24
@na-- na-- added this to the v0.39.0 milestone May 4, 2022
Copy link
Contributor

@olegbespalov olegbespalov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @Maksimall89!

Thanks for your contribution. Changes look good 👍

However, I'd like to propose two small things:

  • remove unused opts goja.Value argument
  • cover new functionality with the tests.

Cheers!

Copy link
Contributor

@codebien codebien left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @Maksimall89, thanks for your contribution. 🎉 I added a single request, let me know if I'm missing the why you added it.

As @olegbespalov said the test part is also very important for us. 🙏

js/modules/k6/http/cookiejar.go Outdated Show resolved Hide resolved
js/modules/k6/http/cookiejar.go Outdated Show resolved Hide resolved
@codecov-commenter
Copy link

codecov-commenter commented May 5, 2022

Codecov Report

Merging #2509 (4506459) into master (42f2e60) will increase coverage by 2.73%.
The diff coverage is 67.10%.

@@            Coverage Diff             @@
##           master    #2509      +/-   ##
==========================================
+ Coverage   72.71%   75.45%   +2.73%     
==========================================
  Files         184      202      +18     
  Lines       14571    15998    +1427     
==========================================
+ Hits        10596    12071    +1475     
+ Misses       3333     3171     -162     
- Partials      642      756     +114     
Flag Coverage Δ
ubuntu 75.33% <67.10%> (+2.69%) ⬆️
windows 75.18% <66.89%> (+2.80%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
api/common/context.go 100.00% <ø> (ø)
api/v1/client/client.go 0.00% <0.00%> (ø)
api/v1/client/metrics.go 0.00% <0.00%> (ø)
api/v1/client/status.go 0.00% <0.00%> (ø)
api/v1/group.go 54.05% <ø> (-35.01%) ⬇️
api/v1/metric.go 68.18% <ø> (-31.82%) ⬇️
api/v1/routes.go 55.31% <ø> (ø)
api/v1/status.go 100.00% <ø> (ø)
cmd/login_cloud.go 19.76% <0.00%> (+19.76%) ⬆️
cmd/login_influxdb.go 11.66% <0.00%> (+11.66%) ⬆️
... and 247 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update eff2c7d...4506459. Read the comment docs.

@Maksimall89
Copy link
Contributor Author

Hey everyone, thanks for your answers! I need time to understand and fix tests

@olegbespalov olegbespalov added the documentation-needed A PR which will need a separate PR for documentation label May 5, 2022
@Maksimall89
Copy link
Contributor Author

Maksimall89 commented May 5, 2022

I fixed it, I hope...
grafana/k6-docs#660 I will do after merge
P.S. I think you need to add more information (or add it into docker-compose) about local unit-tests because there is no information anywhere about what needs to be installed the mock - httpbin.

@Maksimall89
Copy link
Contributor Author

Maksimall89 commented May 6, 2022

hey, I add t.Parallel() but really linter request to add this for all tests in the file.

@olegbespalov
Copy link
Contributor

@Maksimall89 Unfortunately, right now, adding t.Parallel() causes DATA RACE, so for now, do not increase scope of the PR (reorganizing the tests to make them possible to run in parallel) let's just use //nolint:paralleltest.

Regarding the running the tests, you can use a simple make check. It runs linter + tests.

@Maksimall89
Copy link
Contributor Author

@olegbespalov thx, I add //nolint:parallel test like a workaround

@Maksimall89
Copy link
Contributor Author

Maksimall89 commented May 6, 2022

@codebien could you restart tests? I see a flaky test https://github.com/grafana/k6/runs/6320853392?check_suite_focus=true because I nothing changed there

Copy link
Contributor

@codebien codebien left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, @Maksimall89 thanks again for your updates, we plan to merge this PR during the next week.

@Maksimall89
Copy link
Contributor Author

Maksimall89 commented May 6, 2022

Ok, thank you for your support!

@olegbespalov olegbespalov merged commit 50f6926 into grafana:master May 18, 2022
@basgroot
Copy link

I have a scenario where clear and delete cookies don't work.
#3026

Probably it is something I don't understand, but do you mind taking a look?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation-needed A PR which will need a separate PR for documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants