diff --git a/commands/commands.go b/commands/commands.go index 69643968..c994c106 100644 --- a/commands/commands.go +++ b/commands/commands.go @@ -85,7 +85,7 @@ func FullError(err error) { func errorWith(err error, fatalErrFn func(error, string, ...interface{}), errFn func(string, ...interface{})) { if Debugging || errors.IsFatalError(err) { - fatalErrFn(err, "") + fatalErrFn(err, "%s", err) return } @@ -101,8 +101,12 @@ func Debug(format string, args ...interface{}) { log.Printf(format, args...) } -// LoggedError prints a formatted message to Stderr and writes a stack trace for -// the error to a log file without exiting. +// LoggedError prints the given message formatted with its arguments (if any) to +// Stderr. If an empty string is passed as the "format" arguemnt, only the +// standard error logging message will be printed, and the error's body will be +// omitted. +// +// It also writes a stack trace for the error to a log file without exiting. func LoggedError(err error, format string, args ...interface{}) { if len(format) > 0 { Error(format, args...) diff --git a/test/cmd/lfstest-gitserver.go b/test/cmd/lfstest-gitserver.go index 9f6a2894..ebb71849 100644 --- a/test/cmd/lfstest-gitserver.go +++ b/test/cmd/lfstest-gitserver.go @@ -47,7 +47,7 @@ var ( // contentHandlers = []string{ "status-batch-403", "status-batch-404", "status-batch-410", "status-batch-422", "status-batch-500", - "status-storage-403", "status-storage-404", "status-storage-410", "status-storage-422", "status-storage-500", + "status-storage-403", "status-storage-404", "status-storage-410", "status-storage-422", "status-storage-500", "status-storage-503", "status-legacy-404", "status-legacy-410", "status-legacy-422", "status-legacy-403", "status-legacy-500", "status-batch-resume-206", "batch-resume-fail-fallback", "return-expired-action", "return-invalid-size", "object-authenticated", @@ -489,6 +489,15 @@ func storageHandler(w http.ResponseWriter, r *http.Request) { return case "status-storage-500": w.WriteHeader(500) + return + case "status-storage-503": + w.Header().Set("Content-Type", "application/vnd.git-lfs+json") + w.WriteHeader(503) + + json.NewEncoder(w).Encode(&struct { + Message string `json:"message"` + }{"LFS is temporarily unavailable"}) + return case "object-authenticated": if len(r.Header.Get("Authorization")) > 0 { diff --git a/test/test-push-failures.sh b/test/test-push-failures.sh index 3096d0ad..30b20501 100755 --- a/test/test-push-failures.sh +++ b/test/test-push-failures.sh @@ -2,8 +2,16 @@ . "test/testlib.sh" +# push_fail_test preforms a test expecting a `git lfs push` to fail given the +# contents of a particular file contained within that push. The Git server used +# during tests has certain special cases that are triggered by finding specific +# keywords within a file (as given by the first argument). +# +# An optional second argument can be included, "msg", that assert that the +# contents "msg" was included in the output of a `git lfs push`. push_fail_test() { local contents="$1" + local msg="$2" set -e @@ -18,10 +26,14 @@ push_fail_test() { git commit -m "welp" set +e - git push origin master - res="$?" + git push origin master 2>&1 | tee push.log + res="${PIPESTATUS[0]}" set -e + if [ ! -z "$msg" ]; then + grep "$msg" push.log + fi + refute_server_object "$reponame" "$(calc_oid "$contents")" if [ "$res" = "0" ]; then echo "push successful?" @@ -69,6 +81,14 @@ begin_test "push: upload file with storage 500" ) end_test +begin_test "push: upload file with storage 503" +( + set -e + + push_fail_test "status-storage-503" "LFS is temporarily unavailable" +) +end_test + begin_test "push: upload file with api 403" ( set -e