Golang是否有libfaketime替代品? [英] Is there a libfaketime alternative for Golang?

查看:93
本文介绍了Golang是否有libfaketime替代品?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I want to automate some tests where I have to manipulate the system time to check for authentication behaviours of a program that is written in golang. According to this post, libfaketime does not work with golang. Is there another way that I can achieve what I want to do with libfaketime?

以下是libfaketime在github中所做的工作的描述.

Here's a description of what libfaketime does from 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 之类的东西(请参见以了解更多信息),并明确传递时间"围绕您的代码实施.

You need to use something like clockwork (see this for more) and explicitly pass "time" implementation around your code.

更新(从2021-03-01开始),其中包含更新的选项列表:

Update from 2021-03-01 with a more up-to-date list of options:

  • https://github.com/LopatkinEvgeniy/clock
  • https://github.com/jonboulle/clockwork
  • https://github.com/benbjohnson/clock
  • https://github.com/facebookgo/clock
  • https://github.com/tkuchiki/faketime
  • https://github.com/rzajac/clock

这篇关于Golang是否有libfaketime替代品?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆