mirror of
https://github.com/apricote/releaser-pleaser.git
synced 2026-01-13 21:21:03 +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.
62 lines
1.4 KiB
Go
62 lines
1.4 KiB
Go
package updater
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestPackageJsonUpdater_Files(t *testing.T) {
|
|
assert.Equal(t, []string{"package.json"}, PackageJson().Files())
|
|
}
|
|
|
|
func TestPackageJsonUpdater_CreateNewFiles(t *testing.T) {
|
|
assert.False(t, PackageJson().CreateNewFiles())
|
|
}
|
|
|
|
func TestPackageJsonUpdater_Update(t *testing.T) {
|
|
tests := []updaterTestCase{
|
|
{
|
|
name: "simple package.json",
|
|
content: `{"name":"test","version":"1.0.0"}`,
|
|
info: ReleaseInfo{
|
|
Version: "v2.0.5",
|
|
},
|
|
want: `{"name":"test","version":"2.0.5"}`,
|
|
wantErr: assert.NoError,
|
|
},
|
|
{
|
|
name: "complex package.json",
|
|
content: "{\n \"name\": \"test\",\n \"version\": \"1.0.0\",\n \"dependencies\": {\n \"foo\": \"^1.0.0\"\n }\n}",
|
|
info: ReleaseInfo{
|
|
Version: "v2.0.0",
|
|
},
|
|
want: "{\n \"name\": \"test\",\n \"version\": \"2.0.0\",\n \"dependencies\": {\n \"foo\": \"^1.0.0\"\n }\n}",
|
|
wantErr: assert.NoError,
|
|
},
|
|
{
|
|
name: "invalid json",
|
|
content: `not json`,
|
|
info: ReleaseInfo{
|
|
Version: "v2.0.0",
|
|
},
|
|
want: `not json`,
|
|
wantErr: assert.NoError,
|
|
},
|
|
{
|
|
name: "json without version",
|
|
content: `{"name":"test"}`,
|
|
info: ReleaseInfo{
|
|
Version: "v2.0.0",
|
|
},
|
|
want: `{"name":"test"}`,
|
|
wantErr: assert.NoError,
|
|
},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
runUpdaterTest(t, PackageJson(), tt)
|
|
})
|
|
}
|
|
}
|