2024-02-29 08:14:50 +00:00
|
|
|
// Copyright 2024 The Forgejo Authors. All rights reserved.
|
|
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
|
|
|
|
package v1_22 //nolint
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2024-07-14 13:34:42 +00:00
|
|
|
migration_tests "code.gitea.io/gitea/models/migrations/test"
|
2024-02-29 08:14:50 +00:00
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
2024-07-30 19:41:10 +00:00
|
|
|
"github.com/stretchr/testify/require"
|
2024-02-29 08:14:50 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func Test_RemoveSSHSignaturesFromReleaseNotes(t *testing.T) {
|
|
|
|
// A reduced mock of the `repo_model.Release` struct.
|
|
|
|
type Release struct {
|
|
|
|
ID int64 `xorm:"pk autoincr"`
|
|
|
|
Note string `xorm:"TEXT"`
|
|
|
|
}
|
|
|
|
|
2024-07-14 13:34:42 +00:00
|
|
|
x, deferable := migration_tests.PrepareTestEnv(t, 0, new(Release))
|
2024-02-29 08:14:50 +00:00
|
|
|
defer deferable()
|
|
|
|
|
2024-07-30 19:41:10 +00:00
|
|
|
require.NoError(t, RemoveSSHSignaturesFromReleaseNotes(x))
|
2024-02-29 08:14:50 +00:00
|
|
|
|
|
|
|
var releases []Release
|
|
|
|
err := x.Table("release").OrderBy("id ASC").Find(&releases)
|
2024-07-30 19:41:10 +00:00
|
|
|
require.NoError(t, err)
|
2024-02-29 08:14:50 +00:00
|
|
|
assert.Len(t, releases, 3)
|
|
|
|
|
|
|
|
assert.Equal(t, "", releases[0].Note)
|
|
|
|
assert.Equal(t, "A message.\n", releases[1].Note)
|
|
|
|
assert.Equal(t, "no signature present here", releases[2].Note)
|
|
|
|
}
|