internal/cli/commands/catalog/TESTING.md
This document describes the comprehensive end-to-end testing implementation for the Terragrunt Catalog CLI command using teatest from Charm's experimental testing library.
Testing the TUI for the catalog command is a little tricky, as we can't conveniently have someone actually go in and test the TUI every time we make any change that could impact it. To make sure that we don't break the TUI, we take a layered approach to assuring the command works as expected.
The core logic used for the catalog command is actually handled in services/catalog.
This package can be tested in isolation with standard unit tests, and we minimize any logic done outside of it to reduce the surface area for testing of the TUI.
The TUI itself is tested using teatest from Charm's experimental testing library.
This library provides a way to generate golden files that can be used to test the TUI to ensure that we don't encounter catastrophic regressions that would prevent loading of the TUI.
The catalog command initialization is tested in catalog_test.go to make sure we can setup the CLI command correctly to start up the TUI.
teatest.RequireEqualOutput(t, out) for consistent output testing.gitattributes file to handle golden files properlyTests use teatest.WaitFor() with appropriate timeouts and check intervals:
teatest.WaitFor(t, tm.Output(), func(bts []byte) bool {
return bytes.Contains(bts, []byte("List of Modules"))
}, teatest.WithCheckInterval(time.Millisecond*100), teatest.WithDuration(time.Second*2))
go test -v ./cli/commands/catalog/tui/ -run TestTUIInitialOutput -update