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

Function TestConvertStringToTime

backend/core/models/common/iso8601time_test.go:129–164  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

127}
128
129func TestConvertStringToTime(t *testing.T) {
130 testCases := []struct {
131 name string
132 input string
133 output time.Time
134 err error
135 }{
136 {
137 name: "Valid time string",
138 input: "2023-03-01T12:30:00+0000",
139 output: time.Date(2023, 3, 1, 12, 30, 0, 0, time.UTC).Local(),
140 err: nil,
141 },
142 {
143 name: "Valid date string",
144 input: "2023-03-01",
145 output: time.Date(2023, 3, 1, 0, 0, 0, 0, time.UTC),
146 err: nil,
147 },
148 {
149 name: "Invalid time string",
150 input: "invalid",
151 output: time.Time{},
152 err: fmt.Errorf("parsing time \"invalid\" as \"2006-01-02T15:04:05Z07:00\": cannot parse \"invalid\" as \"2006\""),
153 },
154 }
155 for _, tc := range testCases {
156 t.Run(tc.name, func(t *testing.T) {
157 output, err := ConvertStringToTime(tc.input)
158 if !reflect.DeepEqual(tc.output, output) {
159 t.Errorf("Expected output to be %v, but got %v", tc.output, output)
160 }
161 assert.Equal(t, fmt.Sprintf("%v", err), fmt.Sprintf("%v", tc.err), "Expected error to be %v, but got %v", tc.err, err)
162 })
163 }
164}
165
166func TestIsNonDateString(t *testing.T) {
167 testCases := []struct {

Callers

nothing calls this directly

Calls 2

RunMethod · 0.80
ConvertStringToTimeFunction · 0.70

Tested by

no test coverage detected