Skip to content

Commit f302ca8

Browse files
committed
fix
1 parent cb47618 commit f302ca8

File tree

5 files changed

+21
-12
lines changed

5 files changed

+21
-12
lines changed

.github/workflows/pull-db-tests.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,13 +72,13 @@ jobs:
7272
go-version-file: go.mod
7373
check-latest: true
7474
- run: make deps-backend
75-
- run: make backend
75+
- run: GOEXPERIMENT='' make backend
7676
env:
7777
TAGS: bindata gogit sqlite sqlite_unlock_notify
7878
- name: run migration tests
7979
run: make test-sqlite-migration
8080
- name: run tests
81-
run: make test-sqlite
81+
run: GOEXPERIMENT='' make test-sqlite
8282
timeout-minutes: 50
8383
env:
8484
TAGS: bindata gogit sqlite sqlite_unlock_notify
@@ -142,7 +142,7 @@ jobs:
142142
RACE_ENABLED: true
143143
GITHUB_READ_TOKEN: ${{ secrets.GITHUB_READ_TOKEN }}
144144
- name: unit-tests-gogit
145-
run: make unit-test-coverage test-check
145+
run: GOEXPERIMENT='' make unit-test-coverage test-check
146146
env:
147147
TAGS: bindata gogit
148148
RACE_ENABLED: true

modules/json/jsonv2.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,12 @@ var jsonV2 JSONv2
2424

2525
func init() {
2626
commonMarshalOptions := []jsonv2.Options{
27-
jsonv2.MatchCaseInsensitiveNames(true),
2827
jsonv2.FormatNilSliceAsNull(true),
2928
jsonv2.FormatNilMapAsNull(true),
30-
jsonv2.Deterministic(true),
3129
}
3230
jsonV2.marshalOptions = jsonv2.JoinOptions(commonMarshalOptions...)
31+
32+
// Some JSON structs like oci.ImageConfig uses case-insensitive matching
3333
jsonV2.unmarshalOptions = jsonv2.JoinOptions(jsonv2.MatchCaseInsensitiveNames(true))
3434

3535
// by default, "json/v2" omitempty removes all `""` empty strings, no matter where it comes from.
@@ -38,7 +38,7 @@ func init() {
3838
}
3939

4040
func getDefaultJSONHandler() Interface {
41-
return jsonV2
41+
return &jsonV2
4242
}
4343

4444
func MarshalKeepOptionalEmpty(v any) ([]byte, error) {

modules/packages/container/metadata_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ func TestParseImageConfig(t *testing.T) {
2222
repositoryURL := "https://gitea.com/gitea"
2323
documentationURL := "https://docs.gitea.com"
2424

25+
// FIXME: the test case is not right, the config fields are capitalized in the spec
26+
// https://github.com/opencontainers/image-spec/blob/main/schema/config-schema.json
2527
configOCI := `{"config": {"labels": {"` + labelAuthors + `": "` + author + `", "` + labelLicenses + `": "` + license + `", "` + labelURL + `": "` + projectURL + `", "` + labelSource + `": "` + repositoryURL + `", "` + labelDocumentation + `": "` + documentationURL + `", "` + labelDescription + `": "` + description + `"}}, "history": [{"created_by": "do it 1"}, {"created_by": "dummy #(nop) do it 2"}]}`
2628

2729
metadata, err := ParseImageConfig(oci.MediaTypeImageManifest, strings.NewReader(configOCI))

services/webhook/deliver_test.go

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -179,19 +179,21 @@ func TestWebhookDeliverHookTask(t *testing.T) {
179179
}
180180
]
181181
}`
182+
183+
testVersion := 0
182184
s := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
183185
assert.Equal(t, "PUT", r.Method)
184-
switch r.URL.Path {
185-
case "/webhook/66d222a5d6349e1311f551e50722d837e30fce98":
186-
// Version 1
186+
assert.True(t, strings.HasPrefix(r.URL.Path, "/webhook/"))
187+
assert.Len(t, r.URL.Path, len("/webhook/")+40) // +40 for txnID, a unique ID from payload's sha1 hash
188+
switch testVersion {
189+
case 1: // Version 1
187190
assert.Equal(t, "push", r.Header.Get("X-GitHub-Event"))
188191
assert.Empty(t, r.Header.Get("Content-Type"))
189192
body, err := io.ReadAll(r.Body)
190193
assert.NoError(t, err)
191194
assert.Equal(t, `{"data": 42}`, string(body))
192195

193-
case "/webhook/4ddf3b1533e54f082ae6eadfc1b5530be36c8893":
194-
// Version 2
196+
case 2: // Version 2
195197
assert.Equal(t, "push", r.Header.Get("X-GitHub-Event"))
196198
assert.Equal(t, "application/json", r.Header.Get("Content-Type"))
197199
body, err := io.ReadAll(r.Body)
@@ -220,6 +222,7 @@ func TestWebhookDeliverHookTask(t *testing.T) {
220222
assert.NoError(t, webhook_model.CreateWebhook(t.Context(), hook))
221223

222224
t.Run("Version 1", func(t *testing.T) {
225+
testVersion = 1
223226
hookTask := &webhook_model.HookTask{
224227
HookID: hook.ID,
225228
EventType: webhook_module.HookEventPush,
@@ -246,6 +249,7 @@ func TestWebhookDeliverHookTask(t *testing.T) {
246249
data, err := p.JSONPayload()
247250
assert.NoError(t, err)
248251

252+
testVersion = 2
249253
hookTask := &webhook_model.HookTask{
250254
HookID: hook.ID,
251255
EventType: webhook_module.HookEventPush,

services/webhook/matrix_test.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
package webhook
55

66
import (
7+
"strings"
78
"testing"
89

910
webhook_model "code.gitea.io/gitea/models/webhook"
@@ -216,7 +217,9 @@ func TestMatrixJSONPayload(t *testing.T) {
216217
require.NoError(t, err)
217218

218219
assert.Equal(t, "PUT", req.Method)
219-
assert.Equal(t, "/_matrix/client/r0/rooms/ROOM_ID/send/m.room.message/4ddf3b1533e54f082ae6eadfc1b5530be36c8893", req.URL.Path)
220+
txnID, ok := strings.CutPrefix(req.URL.Path, "/_matrix/client/r0/rooms/ROOM_ID/send/m.room.message/")
221+
assert.True(t, ok)
222+
assert.Len(t, txnID, 40) // txnID is just a unique ID for a webhook request, it is a sha1 hash from the payload
220223
assert.Equal(t, "sha256=", req.Header.Get("X-Hub-Signature-256"))
221224
assert.Equal(t, "application/json", req.Header.Get("Content-Type"))
222225
var body MatrixPayload

0 commit comments

Comments
 (0)