-
-
Notifications
You must be signed in to change notification settings - Fork 151
Expand file tree
/
Copy pathtesting_main_test.go
More file actions
29 lines (23 loc) · 792 Bytes
/
testing_main_test.go
File metadata and controls
29 lines (23 loc) · 792 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
package cmd
import (
"os"
"testing"
)
// TestMain provides package-level test setup and teardown.
// It ensures RootCmd state is properly managed across all tests in the package.
func TestMain(m *testing.M) {
// Cross-platform subprocess helper: exit with code 1 when env flag is set.
// This lets tests use the test binary itself as a cross-platform "exit 1" command.
if os.Getenv("_ATMOS_TEST_EXIT_ONE") == "1" {
os.Exit(1)
}
// Capture initial RootCmd state.
initialSnapshot := snapshotRootCmdState()
// Run all tests.
exitCode := m.Run()
// Restore RootCmd to initial state after all tests complete.
// This ensures the package leaves no pollution for other test packages.
restoreRootCmdState(initialSnapshot)
// Exit with the test result code.
os.Exit(exitCode)
}