roots / roots/trellis-cli

Abstract integration helpers

Open
#53 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Go
Stars
169
Forks
30
Avg merge
13h 43m
Merged PRs (30d)
7

Description

Summary

Abstract integration helpers. Something like:

- bin := os.Getenv("TEST_BINARY") 
-  if bin == "" { 
-  	t.Error("TEST_BINARY not supplied") 
-  } 
-  if _, err := os.Stat(bin); os.IsNotExist(err) { 
-  	t.Error(bin + "not exist") 
-  } 
  
-   dummy := os.Getenv("TEST_DUMMY")
- 	if dummy == "" {
- 		t.Error("TEST_DUMMY not supplied")
- 	}

+ bin, dummy = integrationTestHelper.prepareEnvironment()

  // after the tests

+ integrationTestHelper.cleanup(dummy)

integrationTestHelper.prepareEnvironment:

  1. Check environment variables are supplied
  2. Clone the dummy files into a temporary location (to be deleted by integrationTestHelper.cleanup)
  3. return the paths, i.e: bin, dummy

Motivation

Cleaning up becomes problematic when not running tests with docker.

Cloning the dummy files into temporary locations ensure integration tests don't interfere with each others, so that developers don't need to clean up dummy

Cons:

  • Tests take longer to run. But I think this is a reasonable trade-off
  • premature abstraction is evil

Additional context

https://github.com/roots/trellis-cli/blob/1741735ce5d2362313b247ff526d5a880acabaf1/cmd/dot_env_test.go#L151-L162

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 cmd/dot_env_test.go, especially the cited lines 151-162 and the cleanup example around line 167. Inspect the integration tests that repeat environment checks and dummy-file setup, then determine the shared helper's scope. Done means tests isolate temporary files, validate required environment variables, and clean up reliably.

Written by the indexing model from the issue text.

Assessment

Tech stack
go
Domain
cli, testing-qa
Issue type
Refactor
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.