mirror of
https://github.com/go-gitea/gitea.git
synced 2026-06-22 01:27:16 +02:00
test JSON roundtrip for SSHKeyOwnerID
This commit is contained in:
parent
26b4aae364
commit
6bc7ee657b
@ -7,6 +7,8 @@ import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"gitea.dev/modules/json"
|
||||
|
||||
"github.com/santhosh-tekuri/jsonschema/v6"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
@ -36,3 +38,25 @@ func TestMigrationJSON_MilestoneOK(t *testing.T) {
|
||||
err := Load("file_format_testdata/milestones.json", &milestones, true)
|
||||
assert.NoError(t, err)
|
||||
}
|
||||
|
||||
// TestMigrateOptionsSSHKeyOwnerIDRoundtrip guards against the regression where
|
||||
// SSHKeyOwnerID was tagged `json:"-"` and silently lost when the task layer
|
||||
// serialised/deserialised MigrateOptions through the task table, breaking the
|
||||
// "use a specific owner's managed key" override for org migrations.
|
||||
func TestMigrateOptionsSSHKeyOwnerIDRoundtrip(t *testing.T) {
|
||||
data, err := json.Marshal(MigrateOptions{SSHKeyOwnerID: 42})
|
||||
assert.NoError(t, err)
|
||||
|
||||
var got MigrateOptions
|
||||
assert.NoError(t, json.Unmarshal(data, &got))
|
||||
assert.Equal(t, int64(42), got.SSHKeyOwnerID)
|
||||
}
|
||||
|
||||
// TestMigrateOptionsSSHKeyOwnerIDOmitemptyZero ensures the default value (use
|
||||
// repository owner's key) is omitted from the serialised JSON so existing task
|
||||
// payloads in the DB stay compact and backward-compatible.
|
||||
func TestMigrateOptionsSSHKeyOwnerIDOmitemptyZero(t *testing.T) {
|
||||
data, err := json.Marshal(MigrateOptions{})
|
||||
assert.NoError(t, err)
|
||||
assert.NotContains(t, string(data), "ssh_key_owner_id")
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user