mirror of
https://github.com/apricote/releaser-pleaser.git
synced 2026-02-07 18:27:03 +00:00
refactor: let updaters define the files they want to run on
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.
This commit is contained in:
parent
1e9e0aa5d9
commit
0cc22af991
20 changed files with 307 additions and 151 deletions
|
|
@ -6,12 +6,19 @@ import (
|
|||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestGenericUpdater_UpdateContent(t *testing.T) {
|
||||
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",
|
||||
filename: "version.txt",
|
||||
name: "single line",
|
||||
content: "v1.0.0 // x-releaser-pleaser-version",
|
||||
info: ReleaseInfo{
|
||||
Version: "v1.2.0",
|
||||
},
|
||||
|
|
@ -19,9 +26,8 @@ func TestGenericUpdater_UpdateContent(t *testing.T) {
|
|||
wantErr: assert.NoError,
|
||||
},
|
||||
{
|
||||
name: "multiline line",
|
||||
content: "Foooo\n\v1.2.0\nv1.0.0 // x-releaser-pleaser-version\n",
|
||||
filename: "version.txt",
|
||||
name: "multiline line",
|
||||
content: "Foooo\n\v1.2.0\nv1.0.0 // x-releaser-pleaser-version\n",
|
||||
info: ReleaseInfo{
|
||||
Version: "v1.2.0",
|
||||
},
|
||||
|
|
@ -29,9 +35,8 @@ func TestGenericUpdater_UpdateContent(t *testing.T) {
|
|||
wantErr: assert.NoError,
|
||||
},
|
||||
{
|
||||
name: "invalid existing version",
|
||||
content: "1.0 // x-releaser-pleaser-version",
|
||||
filename: "version.txt",
|
||||
name: "invalid existing version",
|
||||
content: "1.0 // x-releaser-pleaser-version",
|
||||
info: ReleaseInfo{
|
||||
Version: "v1.2.0",
|
||||
},
|
||||
|
|
@ -39,9 +44,8 @@ func TestGenericUpdater_UpdateContent(t *testing.T) {
|
|||
wantErr: assert.NoError,
|
||||
},
|
||||
{
|
||||
name: "complicated line",
|
||||
content: "version: v1.2.0-alpha.1 => Awesome, isnt it? x-releaser-pleaser-version foobar",
|
||||
filename: "version.txt",
|
||||
name: "complicated line",
|
||||
content: "version: v1.2.0-alpha.1 => Awesome, isnt it? x-releaser-pleaser-version foobar",
|
||||
info: ReleaseInfo{
|
||||
Version: "v1.2.0",
|
||||
},
|
||||
|
|
@ -51,7 +55,7 @@ func TestGenericUpdater_UpdateContent(t *testing.T) {
|
|||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
runUpdaterTest(t, Generic, tt)
|
||||
runUpdaterTest(t, Generic([]string{"version.txt"}), tt)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue