| 5 | ) |
| 6 | |
| 7 | func TestChecker(t *testing.T) { |
| 8 | |
| 9 | assert := func(ok bool, format string, args ...interface{}) { |
| 10 | if !ok { |
| 11 | t.Errorf(format, args...) |
| 12 | } |
| 13 | } |
| 14 | |
| 15 | command := "testdata/exec.sh" |
| 16 | |
| 17 | // check non-zero exit code |
| 18 | { |
| 19 | testName := "Non-zero exit" |
| 20 | hc := Checker{Name: testName, Command: command, Arguments: []string{"1", testName}, Attempts: 2} |
| 21 | |
| 22 | result, err := hc.Check() |
| 23 | assert(err == nil, "expected no error, got %v, %#v", err, result) |
| 24 | assert(result.Title == testName, "expected result.Title == %s, got '%s'", testName, result.Title) |
| 25 | assert(result.Down == true, "expected result.Down = true, got %v", result.Down) |
| 26 | } |
| 27 | |
| 28 | // check zero exit code |
| 29 | { |
| 30 | testName := "Non-zero exit" |
| 31 | hc := Checker{Name: testName, Command: command, Arguments: []string{"0", testName}, Attempts: 2} |
| 32 | |
| 33 | result, err := hc.Check() |
| 34 | assert(err == nil, "expected no error, got %v, %#v", err, result) |
| 35 | assert(result.Title == testName, "expected result.Title == %s, got '%s'", testName, result.Title) |
| 36 | assert(result.Down == false, "expected result.Down = false, got %v", result.Down) |
| 37 | } |
| 38 | } |