pipe-cd / pipe-cd/pipecd

[pipedv1][terraform] Add unit tests for executeApplyStage, executePlanStage, and executeRollbackStage

Open
#7,108 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

kind/enhancement
Dominant language
Go
Stars
1.4k
Forks
364
Avg merge
1d 4h
Merged PRs (30d)
84

Description

What would you like to be added:
Three stage-execution functions in the pipedv1 Terraform plugin are marked with // TODO: add test comments but have no unit tests:

  • pkg/app/pipedv1/plugin/terraform/deployment/apply.go:27 - executeApplyStage
  • pkg/app/pipedv1/plugin/terraform/deployment/plan.go:28 - executePlanStage
  • pkg/app/pipedv1/plugin/terraform/deployment/rollback.go:27 - executeRollbackStage

These TODOs were left by the original authors as explicit invitations for contribution. The test infrastructure already exists (plugin_test.go and testdata/ directory in the same package), so no new scaffolding is needed.

Tests should cover at least:

executeApplyStage:

  • Failure when StageLogPersister is unavailable (nil client)
  • Failure when provider.NewTerraformCommand fails (invalid/missing directory)

executePlanStage:

  • Failure when StageLogPersister is unavailable
  • Failure when StageConfig JSON is invalid
  • StageStatusExited when plan shows no changes and ExitOnNoChanges: true
  • StageStatusSuccess when plan shows no changes and ExitOnNoChanges: false

executeRollbackStage:

  • Failure when StageLogPersister is unavailable
  • StageStatusFailure when RunningDeploymentSource.CommitHash is empty (first deployment guard)
  • Failure when provider.NewTerraformCommand fails

Why is this needed:

These functions are core to the Terraform plugin's deployment lifecycle but are completely untested. Adding tests here improves confidence in the pipedv1 plugin architecture and aligns with the project's existing testing patterns already seen in plugin_test.go.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the TODO locations in pkg/app/pipedv1/plugin/terraform/deployment/apply.go, plan.go, and rollback.go, then read plugin_test.go and the package testdata directory. Add unit tests for the listed failure and status cases, following the existing test infrastructure. Done means all specified scenarios are covered and the package tests pass.

Written by the indexing model from the issue text.

Assessment

Tech stack
go, terraform
Domain
devops, testing-qa
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Clearly specified
Newbie friendliness
76/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.