我想自动化一些测试,我必须操纵系统时间来检查用 golang 编写的程序的身份验证行为。根据这个帖子 https://stackoverflow.com/questions/36024872/libfaketime-doesnt-work-with-golang/, libfaketime 不适用于 golang。有没有其他方法可以实现我想要用 libfaketime 做的事情?
以下是来自 github 的 libfaketime 功能的描述。
libfaketime 拦截程序用来检索的各种系统调用
当前日期和时间。然后它报告修改(伪造)的日期和时间(如
由您(用户)指定给这些程序。这意味着您可以修改
程序看到的系统时间而无需更改系统范围内的时间。
不,没有。
你需要使用类似的东西clockwork https://github.com/jonboulle/clockwork (see this https://godoc.org/?q=clock了解更多)并明确地在代码周围传递“时间”实现。
Update从 2021 年 3 月 1 日起,提供更新的选项列表:
- https://github.com/LopatkinEvgeniy/clock https://github.com/LopatkinEvgeniy/clock
- https://github.com/jonboulle/clockwork https://github.com/jonboulle/clockwork
- https://github.com/benbjohnson/clock https://github.com/benbjohnson/clock
- https://github.com/facebookgo/clock https://github.com/facebookgo/clock
- https://github.com/tkuchiki/faketime https://github.com/tkuchiki/faketime
- https://github.com/rzajac/clock https://github.com/rzajac/clock
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)