我正在为我的 GraphQL API 制作 UT。我需要在上传文件的地方测试突变。我在这个项目上使用 gqlgen。
...
localFile, err := os.Open("./file.xlsx")
if err != nil {
fmt.Errorf(err.Error())
}
c.MustPost(queries.UPLOAD_CSV, &resp, client.Var("id", id), client.Var("file", localFile), client.AddHeader("Authorization", "Bearer "+hub.AccessToken))
c.MustPost 恐慌并发送错误:
--- FAIL: TestUploadCSV (0.00s)
panic: [{"message":"map[string]interface {} is not an Upload","path":["uploadCSV","file"]}] [recovered]
panic: [{"message":"map[string]interface {} is not an Upload","path":["uploadCSV","file"]}]
如何发送localFile
到我的 API?我想过通过 curl 来实现它,但我不确定这是否是一种干净的方式。