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

feature request: Unit Testing Taskfiles #1659

Open
ryanpodonnell1 opened this issue May 16, 2024 · 2 comments
Open

feature request: Unit Testing Taskfiles #1659

ryanpodonnell1 opened this issue May 16, 2024 · 2 comments
Labels
state: needs triage Waiting to be triaged by a maintainer.

Comments

@ryanpodonnell1
Copy link

ryanpodonnell1 commented May 16, 2024

Summary

As remote taskfiles are on the roadmap it probably makes sense to be able to unit test taskfiles as well to ensure that any breaking changes are adequately accounted for as it can have wide ranging impacts.

ref: #1317

Proposal

Test Taskfiles should be in the same dir and follow the same convention as go tests. The test taskfiles will call all tasks the test prefix as well to determine which individual tasks within the taskfile should be tested

example dir:

taskfiledir/
      git_tasks.yml
      test_git_tasks.yml

example task:

version: 'x'
tasks:
  task1:
    - echo 'somestring' > somefile.txt

example test task:

version: 'x'
tasks:
  test_task1:
    -  test -f somefile.txt

The tests should also be able to mock out sections where tasks other tasks rely on the execution of certain tasks (task1 calls task2) via - task: task2 (which actually makes an HTTP call or something) or the deps block:

version: 'x'
tasks:
  task1:
    - task:  task2
    - echo 'somestring' > somefile.txt
version: 'x'
mocks:
  task2:
   cmd: 'echo "value=$(some JSON respose)" > some.env'

test_task1:
 dotenv: [some.env]
 cmds:
  - cmd:  |
       if [[ $value != "" ]]; then
          echo "failed"
          exit 1
       fi

this of course would result in a subcommand of something like:

task --test -f ./...

@task-bot task-bot added the state: needs triage Waiting to be triaged by a maintainer. label May 16, 2024
@ryanpodonnell1 ryanpodonnell1 changed the title Unit Testing Taskfiles feature request: Unit Testing Taskfiles May 16, 2024
@ryanpodonnell1
Copy link
Author

the idea is heavily inspired by benthos where you can mock out certain processors and works fairly well:
https://www.benthos.dev/docs/configuration/unit_testing/#mocking-processors

@trulede
Copy link

trulede commented Jun 1, 2024

What about E2E tests?

With a format like txtar and Testscript it would become very easy to write test cases from a cli/user perspective. Currently the tests are mostly in task_test.go, and make reference to files in testdata folder - its a bit overwhelming.

I might write unit tests the "normal" way, making reference to files in testdata if necessary. But actually what I would rather write is E2E tests, using the simple Testscript method, because they prove task is working and also provide easy to understand examples.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
state: needs triage Waiting to be triaged by a maintainer.
Projects
None yet
Development

No branches or pull requests

3 participants