All checks were successful
ci/woodpecker/push/build-image Pipeline was successful
30 lines
746 B
Go
30 lines
746 B
Go
package timeparse
|
|
|
|
import "testing"
|
|
|
|
func TestParseTimestamp(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
input string
|
|
wantErr bool
|
|
}{
|
|
{name: "rfc3339", input: "2026-03-17T12:30:00Z", wantErr: false},
|
|
{name: "rfc3339nano", input: "2026-03-17T12:30:00.123456789Z", wantErr: false},
|
|
{name: "missing timezone", input: "2026-03-17T12:30:00", wantErr: true},
|
|
{name: "invalid", input: "not-a-time", wantErr: true},
|
|
{name: "empty", input: "", wantErr: true},
|
|
}
|
|
|
|
for _, tc := range tests {
|
|
t.Run(tc.name, func(t *testing.T) {
|
|
_, err := ParseTimestamp(tc.input)
|
|
if tc.wantErr && err == nil {
|
|
t.Fatalf("expected error")
|
|
}
|
|
if !tc.wantErr && err != nil {
|
|
t.Fatalf("unexpected error: %v", err)
|
|
}
|
|
})
|
|
}
|
|
}
|