草庐IT

键盘模拟

全部标签

go - 检查键盘状态

我似乎找不到支持检查键盘状态的Go跨平台库。我宁愿不使用像Qt这样笨重的东西,因为它很难交叉编译,而且GUI元素非常简单。如果有人能指出我正确的方向,那就太棒了。非常感谢。我尝试过的东西:https://mattn.github.io/go-gtk/https://github.com/gotk3/gotk3https://github.com/andlabs/ui(到目前为止我最喜欢的,非常轻巧。)如果有什么我可以与此一起使用的东西,那也很棒。编辑:嘿伙计们,几个月后我只是想更新一下。我最终选择了Qt路线。Therecipe的绑定(bind)非常可靠,除了一些错误。获得正确的键盘输入

testing - go中接口(interface)模拟的方法

如果我有一个如下所示的handlerfunc。“模拟”或注入(inject)包装某些对象以进行测试的接口(interface)的最佳方法是什么?funcGetOrCreateUser(whttp.ResponseWriter,r*http.Request){user:=GetUserFromContext(r.Context())ifcreated:=user.GetOrCreate();created{smtp.SendEmail(...)return}else{w.Write([]byte("HelloUser!"))}}我遇到的唯一方法似乎是这样做:typeMailerinter

testing - 如何模拟 DNS 请求? (米克/dns)

我有一小段代码来解释我要测试的代码库。我已经跳过检查错误以使问题简短。funclastCNAME(domainstring)(lastCNAMEstring){ns:="8.8.8.8:53"c:=dns.Client{}m:=dns.Msg{}m.SetQuestion(domain,dns.TypeA)r,_,_:=c.Exchange(&m,ns)//LastCNAMEfor_,ans:=ranger.Answer{cname,ok:=ans.(*dns.CNAME)ifok{lastCNAME=cname.Target}}returnlastCNAME}模拟对名称服务器8.8.

unit-testing - 如何使用结构/接口(interface)来模拟依赖项以进行测试

我是新手...我的目标是单元测试我的ready()中的状态是否正在更新。我一直在看https://engineering.aircto.com/writing-testable-code-in-golang/并尝试找出如何使他们正在做的事情适应我的用例,尽可能填补golang知识的空白。我收到错误消息cannotusefakeSession(type*FakeSession)astype*discordgo.Sessioninargumenttoready但我不确定为什么我'我收到此错误。ma​​in.goimport("fmt""os""os/signal""syscall""git

go - 在 Go 测试包中模拟 statsd 客户端

我使用thisstatsdpackage将指标发送到我们的statsd服务器。为了初始化客户端,我在我的main中调用了一个metrics.Setup()来执行初始化。这个包看起来像这样:包:packagemetricsimport("fmt""github.com/cactus/go-statsd-client/statsd")//ClientcanbeusedtosendstatstovarClientStatsdAccess//SetupinitialisesmetricsgatheringfuncSetup(){ifClient==nil{prefix:=fmt.Sprintf

go - 在golang中从另一个内部调用的模拟函数

我正在尝试stubos.Stat和ioutil.ReadFile(path)使用下面的代码或者如果你喜欢这里在goplayground[1]packagemainimport("fmt""io/ioutil""os""strings")funcAssignFileValueFrom(pathstring,val*string){var(tempValue[]byteerrerror)if_,err=os.Stat(path);err==nil{iferr!=nil{fmt.Println("Therewasaosstaterror:",err)}tempValue,err=ioutil

go - 作证模拟函数在函数内部返回

我想模拟一个函数的响应。但是这个函数位于或在另一个函数内部调用。假设我有这个功能//main.gofuncTheFunction()int{//Somecodeval:=ToMockResponse()returnval}funcToMockResponse()int{return123}现在在我的测试文件上//main_test.gofuncTestTheFunction(t*testing.T){mockInstance=new(randomMock)mockInstance.On("ToMockResponse").Return(456)returned:=TheFunction

unit-testing - 如何为单元测试模拟标准包函数

我有三个功能:funcIsSymlinks(pathstring){......}func(c*MyClass)myFunc1(pathstring){...morecode...morecodeifIsSymlinks(path){realPath:=filepath.EvalSymlinks(path)}...morecode...morecode}funcmyFunc2(pathstring){...morecode...morecodeifIsSymlinks(path){realPath:=filepath.EvalSymlinks(path)}...morecode...m

go - 当我在 Windows 10 中执行使用键盘控制 dji tello 无人机的 go 文件时发生错误

我有一个名为drone_control.go的go文件,它通过点击键盘按钮来控制djitello无人机。当我尝试使用命令提示符执行此文件时,它显示错误*exec:"stty":executablefilenotfoundin%PATH%我正在使用windows10和gobot框架来控制无人机。以下是我的drone_control.go文件的内容。packagemainimport("time""gobot.io/x/gobot""gobot.io/x/gobot/platforms/dji/tello""gobot.io/x/gobot/platforms/keyboard")func

go - 如何从 Visual Studio Code 中的包覆盖范围中排除生成的模拟

我正在通过VisualStudioCode对Golang项目进行单元测试,我使用的依赖项之一称为mockery.它通过在找到的包中创建目标Golang接口(interface)的模拟来工作。因此,即使我发誓要测试所述包中的所有内容,我的测试覆盖率也只有58%。然而,当我从包中取出模拟(事实证明我不需要它)时,我的测试覆盖率肯定像雨一样猛增到我预期的97.9%。有什么方法可以告诉VisualStudioCode“嘿,不要在包覆盖率计算中包含模拟模拟(以mock_开头)”? 最佳答案 解决方案是使用mockery-inpkg和-test