aboutsummaryrefslogtreecommitdiffstats
path: root/integrations
diff options
context:
space:
mode:
authorLunny Xiao <xiaolunwen@gmail.com>2021-07-25 00:03:58 +0800
committerGitHub <noreply@github.com>2021-07-24 18:03:58 +0200
commit9f31f3aa8ac4f6bfc8390c9ae63b2a387b414c88 (patch)
tree6f27dc68a35d1f9d806c632e36f0edc8543184ea /integrations
parente0f9635c0691cb67f0fcbb758cabba801d9fc51b (diff)
downloadgitea-9f31f3aa8ac4f6bfc8390c9ae63b2a387b414c88.tar.gz
gitea-9f31f3aa8ac4f6bfc8390c9ae63b2a387b414c88.zip
Add an abstract json layout to make it's easier to change json library (#16528)
* Add an abstract json layout to make it's easier to change json library * Fix import * Fix import sequence * Fix blank lines * Fix blank lines
Diffstat (limited to 'integrations')
-rw-r--r--integrations/api_admin_test.go3
-rw-r--r--integrations/api_helper_for_declarative_test.go4
-rw-r--r--integrations/api_pull_review_test.go4
-rw-r--r--integrations/api_repo_lfs_test.go3
-rw-r--r--integrations/create_no_session_test.go3
-rw-r--r--integrations/integration_test.go4
-rw-r--r--integrations/lfs_getobject_test.go4
-rw-r--r--integrations/oauth_test.go6
-rw-r--r--integrations/repo_commits_test.go3
-rw-r--r--integrations/testlogger.go3
10 files changed, 12 insertions, 25 deletions
diff --git a/integrations/api_admin_test.go b/integrations/api_admin_test.go
index b93179d21d..da6a89c974 100644
--- a/integrations/api_admin_test.go
+++ b/integrations/api_admin_test.go
@@ -10,9 +10,9 @@ import (
"testing"
"code.gitea.io/gitea/models"
+ "code.gitea.io/gitea/modules/json"
api "code.gitea.io/gitea/modules/structs"
- jsoniter "github.com/json-iterator/go"
"github.com/stretchr/testify/assert"
)
@@ -190,7 +190,6 @@ func TestAPIEditUser(t *testing.T) {
resp := session.MakeRequest(t, req, http.StatusUnprocessableEntity)
errMap := make(map[string]interface{})
- json := jsoniter.ConfigCompatibleWithStandardLibrary
json.Unmarshal(resp.Body.Bytes(), &errMap)
assert.EqualValues(t, "email is not allowed to be empty string", errMap["message"].(string))
diff --git a/integrations/api_helper_for_declarative_test.go b/integrations/api_helper_for_declarative_test.go
index d56ae5d27c..5d44cde5bf 100644
--- a/integrations/api_helper_for_declarative_test.go
+++ b/integrations/api_helper_for_declarative_test.go
@@ -14,11 +14,11 @@ import (
"time"
"code.gitea.io/gitea/models"
+ "code.gitea.io/gitea/modules/json"
"code.gitea.io/gitea/modules/queue"
api "code.gitea.io/gitea/modules/structs"
"code.gitea.io/gitea/services/forms"
- jsoniter "github.com/json-iterator/go"
"github.com/stretchr/testify/assert"
)
@@ -231,7 +231,6 @@ func doAPICreatePullRequest(ctx APITestContext, owner, repo, baseBranch, headBra
}
resp := ctx.Session.MakeRequest(t, req, expected)
- json := jsoniter.ConfigCompatibleWithStandardLibrary
decoder := json.NewDecoder(resp.Body)
pr := api.PullRequest{}
err := decoder.Decode(&pr)
@@ -251,7 +250,6 @@ func doAPIGetPullRequest(ctx APITestContext, owner, repo string, index int64) fu
}
resp := ctx.Session.MakeRequest(t, req, expected)
- json := jsoniter.ConfigCompatibleWithStandardLibrary
decoder := json.NewDecoder(resp.Body)
pr := api.PullRequest{}
err := decoder.Decode(&pr)
diff --git a/integrations/api_pull_review_test.go b/integrations/api_pull_review_test.go
index bcc0cbffcb..b0e380376b 100644
--- a/integrations/api_pull_review_test.go
+++ b/integrations/api_pull_review_test.go
@@ -10,8 +10,9 @@ import (
"testing"
"code.gitea.io/gitea/models"
+ "code.gitea.io/gitea/modules/json"
api "code.gitea.io/gitea/modules/structs"
- jsoniter "github.com/json-iterator/go"
+
"github.com/stretchr/testify/assert"
)
@@ -189,7 +190,6 @@ func TestAPIPullReview(t *testing.T) {
})
resp = session.MakeRequest(t, req, http.StatusUnprocessableEntity)
errMap := make(map[string]interface{})
- json := jsoniter.ConfigCompatibleWithStandardLibrary
json.Unmarshal(resp.Body.Bytes(), &errMap)
assert.EqualValues(t, "review event COMMENT requires a body or a comment", errMap["message"].(string))
diff --git a/integrations/api_repo_lfs_test.go b/integrations/api_repo_lfs_test.go
index 9e1e2b0418..7aa172064e 100644
--- a/integrations/api_repo_lfs_test.go
+++ b/integrations/api_repo_lfs_test.go
@@ -13,10 +13,10 @@ import (
"testing"
"code.gitea.io/gitea/models"
+ "code.gitea.io/gitea/modules/json"
"code.gitea.io/gitea/modules/lfs"
"code.gitea.io/gitea/modules/setting"
- jsoniter "github.com/json-iterator/go"
"github.com/stretchr/testify/assert"
)
@@ -86,7 +86,6 @@ func TestAPILFSBatch(t *testing.T) {
decodeResponse := func(t *testing.T, b *bytes.Buffer) *lfs.BatchResponse {
var br lfs.BatchResponse
- json := jsoniter.ConfigCompatibleWithStandardLibrary
assert.NoError(t, json.Unmarshal(b.Bytes(), &br))
return &br
}
diff --git a/integrations/create_no_session_test.go b/integrations/create_no_session_test.go
index 46f111b6f7..d6b3634268 100644
--- a/integrations/create_no_session_test.go
+++ b/integrations/create_no_session_test.go
@@ -12,12 +12,12 @@ import (
"path/filepath"
"testing"
+ "code.gitea.io/gitea/modules/json"
"code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/modules/util"
"code.gitea.io/gitea/routers"
"gitea.com/go-chi/session"
- jsoniter "github.com/json-iterator/go"
"github.com/stretchr/testify/assert"
)
@@ -63,7 +63,6 @@ func TestSessionFileCreation(t *testing.T) {
var config session.Options
- json := jsoniter.ConfigCompatibleWithStandardLibrary
err := json.Unmarshal([]byte(oldSessionConfig), &config)
assert.NoError(t, err)
diff --git a/integrations/integration_test.go b/integrations/integration_test.go
index 8a008ac621..7ddcf3e1cd 100644
--- a/integrations/integration_test.go
+++ b/integrations/integration_test.go
@@ -28,6 +28,7 @@ import (
"code.gitea.io/gitea/modules/base"
"code.gitea.io/gitea/modules/git"
"code.gitea.io/gitea/modules/graceful"
+ "code.gitea.io/gitea/modules/json"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/queue"
"code.gitea.io/gitea/modules/setting"
@@ -37,7 +38,6 @@ import (
"code.gitea.io/gitea/routers"
"github.com/PuerkitoBio/goquery"
- jsoniter "github.com/json-iterator/go"
"github.com/stretchr/testify/assert"
)
@@ -416,7 +416,6 @@ func NewRequestWithValues(t testing.TB, method, urlStr string, values map[string
func NewRequestWithJSON(t testing.TB, method, urlStr string, v interface{}) *http.Request {
t.Helper()
- json := jsoniter.ConfigCompatibleWithStandardLibrary
jsonBytes, err := json.Marshal(v)
assert.NoError(t, err)
req := NewRequestWithBody(t, method, urlStr, bytes.NewBuffer(jsonBytes))
@@ -508,7 +507,6 @@ func logUnexpectedResponse(t testing.TB, recorder *httptest.ResponseRecorder) {
func DecodeJSON(t testing.TB, resp *httptest.ResponseRecorder, v interface{}) {
t.Helper()
- json := jsoniter.ConfigCompatibleWithStandardLibrary
decoder := json.NewDecoder(resp.Body)
assert.NoError(t, decoder.Decode(v))
}
diff --git a/integrations/lfs_getobject_test.go b/integrations/lfs_getobject_test.go
index c99500f469..063f72b25c 100644
--- a/integrations/lfs_getobject_test.go
+++ b/integrations/lfs_getobject_test.go
@@ -14,11 +14,11 @@ import (
"code.gitea.io/gitea/models"
"code.gitea.io/gitea/modules/git"
+ "code.gitea.io/gitea/modules/json"
"code.gitea.io/gitea/modules/lfs"
"code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/routers/web"
- jsoniter "github.com/json-iterator/go"
gzipp "github.com/klauspost/compress/gzip"
"github.com/stretchr/testify/assert"
)
@@ -206,7 +206,7 @@ func TestGetLFSRange(t *testing.T) {
assert.Equal(t, tt.out, resp.Body.String())
} else {
var er lfs.ErrorResponse
- err := jsoniter.Unmarshal(resp.Body.Bytes(), &er)
+ err := json.Unmarshal(resp.Body.Bytes(), &er)
assert.NoError(t, err)
assert.Equal(t, tt.out, er.Message)
}
diff --git a/integrations/oauth_test.go b/integrations/oauth_test.go
index 2da182d0c8..c97db777be 100644
--- a/integrations/oauth_test.go
+++ b/integrations/oauth_test.go
@@ -9,9 +9,9 @@ import (
"io/ioutil"
"testing"
+ "code.gitea.io/gitea/modules/json"
"code.gitea.io/gitea/modules/setting"
- jsoniter "github.com/json-iterator/go"
"github.com/stretchr/testify/assert"
)
@@ -71,7 +71,6 @@ func TestAccessTokenExchange(t *testing.T) {
}
parsed := new(response)
- json := jsoniter.ConfigCompatibleWithStandardLibrary
assert.NoError(t, json.Unmarshal(resp.Body.Bytes(), parsed))
assert.True(t, len(parsed.AccessToken) > 10)
assert.True(t, len(parsed.RefreshToken) > 10)
@@ -96,7 +95,6 @@ func TestAccessTokenExchangeWithoutPKCE(t *testing.T) {
}
parsed := new(response)
- json := jsoniter.ConfigCompatibleWithStandardLibrary
assert.NoError(t, json.Unmarshal(resp.Body.Bytes(), parsed))
assert.True(t, len(parsed.AccessToken) > 10)
assert.True(t, len(parsed.RefreshToken) > 10)
@@ -186,7 +184,6 @@ func TestAccessTokenExchangeWithBasicAuth(t *testing.T) {
}
parsed := new(response)
- json := jsoniter.ConfigCompatibleWithStandardLibrary
assert.NoError(t, json.Unmarshal(resp.Body.Bytes(), parsed))
assert.True(t, len(parsed.AccessToken) > 10)
assert.True(t, len(parsed.RefreshToken) > 10)
@@ -230,7 +227,6 @@ func TestRefreshTokenInvalidation(t *testing.T) {
}
parsed := new(response)
- json := jsoniter.ConfigCompatibleWithStandardLibrary
assert.NoError(t, json.Unmarshal(resp.Body.Bytes(), parsed))
// test without invalidation
diff --git a/integrations/repo_commits_test.go b/integrations/repo_commits_test.go
index 8dcbcd3683..4be1e4ec8e 100644
--- a/integrations/repo_commits_test.go
+++ b/integrations/repo_commits_test.go
@@ -10,10 +10,10 @@ import (
"path"
"testing"
+ "code.gitea.io/gitea/modules/json"
"code.gitea.io/gitea/modules/setting"
api "code.gitea.io/gitea/modules/structs"
- jsoniter "github.com/json-iterator/go"
"github.com/stretchr/testify/assert"
)
@@ -86,7 +86,6 @@ func doTestRepoCommitWithStatus(t *testing.T, state string, classes ...string) {
}
func testRepoCommitsWithStatus(t *testing.T, resp, respOne *httptest.ResponseRecorder, state string) {
- json := jsoniter.ConfigCompatibleWithStandardLibrary
var statuses []*api.CommitStatus
assert.NoError(t, json.Unmarshal(resp.Body.Bytes(), &statuses))
var status api.CombinedStatus
diff --git a/integrations/testlogger.go b/integrations/testlogger.go
index 9ea357ba27..9498ad655b 100644
--- a/integrations/testlogger.go
+++ b/integrations/testlogger.go
@@ -14,9 +14,9 @@ import (
"testing"
"time"
+ "code.gitea.io/gitea/modules/json"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/queue"
- jsoniter "github.com/json-iterator/go"
)
var (
@@ -158,7 +158,6 @@ func NewTestLogger() log.LoggerProvider {
// Init inits connection writer with json config.
// json config only need key "level".
func (log *TestLogger) Init(config string) error {
- json := jsoniter.ConfigCompatibleWithStandardLibrary
err := json.Unmarshal([]byte(config), log)
if err != nil {
return err