ysugimoto / falco

falco is a VCL parser and linter decicated to Fastly
MIT License
101 stars 25 forks source link

[Feature] Structure unit-tests like a jest to illustrate VCL's workflow #301

Closed Shinyaigeek closed 4 months ago

Shinyaigeek commented 5 months ago

Kind of proposals

You can turn on multiple checkboxes.

Describe the feature

Thank you for developing this great tool! This is just a feature request about falco's testing feature.

I want the function to structure unit-tests like a jest's describe, test, it label. Due to the VCL's variable limitation, VCL's each subroutine's set it's returned value as a global variable(like a req.http.VARS:hoge), and a following subroutine will refers it and invoke the process which depends on it (at least in my application).

In a view of testing, each unit-test set req.http.VARS:~~ as parameters before invoking a testing targeted subroutine, and invoke subroutine, and asseret req.http.VARS:~~ as it's returned values. This way is useful for testing in a micro-scope, but not useful for in a macro-scope.

I want the function to structure (or unify) micro-scope unit-tests ( it ) and illustrate macro-scope testing scenario (describe)

usecase in real world

for example, please think about writing a VCL to handle login processing. You might want to split the its processing to the above 3 steps (= subroutine ).

  1. parse auth JWT in cookie: sub parse_jwt
  2. Validate the result of parsed JWT in step 1: sub validate_jwt
  3. Handle the specific process for the each auth state.: sub handle_auth

As mentioned above, each unit-tests for the each subroutine set some req.http.VARS:~~ as parameters, and assert req.http.VARS:~~ as subroutine's returned value.

Each unit-test's meaning and subroutine's specification are clear thanks to it's label setted by @suite decorator, but overall login flow's test's meaning and specification are unclear in a macro view.

ysugimoto commented 4 months ago

@Shinyaigeek Thank you for reporting the issue. Now we have custom-syntax registration for parsing VCL so I've tried to implement some syntax for testing like:

Please try to use https://github.com/ysugimoto/falco/tree/feature/testing-syntax for your testing environment and let me know if you have any additional opinions or problems for this feature.

Shinyaigeek commented 4 months ago

@ysugimoto Thank you for fast reply and PoC! I tested it, and it was exactly what I wanted! Thanks!

ysugimoto commented 4 months ago

@Shinyaigeek Thanks for testing, I will create PR and merge into upstream.