diff --git a/modules/migration/file_format_test.go b/modules/migration/file_format_test.go index fd7db9074b..e1d85fcb36 100644 --- a/modules/migration/file_format_test.go +++ b/modules/migration/file_format_test.go @@ -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") +}