-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathassertions_status.go
54 lines (52 loc) · 1.31 KB
/
assertions_status.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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package qac
import (
"fmt"
"strconv"
)
func (a *StatusAssertion) verify(context planContext) AssertionResult {
result := AssertionResult{
description: fmt.Sprintf(`status for %s`, context.commandResult.execution),
}
commandErrorIsAcceptable := false
commandResult := context.commandResult
if a.GreaterThan != "" {
i, err := strconv.Atoi(a.GreaterThan)
if err != nil {
result.addError(err)
// block
return result
}
if commandResult.exitCode <= i {
result.addErrorf(`exit code expected GT %d got %d`, i, commandResult.exitCode)
}
commandErrorIsAcceptable = true
}
if a.LesserThan != "" {
i, err := strconv.Atoi(a.LesserThan)
if err != nil {
result.addError(err)
// block
return result
}
if commandResult.exitCode >= i {
result.addErrorf(`exit code expected LT %d got %d`, i, commandResult.exitCode)
}
commandErrorIsAcceptable = true
}
if a.EqualsTo != "" {
i, err := strconv.Atoi(a.EqualsTo)
if err != nil {
result.addError(err)
// block
return result
}
if commandResult.exitCode != i {
result.addErrorf(`exit code expected EQUALS %d got %d`, i, commandResult.exitCode)
}
commandErrorIsAcceptable = i > 0
}
if commandResult.err != nil && !commandErrorIsAcceptable {
result.addErrorf(`command execution error: %v`, commandResult.err)
}
return result
}