-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Change so backends return a exec.Cmd instead of actually running the command. Refactor the calling to a setup-phase where any errors abort the entire run first (creating the body-temp file if any). Then either CallAsString and be done with it, or run the returned command. If running the command, embellish somewhat an error message if the deadline is exceeded or if the backend returns an error. Then the last phase is to remove the temp-file (if any). If the temp-file cannot be removed, print an error. Then print any backen-error unless the context was cancelled. Then print any output from the command as separate streams to stderr or stdout. Then unless context was cancelled or dead line exceeded, echo back the backend error-status. Else return 1. Test plan: * Have a template with a [Body} section. Add an .env file and set TMPDIR= to some non-existent directory. Run go run cmd/ain/main.go template.ain and verify error on temp-file canot be created. Verify exit status 1. * Verify -p with a standard template with a [Body] section still works for all backends. Compare the result with the previous version of ain and verify they are the same. * Hack the backendInput.RemoveBodyTempFile and add some chars to the filename. Run go run cmd/ain/main.go. Verify an error on removal of temp-file on stderr. * Have the same template as above and remove the temp-file hack. Set a high Timeout= and press ctrl+c. Verify no error is printed and that exit code 128+2. * Set the timeout to a low value as above and have the backend time out. Verify that an error message on backend timed out and an exit status of 1. * Cause some regular backend error (such as calling a non-existant host). Verify backend error and stdout relayed to the terminal and that the exit code is the same as the backend would give. * Same setup as above but some good case, such as an existing host. Verify stderr is echoed back to the terminal and the exit code copied. * Have a template with a valid [Host], curl as the backend and pass in the [BackendOption] -D /dev/stderr. Call go run cmd/ain/main.go template.ain 2> stderr.txt 1> stdout.txt. Verify stderr now copies the stderr stream of the backend binary, and that stdout does the same.
- Loading branch information
Showing
5 changed files
with
92 additions
and
78 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters