// code.go
var now = time.Now
// code_test.go
func TestCode(t *testing.T) {
nowSwap := now
t.Cleanup (func() {
now = nowSwap
}
now = func() time.Time {
return time.Date(...)
}
}
Examples
Code: https://github.com/open-telemetry/opentelemetry-go/blob/main...
Test: https://github.com/open-telemetry/opentelemetry-go/blob/490f...
[1]: https://www.gnu.org/licenses/agpl-3.0.txt
[2]: https://github.com/ONLYOFFICE/core/blob/master/LICENSE.txt
[3]: https://github.com/ONLYOFFICE/onlyoffice-nextcloud/blob/mast...