forked from skeema/skeema
-
Notifications
You must be signed in to change notification settings - Fork 2
/
exit_test.go
34 lines (31 loc) · 1.02 KB
/
exit_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package main
import (
"errors"
"testing"
)
func TestExitCode(t *testing.T) {
err := errors.New("test error")
if ExitCode(err) != CodeFatalError {
t.Errorf("Expected exit code for non-nil non-ExitValue to be %d, instead found %d", CodeFatalError, ExitCode(err))
}
err = nil
if ExitCode(err) != CodeSuccess {
t.Errorf("Expected exit code for nil error to be %d, instead found %d", CodeSuccess, ExitCode(err))
}
err = NewExitValue(CodePartialError, "test error")
if ExitCode(err) != CodePartialError {
t.Errorf("Expected exit code to be %d, instead found %d", CodePartialError, ExitCode(err))
}
}
func TestExitValueError(t *testing.T) {
err := NewExitValue(CodeBadConfig, "test format string %s %t", "hello world", true)
expected := "test format string hello world true"
if actual := err.Error(); actual != expected {
t.Errorf("Found message %v, expected %v", actual, expected)
}
err = nil
expected = ""
if actual := err.Error(); actual != expected {
t.Errorf("Found message %v, expected %v", actual, expected)
}
}