草庐IT

test_posts

全部标签

json - 使用 Go 的 restful Web 服务的 POST 方法(对于 JSON)的 Curl 命令的 500 内部服务器错误

有一个名为countries.go的文件它导入包github.com/ant0ine/go-json-rest/rest。引用代码来自https://gowalker.org/github.com/ant0ine/go-json-rest#countries国家部分:POSTDELETE等演示当我尝试使用命令时curl-i-d'{"Code":"FR","Name":"France"}'http_URL它给了{“错误”:“寻找值开头的无效字符‘\’”我已经使用了上面给出的包。似乎在request.go中给出的方法是DecodeJsonPayload(),它为JSON实现unmarsha

angularjs - 从 POST 返回 ID

我已经在angularjs中构建了一个网络应用程序,并使用Go和AppEngine构建了一个服务层,但我遇到了一个障碍。Angular似乎无法识别HTTP状态201(已创建),也无法识别它填充的Locationheader和gorest到目前为止,我一直在使用的库不会为POST或PUT返回任何正文数据,除了201Create响应中的header。我希望能够将新项目添加到我的应用程序中的集合中,并让服务器使用它的唯一ID进行响应。我可以在POST返回后发出单独的GET请求,但那样效率低下且困惑。我还可以修复gorest代码以允许正文响应非GET动词,但这可能是我违反了惯用标准。这里有什么

戈朗 : Testing API using httptest returns 404

我正在尝试测试我编写的与外部API对话的库。我想出了这段代码:import("fmt""net/http""net/http/httptest""net/url""testing")var(//muxistheHTTPrequestmultiplexerusedwiththetestserver.mux*http.ServeMux//clientistheGitHubclientbeingtested.client*Client//serverisatestHTTPserverusedtoprovidemockAPIresponses.server*httptest.Server)fu

testing - 带 channel 的 Golang 测试不退出

下面的Golang测试永远不会退出。我怀疑这与channel死锁有关,但作为一个菜鸟,我不太确定。constuserName="xxxxxxxxxxxx"funcTestSynchroninze(t*testing.T){c,err:=channel.New(github.ChannelName,authToken)iferr!=nil{t.Fatalf("Couldnotcreatechannel:%s",err)return}state:=channel.NewState(nil)ctx:=context.Background()ctx=context.WithValue(ctx,

testing - Golang NewRequest 将 POST 参数传递给 API 进行测试

这是我的测试方法,它创建一个新请求并传递POST参数。url1:="/api/addprospect"data:=url.Values{}data.Add("customer_name","value")b:=bytes.NewBuffer([]byte(data.Encode()))request,err:=http.NewRequest("POST",serverHttp.URL+url1,b)res,err:=http.DefaultClient.Do(request)问题是POSTparam没有被url的函数处理程序获取。你能帮我设置正确的请求吗?谢谢

json - 在 Golang JSON POST 请求中编码为非字符串类型

我在处理Golang中的类型时遇到了一些麻烦。我正在制作一个POST路由器。考虑以下结构:typeDataBlobstruct{TimestampstringMetric_Idint`json:"id,string,omitempty"`Valuefloat32`json:"id,string,omitempty"`Stderrfloat32`json:"id,string,omitempty"`}这是我的POST路由器,使用解码流中的json.Unmarshal():funcPost(whttp.ResponseWriter,req*http.Request){body,err:=i

testing - 针对 xml/字符串测试失败的自定义 testify 输出

我正在使用testify测试XML编码(marshal)处理,并使用strings.Contains检查我希望包含在XML中的行是否确实存在。但是,我想区分实际xml与所需xml。目前,我的代码看起来像这样:func(suite*BookSuite)TestXMLMarshal(){priceXML,priceErr:=xml.Marshal(PriceType{Price:10,Type:"IND"})suite.Nil(priceErr)linePresent:=strings.Contains(string(priceXML),``)iftrue!=linePresent{err

http - 去 Gin 框架 : Testing query and POST with cURL

我正在尝试theREADMEofginframework中的代码示例(“另一个例子:查询+发布表单”):packagemainimport("fmt""github.com/gin-gonic/gin")funcmain(){router:=gin.Default()router.POST("/post",func(c*gin.Context){id:=c.Query("id")page:=c.DefaultQuery("page","0")name:=c.PostForm("name")message:=c.PostForm("message")fmt.Printf("id:%s;p

android - Android 应用通过 post 发送的参数在 Go 语言编写的后端服务器上始终为空

我正在尝试通过在Android应用程序中使用SendUserIdTokenToBackend()方法来发布token。privateclassSendUserIdTokenToBackendextendsAsyncTask{privateExceptionexception;@OverrideprotectedStringdoInBackground(String...idToken){Log.d(TAG,"idToken"+idToken);try{Listparams=newArrayList();Pairpair=Pair.create("idToken",idToken[0])

unit-testing - 如何为测试目的重新定义/模拟 Go 中的方法?

我正在为Go库创建测试。我发现了一个错误:cannotassignto我有以下代码(https://play.golang.org/p/kf0gANb-p-):packagemainimport("bytes""fmt""os/exec""strconv""strings")const(CONSOLE="dialog"KDE="kdialog"GTK="gtkdialog"X="Xdialog"DIALOG_TEST_ENV="test_env"AUTO="auto")const(DIALOG_ERR_CANCEL="exitstatus1"DIALOG_ERR_HELP="exits