代码拉取完成,页面将自动刷新
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)
})
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。