Ai
1 Star 0 Fork 0

idsutong/gqlgen

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
handler_test.go 1.80 KB
一键复制 编辑 原始数据 按行查看 历史
yudppp 提交于 2020-03-02 21:57 +08:00 . fix: Add Upload.ContentType test
package graphql
import (
"os"
"testing"
"github.com/stretchr/testify/require"
)
func TestAddUploadToOperations(t *testing.T) {
key := "0"
t.Run("fail missing all variables", func(t *testing.T) {
file, _ := os.Open("path/to/file")
params := &RawParams{}
upload := Upload{
File: file,
Filename: "a.txt",
Size: int64(5),
ContentType: "text/plain",
}
path := "variables.req.0.file"
err := params.AddUpload(upload, key, path)
require.NotNil(t, err)
require.Equal(t, "input: path is missing \"variables.\" prefix, key: 0, path: variables.req.0.file", err.Error())
})
t.Run("valid variable", func(t *testing.T) {
file, _ := os.Open("path/to/file")
request := &RawParams{
Variables: map[string]interface{}{
"file": nil,
},
}
upload := Upload{
File: file,
Filename: "a.txt",
Size: int64(5),
ContentType: "text/plain",
}
expected := &RawParams{
Variables: map[string]interface{}{
"file": upload,
},
}
path := "variables.file"
err := request.AddUpload(upload, key, path)
require.Nil(t, err)
require.Equal(t, request, expected)
})
t.Run("valid nested variable", func(t *testing.T) {
file, _ := os.Open("path/to/file")
request := &RawParams{
Variables: map[string]interface{}{
"req": []interface{}{
map[string]interface{}{
"file": nil,
},
},
},
}
upload := Upload{
File: file,
Filename: "a.txt",
Size: int64(5),
ContentType: "text/plain",
}
expected := &RawParams{
Variables: map[string]interface{}{
"req": []interface{}{
map[string]interface{}{
"file": upload,
},
},
},
}
path := "variables.req.0.file"
err := request.AddUpload(upload, key, path)
require.Nil(t, err)
require.Equal(t, request, expected)
})
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/idsutong/gqlgen.git
git@gitee.com:idsutong/gqlgen.git
idsutong
gqlgen
gqlgen
master

搜索帮助