mirror of
https://github.com/go-gitea/gitea.git
synced 2025-06-20 13:08:02 +02:00
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
This commit is contained in:
@ -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))
|
||||
|
||||
|
@ -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)
|
||||
|
@ -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))
|
||||
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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)
|
||||
|
||||
|
@ -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))
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
Reference in New Issue
Block a user