/
entities.go
113 lines (98 loc) · 2.89 KB
/
entities.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
// Copyright (c) 2016 Uber Technologies, Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
package execute
import (
"fmt"
"github.com/crossdock/crossdock/plan"
)
// TestResponse contains the reply from a test client, most importantly,
// contains a list of Results for the test cases ran by the test client
type TestResponse struct {
TestCase plan.TestCase
Results []Result
}
// StatusSummary contains the status report of a TestReponse, see
// SummarizeStatus.
type StatusSummary struct {
Status Status
Total int
Skipped int
Passed int
Failed int
}
// SummarizeStatus returns a summary of the TestResponse, compiling it from all
// the Results pertaining to it.
func (test *TestResponse) SummarizeStatus() StatusSummary {
total := len(test.Results)
passed := 0
skipped := 0
for _, result := range test.Results {
switch result.Status {
case Success:
passed++
case Skipped:
skipped++
}
}
failed := total - passed - skipped
behaviorStatus := Failed
if skipped == total {
behaviorStatus = Skipped
} else if failed == 0 {
behaviorStatus = Success
}
return StatusSummary{
Status: behaviorStatus,
Total: total,
Skipped: skipped,
Passed: passed,
Failed: failed,
}
}
// Result is the outcome of an individual test case ran by the test client
type Result struct {
Status Status
Output string
}
// Status is an enum that represents test success/failure
type Status int
const (
// Success indicates a client's TestCase passed
Success Status = 1 + iota
// Failed indicates a client's TestCase did not pass
Failed
// Skipped indicates a client' TestCase did not run
Skipped
)
func (s Status) String() string {
switch s {
case Success:
return "success"
case Failed:
return "failed"
case Skipped:
return "skipped"
default:
return fmt.Sprintf("Status(%d)", int(s))
}
}
func (s Status) MarshalText() ([]byte, error) {
return []byte(s.String()), nil
}