1
0
Fork 0
mirror of https://github.com/gocsaf/csaf.git synced 2025-12-22 05:40:11 +01:00

use defer to restore original args.

This commit is contained in:
Sascha L. Teichmann 2023-09-25 20:12:17 +02:00
parent 1854cc4c58
commit 52476f8560

View file

@ -18,7 +18,9 @@ type config struct {
// TestParse helps parsing command line arguments and loading
// stored configurations from file.
func TestParse(t *testing.T) {
originalArgs := os.Args
orig := os.Args
defer func() { os.Args = orig }()
os.Args = []string{"cmd"}
defaultConfigLocation := []string{"data/config.toml"}
p := Parser[config]{
@ -77,7 +79,7 @@ func TestParse(t *testing.T) {
}
// Build subprocess that can be exited
cmd := exec.Command(originalArgs[0], "-test.run=TestParse")
cmd := exec.Command(orig[0], "-test.run=TestParse")
cmd.Env = append(os.Environ(), "TEST_HELP=1")
err := cmd.Run()
if err != nil {
@ -91,14 +93,12 @@ func TestParse(t *testing.T) {
return
}
cmd = exec.Command(originalArgs[0], "-test.run=TestParse")
cmd = exec.Command(orig[0], "-test.run=TestParse")
cmd.Env = append(os.Environ(), "TEST_VERSION=1")
err = cmd.Run()
if err != nil {
t.Fatalf(err.Error())
}
// Reset os.Args
os.Args = originalArgs
}
// TestFindConfigFile tests if findConfigFile() correctly finds existing and