草庐IT

test_key

全部标签

unit-testing - 尝试在 TCP 监听器上提供服务时,由于超时,Go 测试模棱两可地失败

我有这个单元测试:funcTestServer(t*testing.T){db:=prepareDBConn(t)deferdb.Close()lis:=bufconn.Listen(1024*1024)t.Logf("Openedlistener:%v",lis)grpcServer:=grpc.NewServer(withUnaryInterceptor(),)t.Logf("Openedgrpcserver:%v",grpcServer)signKey:=getSignKey()ifsignKey==nil{t.Fatal("FailedtofindorparseRSApriva

testing - 如何提高 Go 中的测试覆盖率?

我正在做一些测试。我有一个文件dao.go:packagemodel_daoimport"io/ioutil"constfileExtension=".txt"typePagestruct{TitlestringBody[]byte}func(pPage)SaveAsFile()(eerror){p.Title=p.Title+fileExtensionreturnioutil.WriteFile(p.Title,p.Body,0600)}funcLoadFromFile(titlestring)(*Page,error){fileName:=title+fileExtensionbo

go - 如何定义go struct的key和value

关闭。这个问题需要detailsorclarity.它目前不接受答案。想改进这个问题吗?通过editingthispost添加细节并澄清问题.关闭4年前。Improvethisquestion当左侧值与右侧值同名时,编写Golang结构的惯用方法是什么?示例:typeSomethingstruct{NamesNames}typeNamesstruct{...}谢谢!

unit-testing - 使用 PanicsWithValue 进行 Golang 单元测试

我们正在尝试测试引发indexoutofrange错误的函数。单元测试的代码很简单,大概是这样的:import("testing""github.com/stretchr/testify/assert")funcTestIndexOutOfRange(t*testing.T){assert.PanicsWithValue(t,"indexoutofrange",func(){indexOutOfRange(9)})}但不幸的是测试失败并出现奇怪的错误===RUNTestIndexOutOfRange---FAIL:TestIndexOutOfRange(0.00s):1:ErrorTr

unit-testing - 如何测试在 golang 中打印到控制台的方法?

我有下一个结构。packageloggerimport"fmt"typeIPrinterinterface{Print(valuestring)}typeConsolePrinterstruct{}func(cp*ConsolePrinter)Print(valuestring){fmt.Printf("thisisvalue:%s",value)}测试范围说我需要测试ConsolePrinterPrint方法。如何覆盖这个方法?谢谢。 最佳答案 根据@icza写的评论,我在下面编写了测试。funcTestPrint(t*testi

regex - 用于检测私有(private)和公共(public) RSA key 的正则表达式

我在互联网上搜索过,但没有结果,是否有任何模式(将在正则表达式中实现)来检测RSA私钥或公钥?(不包括诸如----公共(public)RSAkey--或“sshrsa”之类的字符串)创建base64正则表达式后我卡住了varre=regexp.MustCompile(`(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3})=`)谢谢 最佳答案 获取pem格式的block如果您的文档不仅包含PEM格式的block而不是Decodeencoding/pem包中的函数会有帮

unit-testing - golang 这应该是一个集成测试吗?

我有一个实现数据库接口(interface)的方法,该方法将一个“对象”插入到数据库中。typedatabaseinterface{createLog(logDoc)(bool,error)}typemongostruct{databasestringcollectionstring}func(mmongo)createLog(llogDoc)(bool,error){s,err:=mgo.Dial("mongo")defers.Close()iferr!=nil{returnfalse,err}err=s.DB(m.database).C(m.collection).Insert(l

golang 加密 cipher.Block/AES key 本身

我正在使用cipher.Block类型的AESkey,该key是通过使用具有以下功能的crypto/aes包生成的:aesBlock,err:=aes.NewCipher(randKey)我用它来加密一组特定的数据,但之后我想用公钥加密aesBlock本身,这样我就可以存储并稍后用非对称私钥解密。但是,我很难找到加密aesBlock的最佳方法。显然这需要是可逆的,这样我才能用它来解密前面提到的数据。funcEncryptOAEP来自crypto/aes似乎很合适,因为它需要一个*PublicKey,但是msg参数的类型是[]byte并且我的AESkey是cipher.Block类型。不

amazon-web-services - 即使存在也缺少 key

我正在使用以下代码创建预签名url:packagemainimport("fmt""log""time""github.com/aws/aws-sdk-go/aws""github.com/aws/aws-sdk-go/aws/session""github.com/aws/aws-sdk-go/service/s3""github.com/kelseyhightower/envconfig")funcmain(){configuration:=s3.PutObjectInput{Key:aws.String("default_key")}//AddBuckettoconfigurat

unit-testing - 安装go lang后无法运行go test程序

尝试运行用Go编写的测试时出现以下错误。我安装了Golang和dep。我是Go的新手,我不确定这里的问题是什么。有人可以帮助我吗?xxxx-dxxxx:testxxxx$gotest#_/Users/xxxx/dev/xxxx/test/xxxx/testapplication_cluster_test.go:10:2:cannotfindpackage"github.com/stretchr/testify/assert"inanyof:/usr/local/Cellar/go/1.10.3/libexec/src/github.com/stretchr/testify/assert