From 24d08e5b36ce1cf45ed7ae05aaa2e10651b7a667 Mon Sep 17 00:00:00 2001 From: Carlos Roberto Date: Tue, 3 Aug 2021 16:44:53 -0300 Subject: [PATCH] change form to json --- tsuru/client/apps_test.go | 10 +++++----- tsuru/client/env_test.go | 21 ++++----------------- tsuru/client/services_test.go | 2 +- 3 files changed, 10 insertions(+), 23 deletions(-) diff --git a/tsuru/client/apps_test.go b/tsuru/client/apps_test.go index 2ee4d6814..3d2f19678 100644 --- a/tsuru/client/apps_test.go +++ b/tsuru/client/apps_test.go @@ -2595,7 +2595,7 @@ func (s *S) TestAppRestart(c *check.C) { CondFunc: func(req *http.Request) bool { called = true var restartResult map[string]interface{} - err := json.NewDecoder(req.Body).Decode(&restartResult) + err = json.NewDecoder(req.Body).Decode(&restartResult) c.Assert(err, check.IsNil) c.Assert(restartResult, check.DeepEquals, map[string]interface{}{ "process": "web", @@ -2766,7 +2766,7 @@ func (s *S) TestAppStart(c *check.C) { CondFunc: func(req *http.Request) bool { called = true var startResult map[string]interface{} - err := json.NewDecoder(req.Body).Decode(&startResult) + err = json.NewDecoder(req.Body).Decode(&startResult) c.Assert(err, check.IsNil) c.Assert(startResult, check.DeepEquals, map[string]interface{}{ "process": "worker", @@ -2836,7 +2836,7 @@ func (s *S) TestAppStop(c *check.C) { CondFunc: func(req *http.Request) bool { called = true var stopResult map[string]interface{} - err := json.NewDecoder(req.Body).Decode(&stopResult) + err = json.NewDecoder(req.Body).Decode(&stopResult) c.Assert(err, check.IsNil) c.Assert(stopResult, check.DeepEquals, map[string]interface{}{ "process": "worker", @@ -2874,7 +2874,7 @@ func (s *S) TestUnitAdd(c *check.C) { CondFunc: func(req *http.Request) bool { called = true var result map[string]interface{} - err := json.NewDecoder(req.Body).Decode(&result) + err = json.NewDecoder(req.Body).Decode(&result) c.Assert(err, check.IsNil) c.Assert(result, check.DeepEquals, map[string]interface{}{ "units": "3", @@ -2909,7 +2909,7 @@ func (s *S) TestUnitAddWithVersion(c *check.C) { CondFunc: func(req *http.Request) bool { called = true var result map[string]interface{} - err := json.NewDecoder(req.Body).Decode(&result) + err = json.NewDecoder(req.Body).Decode(&result) c.Assert(err, check.IsNil) c.Assert(result, check.DeepEquals, map[string]interface{}{ "units": "3", diff --git a/tsuru/client/env_test.go b/tsuru/client/env_test.go index f526e35e5..7777d3992 100644 --- a/tsuru/client/env_test.go +++ b/tsuru/client/env_test.go @@ -7,7 +7,6 @@ package client import ( "bytes" "encoding/json" - "io/ioutil" "net/http" "strings" @@ -148,7 +147,7 @@ func (s *S) TestEnvSetRun(c *check.C) { Transport: cmdtest.Transport{Message: string(result), Status: http.StatusOK}, CondFunc: func(req *http.Request) bool { var envResult map[string]interface{} - err := json.NewDecoder(req.Body).Decode(&envResult) + err = json.NewDecoder(req.Body).Decode(&envResult) c.Assert(err, check.IsNil) c.Assert(envResult, check.DeepEquals, map[string]interface{}{"envs": []interface{}{map[string]interface{}{"name": "DATABASE_HOST", "value": "somehost"}}}) @@ -208,11 +207,8 @@ variable 2`}, {Name: "LINE1", Value: "multiline\nvariable 1", Alias: "", Private: private}, {Name: "LINE2", Value: "multiline\nvariable 2", Alias: "", Private: private}, } - err = req.ParseForm() var e tsuru.EnvSetData - data, err := ioutil.ReadAll(req.Body) - c.Assert(err, check.IsNil) - err = json.Unmarshal(data, &e) + err = json.NewDecoder(req.Body).Decode(&e) c.Assert(err, check.IsNil) c.Assert(e.Envs, check.DeepEquals, want) private = !e.Private @@ -263,13 +259,8 @@ func (s *S) TestEnvSetValues(c *check.C) { {Name: "BASE64_STRING", Value: "t5urur0ck5==", Alias: "", Private: private}, {Name: "SOME_PASSWORD", Value: "js87$%32??", Alias: "", Private: private}, } - err = req.ParseForm() - c.Assert(err, check.IsNil) var e tsuru.EnvSetData - c.Assert(err, check.IsNil) - data, err := ioutil.ReadAll(req.Body) - c.Assert(err, check.IsNil) - err = json.Unmarshal(data, &e) + err = json.NewDecoder(req.Body).Decode(&e) c.Assert(err, check.IsNil) c.Assert(e.Envs, check.DeepEquals, want) private = !e.Private @@ -319,12 +310,8 @@ func (s *S) TestEnvSetValuesAndPrivateAndNoRestart(c *check.C) { {Name: "VALUE_WITH_EQUAL_SIGN", Value: "http://wholikesquerystrings.me/?tsuru=awesome", Private: private}, {Name: "BASE64_STRING", Value: "t5urur0ck5==", Alias: "", Private: private}, } - err = req.ParseForm() - c.Assert(err, check.IsNil) var e tsuru.EnvSetData - data, err := ioutil.ReadAll(req.Body) - c.Assert(err, check.IsNil) - err = json.Unmarshal(data, &e) + err = json.NewDecoder(req.Body).Decode(&e) c.Assert(err, check.IsNil) c.Assert(e.Envs, check.DeepEquals, want) private = e.Private diff --git a/tsuru/client/services_test.go b/tsuru/client/services_test.go index 80127bc20..8f7a59a63 100644 --- a/tsuru/client/services_test.go +++ b/tsuru/client/services_test.go @@ -251,7 +251,7 @@ func (s *S) TestServiceInstanceBind(c *check.C) { method := req.Method == "PUT" path := strings.HasSuffix(req.URL.Path, "/services/mysql/instances/my-mysql/g1") var bindResult map[string]interface{} - err := json.NewDecoder(req.Body).Decode(&bindResult) + err = json.NewDecoder(req.Body).Decode(&bindResult) c.Assert(err, check.IsNil) c.Assert(bindResult, check.DeepEquals, map[string]interface{}{ "noRestart": true,