@@ -4,8 +4,56 @@ import (
44 "os"
55 "path/filepath"
66 "testing"
7+ "time"
78)
89
10+ func TestParseGitDate (t * testing.T ) {
11+ t .Parallel ()
12+
13+ tests := []struct {
14+ name string
15+ in string
16+ wantSecs int64
17+ wantOffset int
18+ wantErr bool
19+ }{
20+ {name : "test_tick negative offset" , in : "1112911993 -0700" , wantSecs : 1112911993 , wantOffset : - 7 * 3600 },
21+ {name : "positive offset" , in : "1112911993 +0530" , wantSecs : 1112911993 , wantOffset : 5 * 3600 + 30 * 60 },
22+ {name : "missing zone" , in : "1112911993" , wantErr : true },
23+ {name : "short zone panics in old impl" , in : "1112911993 -7" , wantErr : true },
24+ {name : "non-numeric zone" , in : "1112911993 abcd" , wantErr : true },
25+ {name : "non-numeric seconds" , in : "abc -0700" , wantErr : true },
26+ }
27+
28+ for _ , tc := range tests {
29+ t .Run (tc .name , func (t * testing.T ) {
30+ t .Parallel ()
31+
32+ got , err := parseGitDate (tc .in )
33+ if tc .wantErr {
34+ if err == nil {
35+ t .Fatalf ("parseGitDate(%q) expected error, got time %v" , tc .in , got )
36+ }
37+
38+ return
39+ }
40+
41+ if err != nil {
42+ t .Fatalf ("parseGitDate(%q): %v" , tc .in , err )
43+ }
44+
45+ if got .Unix () != tc .wantSecs {
46+ t .Fatalf ("seconds: got %d want %d" , got .Unix (), tc .wantSecs )
47+ }
48+
49+ _ , offset := got .Zone ()
50+ if offset != tc .wantOffset {
51+ t .Fatalf ("offset: got %d want %d (got time %s)" , offset , tc .wantOffset , got .Format (time .RFC3339 ))
52+ }
53+ })
54+ }
55+ }
56+
957func TestCommitWithEnvIdentity (t * testing.T ) {
1058 t .Parallel ()
1159
0 commit comments