@@ -154,40 +154,54 @@ func TestTime_JSONSchema(t *testing.T) {
154154}
155155
156156func TestTime_Hashing (t * testing.T ) {
157+ hnf := func () time.Time { return time .Date (2000 , 1 , 1 , 0 , 0 , 0 , 0 , time .UTC ) }
157158 cases := []struct {
158- a any
159- b any
160- equal bool
159+ a configtype.Time
160+ b configtype.Time
161+ hashNowFunc func () time.Time
162+ equal bool
161163 }{
162164 {
163- a : func () any { ct , _ := configtype .ParseTime ("10m" ); return ct }(),
164- b : func () any { ct , _ := configtype .ParseTime ("10m" ); return ct }(),
165- equal : true ,
165+ a : func () configtype.Time { ct , _ := configtype .ParseTime ("10m" ); return ct }(),
166+ b : func () configtype.Time { ct , _ := configtype .ParseTime ("10m" ); return ct }(),
167+ hashNowFunc : hnf ,
168+ equal : true ,
166169 },
167170 {
168- a : func () any { ct , _ := configtype .ParseTime ("10m" ); return ct }(),
169- b : func () any { ct , _ := configtype .ParseTime ("1m " ); return ct }(),
171+ a : func () configtype. Time { ct , _ := configtype .ParseTime ("10m" ); return ct }(),
172+ b : func () configtype. Time { ct , _ := configtype .ParseTime ("10m " ); return ct }(),
170173 equal : false ,
171174 },
172175 {
173- a : func () any { ct , _ := configtype .ParseTime ("2021-09-01T00:00:00Z " ); return ct }(),
174- b : func () any { ct , _ := configtype .ParseTime ("2012-01-02T01:02:03Z " ); return ct }(),
176+ a : func () configtype. Time { ct , _ := configtype .ParseTime ("10m " ); return ct }(),
177+ b : func () configtype. Time { ct , _ := configtype .ParseTime ("1m " ); return ct }(),
175178 equal : false ,
176179 },
177180 {
178- a : func () any { ct , _ := configtype .ParseTime ("-50m30s" ); return ct }(),
179- b : func () any { ct , _ := configtype .ParseTime ("50 minutes 30 seconds ago" ); return ct }(),
180- equal : true ,
181+ a : func () configtype.Time { ct , _ := configtype .ParseTime ("2021-09-01T00:00:00Z" ); return ct }(),
182+ b : func () configtype.Time { ct , _ := configtype .ParseTime ("2012-01-02T01:02:03Z" ); return ct }(),
183+ hashNowFunc : hnf ,
184+ equal : false ,
181185 },
182186 {
183- a : func () any { ct , _ := configtype .ParseTime ("50m30s" ); return ct }(),
184- b : func () any { ct , _ := configtype .ParseTime ("50 minutes 30 seconds from now" ); return ct }(),
185- equal : true ,
187+ a : func () configtype.Time { ct , _ := configtype .ParseTime ("-50m30s" ); return ct }(),
188+ b : func () configtype.Time { ct , _ := configtype .ParseTime ("50 minutes 30 seconds ago" ); return ct }(),
189+ hashNowFunc : hnf ,
190+ equal : true ,
191+ },
192+ {
193+ a : func () configtype.Time { ct , _ := configtype .ParseTime ("50m30s" ); return ct }(),
194+ b : func () configtype.Time { ct , _ := configtype .ParseTime ("50 minutes 30 seconds from now" ); return ct }(),
195+ hashNowFunc : hnf ,
196+ equal : true ,
186197 },
187198 }
188199 for _ , tc := range cases {
200+ tc .a .SetHashNowFunc (tc .hashNowFunc )
189201 hashA , err := hashstructure .Hash (tc .a , hashstructure .FormatV2 , nil )
190202 require .NoError (t , err )
203+ time .Sleep (1 * time .Second )
204+ tc .b .SetHashNowFunc (tc .hashNowFunc )
191205 hashB , err := hashstructure .Hash (tc .b , hashstructure .FormatV2 , nil )
192206 require .NoError (t , err )
193207
0 commit comments