return error exit status in prometheus cli (#4296)
Signed-off-by: mikeykhalil <mikeyfkhalil@gmail.com>
This commit is contained in:
parent
630f42fcf1
commit
78e0784d04
|
@ -595,6 +595,7 @@ func main() {
|
|||
}
|
||||
if err := g.Run(); err != nil {
|
||||
level.Error(logger).Log("err", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
level.Info(logger).Log("msg", "See you next time!")
|
||||
}
|
||||
|
|
|
@ -20,6 +20,7 @@ import (
|
|||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"syscall"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
|
@ -155,3 +156,20 @@ func TestComputeExternalURL(t *testing.T) {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Let's provide an invalid configuration file and verify the exit status indicates the error.
|
||||
func TestFailedStartupExitCode(t *testing.T) {
|
||||
fakeInputFile := "fake-input-file"
|
||||
expectedExitStatus := 1
|
||||
|
||||
prom := exec.Command(promPath, "--config.file="+fakeInputFile)
|
||||
err := prom.Run()
|
||||
testutil.NotOk(t, err, "")
|
||||
|
||||
if exitError, ok := err.(*exec.ExitError); ok {
|
||||
status := exitError.Sys().(syscall.WaitStatus)
|
||||
testutil.Equals(t, expectedExitStatus, status.ExitStatus())
|
||||
} else {
|
||||
t.Errorf("unable to retrieve the exit status for prometheus: %v", err)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue