summaryrefslogtreecommitdiff
path: root/internal/api/client/instance/instancepeersget_test.go
diff options
context:
space:
mode:
authorLibravatar kim <89579420+NyaaaWhatsUpDoc@users.noreply.github.com>2022-07-12 08:32:20 +0100
committerLibravatar GitHub <noreply@github.com>2022-07-12 08:32:20 +0100
commit6934ae378ab5743da80a5995fc74d167502187b1 (patch)
tree6e3f58498158f1e844504961338eadb18f5a590e /internal/api/client/instance/instancepeersget_test.go
parent[performance] Add new index to fix slow web profile queries (#706) (diff)
downloadgotosocial-6934ae378ab5743da80a5995fc74d167502187b1.tar.xz
[chore] improved router logging, recovery and error handling (#705)
* move panic recovery to logging middleware, improve logging + panic recovery logic Signed-off-by: kim <grufwub@gmail.com> * remove dead code Signed-off-by: kim <grufwub@gmail.com> * remove skip paths code Signed-off-by: kim <grufwub@gmail.com> * re-enable log quoting Signed-off-by: kim <grufwub@gmail.com> * use human-friendly bytesize in logging body size Signed-off-by: kim <grufwub@gmail.com> * only disable quoting in debug builds Signed-off-by: kim <grufwub@gmail.com> * use logrus level instead of debug.DEBUG() to enable/disable quoting Signed-off-by: kim <grufwub@gmail.com> * shutup linter Signed-off-by: kim <grufwub@gmail.com> * fix instance tests Signed-off-by: kim <grufwub@gmail.com> * fix gin test contexts created with missing engine HTML renderer Signed-off-by: kim <grufwub@gmail.com> * add note regarding not logging query parameters Signed-off-by: kim <grufwub@gmail.com> * better explain 'DisableQuoting' logic Signed-off-by: kim <grufwub@gmail.com> * add license text Signed-off-by: kim <grufwub@gmail.com>
Diffstat (limited to 'internal/api/client/instance/instancepeersget_test.go')
-rw-r--r--internal/api/client/instance/instancepeersget_test.go33
1 files changed, 11 insertions, 22 deletions
diff --git a/internal/api/client/instance/instancepeersget_test.go b/internal/api/client/instance/instancepeersget_test.go
index cb35a9e50..48fb42a73 100644
--- a/internal/api/client/instance/instancepeersget_test.go
+++ b/internal/api/client/instance/instancepeersget_test.go
@@ -26,7 +26,7 @@ import (
"net/http/httptest"
"testing"
- "github.com/gin-gonic/gin"
+ "github.com/gin-gonic/gin/render"
"github.com/stretchr/testify/suite"
"github.com/superseriousbusiness/gotosocial/internal/api/client/instance"
"github.com/superseriousbusiness/gotosocial/internal/config"
@@ -40,7 +40,8 @@ type InstancePeersGetTestSuite struct {
func (suite *InstancePeersGetTestSuite) TestInstancePeersGetNoParams() {
recorder := httptest.NewRecorder()
- ctx, _ := gin.CreateTestContext(recorder)
+ ctx, r := testrig.CreateGinTestContext(recorder, nil)
+ r.HTMLRender = render.HTMLDebug{}
baseURI := fmt.Sprintf("%s://%s", config.GetProtocol(), config.GetHost())
requestURI := fmt.Sprintf("%s/%s", baseURI, instance.InstancePeersPath)
@@ -63,11 +64,9 @@ func (suite *InstancePeersGetTestSuite) TestInstancePeersGetNoParamsUnauthorized
config.SetInstanceExposePeers(false)
recorder := httptest.NewRecorder()
- ctx, _ := gin.CreateTestContext(recorder)
-
baseURI := fmt.Sprintf("%s://%s", config.GetProtocol(), config.GetHost())
requestURI := fmt.Sprintf("%s/%s", baseURI, instance.InstancePeersPath)
- ctx.Request = httptest.NewRequest(http.MethodGet, requestURI, nil)
+ ctx := suite.newContext(recorder, http.MethodGet, requestURI, nil, "", false)
suite.instanceModule.InstancePeersGETHandler(ctx)
@@ -88,7 +87,7 @@ func (suite *InstancePeersGetTestSuite) TestInstancePeersGetNoParamsAuthorized()
recorder := httptest.NewRecorder()
baseURI := fmt.Sprintf("%s://%s", config.GetProtocol(), config.GetHost())
requestURI := fmt.Sprintf("%s/%s", baseURI, instance.InstancePeersPath)
- ctx := suite.newContext(recorder, http.MethodGet, []byte{}, requestURI, "")
+ ctx := suite.newContext(recorder, http.MethodGet, requestURI, nil, "", true)
suite.instanceModule.InstancePeersGETHandler(ctx)
@@ -105,11 +104,9 @@ func (suite *InstancePeersGetTestSuite) TestInstancePeersGetNoParamsAuthorized()
func (suite *InstancePeersGetTestSuite) TestInstancePeersGetOnlySuspended() {
recorder := httptest.NewRecorder()
- ctx, _ := gin.CreateTestContext(recorder)
-
baseURI := fmt.Sprintf("%s://%s", config.GetProtocol(), config.GetHost())
requestURI := fmt.Sprintf("%s/%s?filter=suspended", baseURI, instance.InstancePeersPath)
- ctx.Request = httptest.NewRequest(http.MethodGet, requestURI, nil)
+ ctx := suite.newContext(recorder, http.MethodGet, requestURI, nil, "", false)
suite.instanceModule.InstancePeersGETHandler(ctx)
@@ -128,11 +125,9 @@ func (suite *InstancePeersGetTestSuite) TestInstancePeersGetOnlySuspendedUnautho
config.SetInstanceExposeSuspended(false)
recorder := httptest.NewRecorder()
- ctx, _ := gin.CreateTestContext(recorder)
-
baseURI := fmt.Sprintf("%s://%s", config.GetProtocol(), config.GetHost())
requestURI := fmt.Sprintf("%s/%s?filter=suspended", baseURI, instance.InstancePeersPath)
- ctx.Request = httptest.NewRequest(http.MethodGet, requestURI, nil)
+ ctx := suite.newContext(recorder, http.MethodGet, requestURI, nil, "", false)
suite.instanceModule.InstancePeersGETHandler(ctx)
@@ -153,7 +148,7 @@ func (suite *InstancePeersGetTestSuite) TestInstancePeersGetOnlySuspendedAuthori
recorder := httptest.NewRecorder()
baseURI := fmt.Sprintf("%s://%s", config.GetProtocol(), config.GetHost())
requestURI := fmt.Sprintf("%s/%s?filter=suspended", baseURI, instance.InstancePeersPath)
- ctx := suite.newContext(recorder, http.MethodGet, []byte{}, requestURI, "")
+ ctx := suite.newContext(recorder, http.MethodGet, requestURI, nil, "", true)
suite.instanceModule.InstancePeersGETHandler(ctx)
@@ -170,11 +165,9 @@ func (suite *InstancePeersGetTestSuite) TestInstancePeersGetOnlySuspendedAuthori
func (suite *InstancePeersGetTestSuite) TestInstancePeersGetAll() {
recorder := httptest.NewRecorder()
- ctx, _ := gin.CreateTestContext(recorder)
-
baseURI := fmt.Sprintf("%s://%s", config.GetProtocol(), config.GetHost())
requestURI := fmt.Sprintf("%s/%s?filter=suspended,open", baseURI, instance.InstancePeersPath)
- ctx.Request = httptest.NewRequest(http.MethodGet, requestURI, nil)
+ ctx := suite.newContext(recorder, http.MethodGet, requestURI, nil, "", false)
suite.instanceModule.InstancePeersGETHandler(ctx)
@@ -202,11 +195,9 @@ func (suite *InstancePeersGetTestSuite) TestInstancePeersGetAllWithObfuscated()
suite.NoError(err)
recorder := httptest.NewRecorder()
- ctx, _ := gin.CreateTestContext(recorder)
-
baseURI := fmt.Sprintf("%s://%s", config.GetProtocol(), config.GetHost())
requestURI := fmt.Sprintf("%s/%s?filter=suspended,open", baseURI, instance.InstancePeersPath)
- ctx.Request = httptest.NewRequest(http.MethodGet, requestURI, nil)
+ ctx := suite.newContext(recorder, http.MethodGet, requestURI, nil, "", false)
suite.instanceModule.InstancePeersGETHandler(ctx)
@@ -223,11 +214,9 @@ func (suite *InstancePeersGetTestSuite) TestInstancePeersGetAllWithObfuscated()
func (suite *InstancePeersGetTestSuite) TestInstancePeersGetFunkyParams() {
recorder := httptest.NewRecorder()
- ctx, _ := gin.CreateTestContext(recorder)
-
baseURI := fmt.Sprintf("%s://%s", config.GetProtocol(), config.GetHost())
requestURI := fmt.Sprintf("%s/%s?filter=aaaaaaaaaaaaaaaaa,open", baseURI, instance.InstancePeersPath)
- ctx.Request = httptest.NewRequest(http.MethodGet, requestURI, nil)
+ ctx := suite.newContext(recorder, http.MethodGet, requestURI, nil, "", true)
suite.instanceModule.InstancePeersGETHandler(ctx)