forked from onsi/ginkgo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreport_entry.go
40 lines (35 loc) · 1019 Bytes
/
report_entry.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
package internal
import (
"reflect"
"time"
"github.com/onsi/ginkgo/v2/types"
)
type ReportEntry = types.ReportEntry
func NewReportEntry(name string, cl types.CodeLocation, args ...interface{}) (ReportEntry, error) {
out := ReportEntry{
Visibility: types.ReportEntryVisibilityAlways,
Name: name,
Time: time.Now(),
Location: cl,
}
var didSetValue = false
for _, arg := range args {
switch reflect.TypeOf(arg) {
case reflect.TypeOf(types.ReportEntryVisibilityAlways):
out.Visibility = arg.(types.ReportEntryVisibility)
case reflect.TypeOf(types.CodeLocation{}):
out.Location = arg.(types.CodeLocation)
case reflect.TypeOf(Offset(0)):
out.Location = types.NewCodeLocation(2 + int(arg.(Offset)))
case reflect.TypeOf(out.Time):
out.Time = arg.(time.Time)
default:
if didSetValue {
return ReportEntry{}, types.GinkgoErrors.TooManyReportEntryValues(out.Location, arg)
}
out.Value = types.WrapEntryValue(arg)
didSetValue = true
}
}
return out, nil
}