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

How to set a variable to Kong Context while doing unit tests? #171

Closed
lays147 opened this issue Jan 19, 2024 · 9 comments
Closed

How to set a variable to Kong Context while doing unit tests? #171

lays147 opened this issue Jan 19, 2024 · 9 comments
Assignees

Comments

@lays147
Copy link

lays147 commented Jan 19, 2024

Hi,
I'm trying to write a couple of unit tests for a plugin that I'm doing, and based on the docs, I can't see where I could add a variable to the kong.context for the purpose of the unit test.

Checking the source code, the Ctx is available at env.pdk, but this variable is not available for external access.

@lays147 lays147 changed the title How to set a variable to Kong Context while doing unit tests How to set a variable to Kong Context while doing unit tests? Jan 19, 2024
@Water-Melon
Copy link

@nowNick
Copy link

nowNick commented Jan 29, 2024

Hey! @lays147

Thank you for sending your question! Does the link that @Water-Melon sent above help (☝️)? There's some documentation that should explain how to use kong.ctx (context). Would that work for your use case?

@nowNick nowNick self-assigned this Jan 29, 2024
@lays147
Copy link
Author

lays147 commented Jan 29, 2024

Hi @nowNick no. As I said, the context var on the test pdk is not available. I can use it on writing a plugin, but I can't manage the context on the text setup. Because in this case, I'm retrieving a var from the context, not setting it.

Also, the docs are wrong because to use SetShared requires a key and value, and the pdk docs shows otherwise. Moreover, it does not make sense to save something in context without a value, only with a key.

@nowNick
Copy link

nowNick commented Jan 29, 2024

Oh! Ok I see. Apologies for the confusion then!

I'll take a deeper look at this and I'll try to offer better guidance / report bugs.

@winslowdibona
Copy link
Contributor

@nowNick I was running into the same issue and created PR #174 which would allow the usage of the shared context during testing.

@nowNick
Copy link

nowNick commented Feb 15, 2024

That's awesome @winslowdibona! Thank you for your contribution!

@winslowdibona
Copy link
Contributor

@nowNick Is there someone specific I should reach out to about reviewing PR #174 ?
I've mentioned a few others on there but I haven't gotten any reviews/comments on it in about a week.

@nowNick
Copy link

nowNick commented Feb 20, 2024

Hey @winslowdibona
If possible I'd like to merge this one first: #170 and then rebase your PR on top of it.
I'll keep track of both of these PRs to make sure they're merged swiftly.

@gszr
Copy link
Member

gszr commented Feb 21, 2024

Solved by #174

@gszr gszr closed this as completed Feb 21, 2024
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

5 participants