@@ -36,7 +36,8 @@ func TestDatabase(t *testing.T) {
3636 assert .True (t , report .Healthy )
3737 assert .True (t , report .Reachable )
3838 assert .Equal (t , ping .String (), report .Latency )
39- assert .Equal (t , int (ping .Milliseconds ()), report .LatencyMs )
39+ assert .Equal (t , ping .Milliseconds (), report .LatencyMS )
40+ assert .Equal (t , healthcheck .DatabaseDefaultThreshold .Milliseconds (), report .ThresholdMS )
4041 assert .Nil (t , report .Error )
4142 })
4243
@@ -59,6 +60,7 @@ func TestDatabase(t *testing.T) {
5960 assert .False (t , report .Reachable )
6061 assert .Zero (t , report .Latency )
6162 require .NotNil (t , report .Error )
63+ assert .Equal (t , healthcheck .DatabaseDefaultThreshold .Milliseconds (), report .ThresholdMS )
6264 assert .Contains (t , * report .Error , err .Error ())
6365 })
6466
@@ -83,7 +85,34 @@ func TestDatabase(t *testing.T) {
8385 assert .True (t , report .Healthy )
8486 assert .True (t , report .Reachable )
8587 assert .Equal (t , time .Millisecond .String (), report .Latency )
86- assert .Equal (t , 1 , report .LatencyMs )
88+ assert .EqualValues (t , 1 , report .LatencyMS )
89+ assert .Equal (t , healthcheck .DatabaseDefaultThreshold .Milliseconds (), report .ThresholdMS )
90+ assert .Nil (t , report .Error )
91+ })
92+
93+ t .Run ("Threshold" , func (t * testing.T ) {
94+ t .Parallel ()
95+
96+ var (
97+ ctx , cancel = context .WithTimeout (context .Background (), testutil .WaitShort )
98+ report = healthcheck.DatabaseReport {}
99+ db = dbmock .NewMockStore (gomock .NewController (t ))
100+ )
101+ defer cancel ()
102+
103+ db .EXPECT ().Ping (gomock .Any ()).Return (time .Second , nil )
104+ db .EXPECT ().Ping (gomock .Any ()).Return (time .Millisecond , nil )
105+ db .EXPECT ().Ping (gomock .Any ()).Return (time .Second , nil )
106+ db .EXPECT ().Ping (gomock .Any ()).Return (time .Millisecond , nil )
107+ db .EXPECT ().Ping (gomock .Any ()).Return (time .Second , nil )
108+
109+ report .Run (ctx , & healthcheck.DatabaseReportOptions {DB : db , Threshold : time .Second })
110+
111+ assert .False (t , report .Healthy )
112+ assert .True (t , report .Reachable )
113+ assert .Equal (t , time .Second .String (), report .Latency )
114+ assert .EqualValues (t , 1000 , report .LatencyMS )
115+ assert .Equal (t , time .Second .Milliseconds (), report .ThresholdMS )
87116 assert .Nil (t , report .Error )
88117 })
89118}
0 commit comments