2023-10-15 19:29:29 +00:00
|
|
|
package app
|
2021-04-13 01:19:36 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"reflect"
|
|
|
|
"testing"
|
2021-07-22 23:07:18 +00:00
|
|
|
|
2023-10-16 19:41:33 +00:00
|
|
|
"github.com/thegeeklab/git-sv/sv"
|
2021-04-13 01:19:36 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func Test_merge(t *testing.T) {
|
|
|
|
boolFalse := false
|
|
|
|
boolTrue := true
|
2023-01-22 02:30:29 +00:00
|
|
|
emptyStr := ""
|
|
|
|
nonEmptyStr := "something"
|
2021-04-13 01:19:36 +00:00
|
|
|
|
|
|
|
tests := []struct {
|
|
|
|
name string
|
|
|
|
dst Config
|
|
|
|
src Config
|
|
|
|
want Config
|
|
|
|
wantErr bool
|
|
|
|
}{
|
2023-10-12 14:18:25 +00:00
|
|
|
{
|
|
|
|
"overwrite string",
|
|
|
|
Config{Version: "a"},
|
|
|
|
Config{Version: "b"},
|
|
|
|
Config{Version: "b"},
|
|
|
|
false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"default string",
|
|
|
|
Config{Version: "a"},
|
|
|
|
Config{Version: ""},
|
|
|
|
Config{Version: "a"},
|
|
|
|
false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"overwrite list",
|
|
|
|
Config{Branches: sv.BranchesConfig{Skip: []string{"a", "b"}}},
|
|
|
|
Config{Branches: sv.BranchesConfig{Skip: []string{"c", "d"}}},
|
|
|
|
Config{Branches: sv.BranchesConfig{Skip: []string{"c", "d"}}},
|
|
|
|
false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"overwrite list with empty",
|
|
|
|
Config{Branches: sv.BranchesConfig{Skip: []string{"a", "b"}}},
|
|
|
|
Config{Branches: sv.BranchesConfig{Skip: make([]string, 0)}},
|
|
|
|
Config{Branches: sv.BranchesConfig{Skip: make([]string, 0)}},
|
|
|
|
false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"default list",
|
|
|
|
Config{Branches: sv.BranchesConfig{Skip: []string{"a", "b"}}},
|
|
|
|
Config{Branches: sv.BranchesConfig{Skip: nil}},
|
|
|
|
Config{Branches: sv.BranchesConfig{Skip: []string{"a", "b"}}},
|
|
|
|
false,
|
|
|
|
},
|
2021-04-13 01:19:36 +00:00
|
|
|
|
2023-10-12 14:18:25 +00:00
|
|
|
{
|
|
|
|
"overwrite pointer bool false",
|
|
|
|
Config{Branches: sv.BranchesConfig{SkipDetached: &boolFalse}},
|
|
|
|
Config{Branches: sv.BranchesConfig{SkipDetached: &boolTrue}},
|
|
|
|
Config{Branches: sv.BranchesConfig{SkipDetached: &boolTrue}},
|
|
|
|
false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"overwrite pointer bool true",
|
|
|
|
Config{Branches: sv.BranchesConfig{SkipDetached: &boolTrue}},
|
|
|
|
Config{Branches: sv.BranchesConfig{SkipDetached: &boolFalse}},
|
|
|
|
Config{Branches: sv.BranchesConfig{SkipDetached: &boolFalse}},
|
|
|
|
false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"default pointer bool",
|
|
|
|
Config{Branches: sv.BranchesConfig{SkipDetached: &boolTrue}},
|
|
|
|
Config{Branches: sv.BranchesConfig{SkipDetached: nil}},
|
|
|
|
Config{Branches: sv.BranchesConfig{SkipDetached: &boolTrue}},
|
|
|
|
false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"merge maps",
|
|
|
|
Config{CommitMessage: sv.CommitMessageConfig{
|
|
|
|
Footer: map[string]sv.CommitMessageFooterConfig{"issue": {Key: "jira"}},
|
|
|
|
}},
|
|
|
|
Config{CommitMessage: sv.CommitMessageConfig{
|
|
|
|
Footer: map[string]sv.CommitMessageFooterConfig{"issue2": {Key: "jira2"}},
|
|
|
|
}},
|
|
|
|
Config{CommitMessage: sv.CommitMessageConfig{Footer: map[string]sv.CommitMessageFooterConfig{
|
|
|
|
"issue": {Key: "jira"},
|
|
|
|
"issue2": {Key: "jira2"},
|
|
|
|
}}},
|
|
|
|
false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"default maps",
|
|
|
|
Config{CommitMessage: sv.CommitMessageConfig{
|
|
|
|
Footer: map[string]sv.CommitMessageFooterConfig{"issue": {Key: "jira"}},
|
|
|
|
}},
|
|
|
|
Config{CommitMessage: sv.CommitMessageConfig{
|
|
|
|
Footer: nil,
|
|
|
|
}},
|
|
|
|
Config{CommitMessage: sv.CommitMessageConfig{
|
|
|
|
Footer: map[string]sv.CommitMessageFooterConfig{"issue": {Key: "jira"}},
|
|
|
|
}},
|
|
|
|
false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"merge empty maps",
|
|
|
|
Config{CommitMessage: sv.CommitMessageConfig{
|
|
|
|
Footer: map[string]sv.CommitMessageFooterConfig{"issue": {Key: "jira"}},
|
|
|
|
}},
|
|
|
|
Config{CommitMessage: sv.CommitMessageConfig{
|
|
|
|
Footer: map[string]sv.CommitMessageFooterConfig{},
|
|
|
|
}},
|
|
|
|
Config{CommitMessage: sv.CommitMessageConfig{
|
|
|
|
Footer: map[string]sv.CommitMessageFooterConfig{"issue": {Key: "jira"}},
|
|
|
|
}},
|
|
|
|
false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"overwrite tag config",
|
|
|
|
Config{
|
|
|
|
Version: "a",
|
2023-10-15 19:29:29 +00:00
|
|
|
Tag: TagConfig{
|
2023-10-12 14:18:25 +00:00
|
|
|
Pattern: &nonEmptyStr,
|
|
|
|
Filter: &nonEmptyStr,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Config{
|
|
|
|
Version: "",
|
2023-10-15 19:29:29 +00:00
|
|
|
Tag: TagConfig{
|
2023-10-12 14:18:25 +00:00
|
|
|
Pattern: &emptyStr,
|
|
|
|
Filter: &emptyStr,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Config{
|
|
|
|
Version: "a",
|
2023-10-15 19:29:29 +00:00
|
|
|
Tag: TagConfig{
|
2023-10-12 14:18:25 +00:00
|
|
|
Pattern: &emptyStr,
|
|
|
|
Filter: &emptyStr,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
false,
|
|
|
|
},
|
2021-04-13 01:19:36 +00:00
|
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
|
|
if err := merge(&tt.dst, tt.src); (err != nil) != tt.wantErr {
|
|
|
|
t.Errorf("merge() error = %v, wantErr %v", err, tt.wantErr)
|
|
|
|
}
|
2024-02-12 08:09:42 +00:00
|
|
|
|
2021-04-13 01:19:36 +00:00
|
|
|
if !reflect.DeepEqual(tt.dst, tt.want) {
|
|
|
|
t.Errorf("merge() = %v, want %v", tt.dst, tt.want)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|