9a5720e8ad
Branch Policy Check / Verify merge target (pull_request) Has been cancelled
Universal: PR Check / Branch Policy (pull_request) Has been cancelled
PR RC Release / Build RC Release (pull_request) Has been cancelled
Universal: PR Check / Validate PR (pull_request) Has been cancelled
Branch Cleanup / Delete merged branch (pull_request) Has been cancelled
Universal: PR Check / Build RC Package (pull_request) Has been cancelled
Full namespace migration: update the Go module path and all import statements from git.mokoconsulting.tech to code.mokoconsulting.tech. Also updates all URL references in templates, workflows, configs, tests, and documentation. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
53 lines
1.6 KiB
Go
53 lines
1.6 KiB
Go
// Copyright 2026 The Gitea Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package actions
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"code.mokoconsulting.tech/MokoConsulting/MokoGitea/modules/json"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestWithScheduleInEventPayload(t *testing.T) {
|
|
t.Run("adds schedule to existing payload", func(t *testing.T) {
|
|
payload := `{"ref":"refs/heads/main"}`
|
|
updated := withScheduleInEventPayload(payload, "*/5 * * * *")
|
|
|
|
event := map[string]any{}
|
|
assert.NoError(t, json.Unmarshal([]byte(updated), &event))
|
|
assert.Equal(t, "*/5 * * * *", event["schedule"])
|
|
assert.Equal(t, "refs/heads/main", event["ref"])
|
|
})
|
|
|
|
t.Run("adds schedule to null payload", func(t *testing.T) {
|
|
updated := withScheduleInEventPayload("null", "37 12 5 1 2")
|
|
|
|
event := map[string]any{}
|
|
assert.NoError(t, json.Unmarshal([]byte(updated), &event))
|
|
assert.Equal(t, "37 12 5 1 2", event["schedule"])
|
|
})
|
|
|
|
t.Run("adds schedule to empty payload", func(t *testing.T) {
|
|
updated := withScheduleInEventPayload("", "37 12 5 1 2")
|
|
|
|
event := map[string]any{}
|
|
assert.NoError(t, json.Unmarshal([]byte(updated), &event))
|
|
assert.Equal(t, "37 12 5 1 2", event["schedule"])
|
|
})
|
|
|
|
t.Run("keeps payload when schedule empty", func(t *testing.T) {
|
|
payload := `{"ref":"refs/heads/main"}`
|
|
updated := withScheduleInEventPayload(payload, "")
|
|
assert.Equal(t, payload, updated)
|
|
})
|
|
|
|
t.Run("keeps payload when malformed JSON", func(t *testing.T) {
|
|
payload := `not a json object`
|
|
updated := withScheduleInEventPayload(payload, "*/5 * * * *")
|
|
assert.Equal(t, payload, updated)
|
|
})
|
|
}
|