Created
July 16, 2020 18:42
-
-
Save anonymouse64/89ceb21d80772658c82d2766f8b25c10 to your computer and use it in GitHub Desktop.
go-check MockCommand mocking of a fully verifying argument script
This file contains hidden or 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
| func mockRealSystemdMountInBash(c *C, expArgs [][]string) *testutil.MockCmd { | |
| stateCallFile := filepath.Join(c.MkDir(), "systemd-mount-state-call") | |
| template := fmt.Sprintf(` | |
| STATE_FILE=%s | |
| if [ ! -f "$STATE_FILE" ]; then | |
| CALL_NUM=0 | |
| else | |
| CALL_NUM=$(cat "$STATE_FILE") | |
| fi | |
| CALL_NUM=$(( CALL_NUM + 1 )) | |
| echo "${CALL_NUM}" > "$STATE_FILE" | |
| ALL_ARGS="$*" | |
| #set -x | |
| #exec 2>&1 | |
| fail() { | |
| echo "unexpected systemd-mount call: ${ALL_ARGS}" | |
| exit 1 | |
| } | |
| case "${CALL_NUM}" in | |
| `, stateCallFile) | |
| for i, args := range expArgs { | |
| argsAsString := strings.Join(args, " ") | |
| caseStr := fmt.Sprintf(` | |
| %d) | |
| test "${ALL_ARGS}" = %q || fail ;; | |
| `, | |
| i+1, | |
| argsAsString, | |
| ) | |
| template += caseStr | |
| } | |
| // add the closing bit to the case | |
| template += ` | |
| *) | |
| fail | |
| esac | |
| ` | |
| return testutil.MockCommand(c, "systemd-mount", template) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment