mirror of https://github.com/go-gitea/gitea
Git with a cup of tea, painless self-hosted git service
Mirror for internal git.with.parts use
https://git.with.parts
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
67 lines
1.8 KiB
67 lines
1.8 KiB
// Copyright 2022 The Gitea Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package pull
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func Test_expandDefaultMergeMessage(t *testing.T) {
|
|
type args struct {
|
|
template string
|
|
vars map[string]string
|
|
}
|
|
tests := []struct {
|
|
name string
|
|
args args
|
|
want string
|
|
wantBody string
|
|
}{
|
|
{
|
|
name: "single line",
|
|
args: args{
|
|
template: "Merge ${PullRequestTitle}",
|
|
vars: map[string]string{
|
|
"PullRequestTitle": "PullRequestTitle",
|
|
"PullRequestDescription": "Pull\nRequest\nDescription\n",
|
|
},
|
|
},
|
|
want: "Merge PullRequestTitle",
|
|
wantBody: "",
|
|
},
|
|
{
|
|
name: "multiple lines",
|
|
args: args{
|
|
template: "Merge ${PullRequestTitle}\nDescription:\n\n${PullRequestDescription}\n",
|
|
vars: map[string]string{
|
|
"PullRequestTitle": "PullRequestTitle",
|
|
"PullRequestDescription": "Pull\nRequest\nDescription\n",
|
|
},
|
|
},
|
|
want: "Merge PullRequestTitle",
|
|
wantBody: "Description:\n\nPull\nRequest\nDescription\n",
|
|
},
|
|
{
|
|
name: "leading newlines",
|
|
args: args{
|
|
template: "\n\n\nMerge ${PullRequestTitle}\n\n\nDescription:\n\n${PullRequestDescription}\n",
|
|
vars: map[string]string{
|
|
"PullRequestTitle": "PullRequestTitle",
|
|
"PullRequestDescription": "Pull\nRequest\nDescription\n",
|
|
},
|
|
},
|
|
want: "Merge PullRequestTitle",
|
|
wantBody: "Description:\n\nPull\nRequest\nDescription\n",
|
|
},
|
|
}
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
got, got1 := expandDefaultMergeMessage(tt.args.template, tt.args.vars)
|
|
assert.Equalf(t, tt.want, got, "expandDefaultMergeMessage(%v, %v)", tt.args.template, tt.args.vars)
|
|
assert.Equalf(t, tt.wantBody, got1, "expandDefaultMergeMessage(%v, %v)", tt.args.template, tt.args.vars)
|
|
})
|
|
}
|
|
}
|
|
|