mirror of
https://github.com/apricote/releaser-pleaser.git
synced 2026-02-07 18:27:03 +00:00
refactor: move things to packages (#39)
This commit is contained in:
parent
44184a77f9
commit
a0a064d387
32 changed files with 923 additions and 892 deletions
|
|
@ -1,171 +0,0 @@
|
|||
package rp
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func ptr[T any](input T) *T {
|
||||
return &input
|
||||
}
|
||||
|
||||
func Test_NewChangelogEntry(t *testing.T) {
|
||||
type args struct {
|
||||
analyzedCommits []AnalyzedCommit
|
||||
version string
|
||||
link string
|
||||
prefix string
|
||||
suffix string
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
args args
|
||||
want string
|
||||
wantErr assert.ErrorAssertionFunc
|
||||
}{
|
||||
{
|
||||
name: "empty",
|
||||
args: args{
|
||||
analyzedCommits: []AnalyzedCommit{},
|
||||
version: "1.0.0",
|
||||
link: "https://example.com/1.0.0",
|
||||
},
|
||||
want: "## [1.0.0](https://example.com/1.0.0)",
|
||||
wantErr: assert.NoError,
|
||||
},
|
||||
{
|
||||
name: "single feature",
|
||||
args: args{
|
||||
analyzedCommits: []AnalyzedCommit{
|
||||
{
|
||||
Commit: Commit{},
|
||||
Type: "feat",
|
||||
Description: "Foobar!",
|
||||
},
|
||||
},
|
||||
version: "1.0.0",
|
||||
link: "https://example.com/1.0.0",
|
||||
},
|
||||
want: "## [1.0.0](https://example.com/1.0.0)\n### Features\n\n- Foobar!\n",
|
||||
wantErr: assert.NoError,
|
||||
},
|
||||
{
|
||||
name: "single fix",
|
||||
args: args{
|
||||
analyzedCommits: []AnalyzedCommit{
|
||||
{
|
||||
Commit: Commit{},
|
||||
Type: "fix",
|
||||
Description: "Foobar!",
|
||||
},
|
||||
},
|
||||
version: "1.0.0",
|
||||
link: "https://example.com/1.0.0",
|
||||
},
|
||||
want: "## [1.0.0](https://example.com/1.0.0)\n### Bug Fixes\n\n- Foobar!\n",
|
||||
wantErr: assert.NoError,
|
||||
},
|
||||
{
|
||||
name: "multiple commits with scopes",
|
||||
args: args{
|
||||
analyzedCommits: []AnalyzedCommit{
|
||||
{
|
||||
Commit: Commit{},
|
||||
Type: "feat",
|
||||
Description: "Blabla!",
|
||||
},
|
||||
{
|
||||
Commit: Commit{},
|
||||
Type: "feat",
|
||||
Description: "So awesome!",
|
||||
Scope: ptr("awesome"),
|
||||
},
|
||||
{
|
||||
Commit: Commit{},
|
||||
Type: "fix",
|
||||
Description: "Foobar!",
|
||||
},
|
||||
{
|
||||
Commit: Commit{},
|
||||
Type: "fix",
|
||||
Description: "So sad!",
|
||||
Scope: ptr("sad"),
|
||||
},
|
||||
},
|
||||
version: "1.0.0",
|
||||
link: "https://example.com/1.0.0",
|
||||
},
|
||||
want: `## [1.0.0](https://example.com/1.0.0)
|
||||
### Features
|
||||
|
||||
- Blabla!
|
||||
- **awesome**: So awesome!
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
- Foobar!
|
||||
- **sad**: So sad!
|
||||
`,
|
||||
wantErr: assert.NoError,
|
||||
},
|
||||
{
|
||||
name: "prefix",
|
||||
args: args{
|
||||
analyzedCommits: []AnalyzedCommit{
|
||||
{
|
||||
Commit: Commit{},
|
||||
Type: "fix",
|
||||
Description: "Foobar!",
|
||||
},
|
||||
},
|
||||
version: "1.0.0",
|
||||
link: "https://example.com/1.0.0",
|
||||
prefix: "### Breaking Changes",
|
||||
},
|
||||
want: `## [1.0.0](https://example.com/1.0.0)
|
||||
### Breaking Changes
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
- Foobar!
|
||||
`,
|
||||
wantErr: assert.NoError,
|
||||
},
|
||||
{
|
||||
name: "suffix",
|
||||
args: args{
|
||||
analyzedCommits: []AnalyzedCommit{
|
||||
{
|
||||
Commit: Commit{},
|
||||
Type: "fix",
|
||||
Description: "Foobar!",
|
||||
},
|
||||
},
|
||||
version: "1.0.0",
|
||||
link: "https://example.com/1.0.0",
|
||||
suffix: "### Compatibility\n\nThis version is compatible with flux-compensator v2.2 - v2.9.",
|
||||
},
|
||||
want: `## [1.0.0](https://example.com/1.0.0)
|
||||
### Bug Fixes
|
||||
|
||||
- Foobar!
|
||||
|
||||
### Compatibility
|
||||
|
||||
This version is compatible with flux-compensator v2.2 - v2.9.
|
||||
`,
|
||||
wantErr: assert.NoError,
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
got, err := NewChangelogEntry(tt.args.analyzedCommits, tt.args.version, tt.args.link, tt.args.prefix, tt.args.suffix)
|
||||
if !tt.wantErr(t, err) {
|
||||
return
|
||||
}
|
||||
assert.Equal(t, tt.want, got)
|
||||
})
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue