mirror of
https://github.com/apricote/releaser-pleaser.git
synced 2026-01-13 13:21:00 +00:00
This change reverses the responsibility for which files the updaters are run on. Now each updater can specify the list of files and wether the files should be created when they do not exist yet. This simplifies the handling of each update in releaserpleaser.go, as we can just iterate over all updaters and call it for each file of that updater. Also update the flags to allow users to easily define which updaters should run.
61 lines
1.5 KiB
Go
61 lines
1.5 KiB
Go
package updater
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestGenericUpdater_Files(t *testing.T) {
|
|
assert.Equal(t, []string{"foo.bar", "version.txt"}, Generic([]string{"foo.bar", "version.txt"}).Files())
|
|
}
|
|
|
|
func TestGenericUpdater_CreateNewFiles(t *testing.T) {
|
|
assert.False(t, Generic([]string{}).CreateNewFiles())
|
|
}
|
|
|
|
func TestGenericUpdater_Update(t *testing.T) {
|
|
tests := []updaterTestCase{
|
|
{
|
|
name: "single line",
|
|
content: "v1.0.0 // x-releaser-pleaser-version",
|
|
info: ReleaseInfo{
|
|
Version: "v1.2.0",
|
|
},
|
|
want: "v1.2.0 // x-releaser-pleaser-version",
|
|
wantErr: assert.NoError,
|
|
},
|
|
{
|
|
name: "multiline line",
|
|
content: "Foooo\n\v1.2.0\nv1.0.0 // x-releaser-pleaser-version\n",
|
|
info: ReleaseInfo{
|
|
Version: "v1.2.0",
|
|
},
|
|
want: "Foooo\n\v1.2.0\nv1.2.0 // x-releaser-pleaser-version\n",
|
|
wantErr: assert.NoError,
|
|
},
|
|
{
|
|
name: "invalid existing version",
|
|
content: "1.0 // x-releaser-pleaser-version",
|
|
info: ReleaseInfo{
|
|
Version: "v1.2.0",
|
|
},
|
|
want: "1.0 // x-releaser-pleaser-version",
|
|
wantErr: assert.NoError,
|
|
},
|
|
{
|
|
name: "complicated line",
|
|
content: "version: v1.2.0-alpha.1 => Awesome, isnt it? x-releaser-pleaser-version foobar",
|
|
info: ReleaseInfo{
|
|
Version: "v1.2.0",
|
|
},
|
|
want: "version: v1.2.0 => Awesome, isnt it? x-releaser-pleaser-version foobar",
|
|
wantErr: assert.NoError,
|
|
},
|
|
}
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
runUpdaterTest(t, Generic([]string{"version.txt"}), tt)
|
|
})
|
|
}
|
|
}
|