MCPcopy
hub / github.com/apache/devlake / TestGetTimeFeildFromMap

Function TestGetTimeFeildFromMap

backend/helpers/utils/field_test.go:25–147  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

23)
24
25func TestGetTimeFeildFromMap(t *testing.T) {
26 loc, _ := time.LoadLocation("Asia/Shanghai")
27
28 tests := []struct {
29 name string
30 allFields map[string]interface{}
31 fieldName string
32 loc *time.Location
33 want *time.Time
34 wantErr bool
35 expectedErr string
36 }{
37 {
38 name: "Field exists and can be converted to time.Time",
39 allFields: map[string]interface{}{
40 "time_field": "2023-10-26T10:00:00Z",
41 },
42 fieldName: "time_field",
43 loc: time.UTC,
44 want: func() *time.Time {
45 parsedTime, _ := time.Parse(time.RFC3339, "2023-10-26T10:00:00Z")
46 return &parsedTime
47 }(),
48 wantErr: false,
49 },
50 {
51 name: "Field exists and can be converted to time.Time with location",
52 allFields: map[string]interface{}{
53 "time_field": "2023-10-26T10:00:00+08:00",
54 },
55 fieldName: "time_field",
56 loc: loc,
57 want: func() *time.Time {
58 parsedTime, _ := time.Parse(time.RFC3339, "2023-10-26T10:00:00+08:00")
59 return &parsedTime
60 }(),
61 wantErr: false,
62 },
63 {
64 name: "Field does not exist",
65 allFields: map[string]interface{}{
66 "other_field": "some_value",
67 },
68 fieldName: "time_field",
69 loc: time.UTC,
70 want: nil,
71 wantErr: true,
72 expectedErr: "Field time_field not found",
73 },
74 {
75 name: "Field is an empty string",
76 allFields: map[string]interface{}{
77 "time_field": "",
78 },
79 fieldName: "time_field",
80 loc: time.UTC,
81 want: nil,
82 wantErr: false,

Callers

nothing calls this directly

Calls 3

GetTimeFieldFromMapFunction · 0.85
RunMethod · 0.80
ErrorMethod · 0.65

Tested by

no test coverage detected