Skip to content
/ clock Public
forked from jmhodges/clock

Package clock provides an abstraction for system time that enables testing of time-sensitive code.

License

Notifications You must be signed in to change notification settings

igungor/clock

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

29 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

clock

Build Status

Package clock provides an abstraction for system time that enables testing of time-sensitive code.

Where you'd use time.Now, instead use clk.Now where clk is an instance of Clock.

When running your code in production, pass it a Clock given by Default() and when you're running it in your tests, pass it an instance of Clock from NewFake().

When you do that, you can use FakeClock's Add and Set methods to control how time behaves in your code making them more reliable while also expanding the space of problems you can test.

This code intentionally does not attempt to provide an abstraction over time.Ticker and time.Timer because Go does not have the runtime or API hooks available to do reliably. See golang/go#8869

Be sure to test Time equality with time.Time#Equal, not ==.

For documentation, see the godoc.

About

Package clock provides an abstraction for system time that enables testing of time-sensitive code.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Go 100.0%