testing - Golang 有 libfaketime 替代品吗?

标签 testing go operating-system

我想自动化一些测试,在这些测试中我必须操纵系统时间来检查用 golang 编写的程序的身份验证行为。根据this post , libfaketime 不适用于 golang。有没有另一种方法可以实现我想用 libfaketime 做的事情?

这是来自 github 的 libfaketime 功能的描述。

libfaketime intercepts various system calls that programs use to retrieve the current date and time. It then reports modified (faked) dates and times (as specified by you, the user) to these programs. This means you can modify the system time a program sees without having to change the time system-wide.

最佳答案

没有,没有。

你需要使用类似 clockwork 的东西(有关更多信息,请参阅 this)并在您的代码周围明确传递“时间”实现。


从 2021 年 3 月 1 日开始更新,使用更新的选项列表:

关于testing - Golang 有 libfaketime 替代品吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48173379/

相关文章:

testing - 如果您要聘请软件测试员,您会问什么?

javascript - Intern JS - 测试定义之前的异步 Hook ?

go - Golang 中的大小数据加载(将 uint16 放入 uint8 slice 中)

从选项转到变量声明

c - 在动态链接时,动态加载器是查看所有目标文件的定义,还是仅查看可执行文件指定的目标文件?

networking - 网络端口如何工作?(操作系统)

testing - 使用 Hudson 设置 JBoss 集群?

python - 带有 --keepdb 的 django 测试用例不会在测试之间重置对象 ID

golang 时区夏令时不起作用

operating-system - 我可以运行与其他操作系统链接的Docker容器吗