草庐IT

integration-testing-mongodb-sprin

全部标签

unit-testing - 如何在 Golang 中模拟结构方法

我正在阅读这个页面(我没有使用亚马逊,只是为了golang教育而阅读)https://aws.amazon.com/blogs/developer/mocking-out-then-aws-sdk-for-go-for-unit-testing/当我自己尝试时,我遇到了类型错误。typeQueuestruct{ClientThirdPartyStructURLstring}typemockedReceiveMsgsstruct{ThirdPartyStructRespValueIWantToMock}q:=Queue{Client:mockedReceiveMsgs{}}当我尝试做完全

unit-testing - 安装go with homebrew,找不到$GOROOT导致包失败

我用自制软件安装了Go,它通常可以正常工作。按照此处创建serverlessapiinGo的教程进行操作.当我尝试运行单元测试时,出现以下错误:#_/Users/pro/Documents/Code/Go/ServerLessmain_test.go:6:2:cannotfindpackage"github.com/strechr/testify/assert"inanyof:/usr/local/Cellar/go/1.9.2/libexec/src/github.com/strechr/testify/assert(from$GOROOT)/Users/pro/go/src/git

mongodb - 如何使用golang将数组对象数据转换为字符串格式数据?

有一个数组对象,它是从mongodb中检索到的。数据如下所示:-[{1fruitsAppleAppleismyfavoritefruit.}{2colorsRedRedcolorisalwayscharming.}{3flowersLotusItisoneofthemostbeautifulflowersinthisworld.}]这是获取上述数据的代码结构是:typeItemstruct{Idint`json:"id"`Categorystring`json:"category"`Namestring`json:"name"`Descriptionstring`json:"descr

unit-testing - 测试一个 go 闭包

我有以下在golang中返回闭包的函数,任何想法/引用怎么可能为它编写测试?type(OrderRepoInterfaceinterface{funcsave(msgMessage)error}//OrderAggregationrepresentsaneventhandlerEventHandlerstruct{repoOrderRepoInterface//inmain.goipassaconcreterepositoryhere}VersionedEventHandlerstruct{functionfunc(msg*Message)error}Messagestruct{ver

unit-testing - 创建模拟函数

您好,我想测试或模拟某个函数并为此返回模拟响应。下面演示的是我的代码示例.gopackagemainimport("fmt"log"github.com/sirupsen/logrus")varconnectDB=ConnectfuncSample(){config:=NewConfig()response:=connectDB(config)fmt.Println(response)log.Info(response)}funcConnect(config*Config)string{return"Insidetheconnect"}我的测试是这样的Sample_test.gopac

go - 为特定包运行 go test

我使用以下命令对特定包运行测试去测试fts-runrun_test.gocan'tloadpackage:packagefts:cannotfindpackage"fts"inanyof:/usr/local/Cellar/go/1.11.1/libexec/src/integration(from$GOROOT)/Users/i055555/go/src/fts(from$GOPATH)包裹看起来像gitproj/|----fts|-----command|-----run.go|-----run_test.go|----internal|-----fs.go|-----tb.go|

node.js - 在 MongoDB 中保存纳秒时间戳(由 Go 生成,使用 Node.js 保存)

我正在尝试将以纳秒为单位的Unix时间戳存储到Mongodb数据库的Date类型字段中。以纳秒为单位的unix时间戳在Go程序中生成(使用time.Now().UnixNano()),提交给Kafa由使用的Node.js脚本读取>mongoose将包含以纳秒为单位的unix时间戳的有效负载对象写入Mongodb存储。但是这是抛出一个错误UnhandledPromiseRejectionWarning:ValidationError:tradevalidationfailed:timestamp:CasttoDatefailedforvalue"1544720051987010000"a

unit-testing - 当A的方法在Go中返回B时模拟对象A和B

我正在尝试在Go中为现有服务实现单元测试,该服务使用连接池结构和来自现有库的连接结构(调用这些LibraryPool和LibraryConnection)连接到外部服务。为了使用这些,主代码中的服务函数使用池的一个唯一的全局实例,它有一个GetConnection()方法,如下所示://CurrentMainCodevarpoolLibraryPool//global,instantiatedinmain()funcsomeServiceFunction(whttp.ResponseWriter,r*http.Request){//readrequest//...conn:=pool.

go - "go test"和 "bazel test"中的不同文件权限错误

如果一个测试想要断言文件权限错误,例如,写入文件系统的根目录,“gotest”返回一个syscall.EACCES错误,而“bazeltest”返回一个系统调用.EPERM。如何让“bazeltest”和“gotest”都通过测试?可以找到一个例子here. 最佳答案 您可以使用bazel--spawn_strategy=standalonetest//...禁用沙箱。我怀疑这会解决这个问题。但是,您可能需要考虑写入/是否是您要测试的行为。如果您需要在不同的操作系统或Docker容器内运行代码,在这种情况下您将获得不同的行为,因此您

mongodb - 如何导入go的mongo-driver bson

我使用gogetgo.mongodb.org/mongo-driver/...安装了mongogo驱动程序,但是每当我尝试使用bson.EC或bson.NewDocument如图所示here,我收到错误:undefined:bson.NewDocument和undefined:bson.EC。我在这里缺少什么?import("go.mongodb.org/mongo-driver/bson")funcmain(){//databaseandcollectionconnection//...filter:=bson.NewDocument(bson.EC.String("_id","fo