From 27a755ce81ae7ff0b4b8fc153c546f5c7d0ce1b6 Mon Sep 17 00:00:00 2001 From: Theis Date: Wed, 6 Mar 2024 12:47:26 +0100 Subject: [PATCH] test: added a test for grouping --- src_code/go_src/cocommit.go | 19 ++++++++++--------- src_code/go_src/cocommit_test.go | 23 +++++++++++++++++++++++ 2 files changed, 33 insertions(+), 9 deletions(-) diff --git a/src_code/go_src/cocommit.go b/src_code/go_src/cocommit.go index 4f1676d..b059648 100644 --- a/src_code/go_src/cocommit.go +++ b/src_code/go_src/cocommit.go @@ -17,20 +17,22 @@ type user struct { // Map of all th users in the author file var users = make(map[string]user) + // String builder for building the commit message var sb strings.Builder + // Flag that can be toggled to include all users in a commit message (excluding defExclude) var all_flag = false -// DefaultExclude -> A list that contains users marked with ex meaning + +// DefaultExclude -> A list that contains users marked with ex meaning // they should not be included in all and negations var defExclude = []string{} + // Group map for adding people as a group var groups = make(map[string][]user) - func main() { - // Reads a shell env variable :: author_file authors := os.Getenv("author_file") @@ -53,8 +55,8 @@ func main() { if strings.Contains(input_str, ";;") { input := strings.Split(input_str, ";;") input_str = input[0] - group_info = append(group_info, strings.Split(input[1],"|")...) - } + group_info = append(group_info, strings.Split(input[1], "|")...) + } info := strings.Split(input_str, "|") usr := user{username: info[2], email: info[3]} users[info[0]] = usr @@ -70,7 +72,7 @@ func main() { if groups[group] == nil { groups[group] = []user{usr} } else { - //TODO: Try and find a cleaner way of doing this + //TODO: Try and find a cleaner way of doing this usr_lst := groups[group] usr_lst = append(usr_lst, usr) groups[group] = usr_lst @@ -128,14 +130,13 @@ func main() { } // Skip label for adding all - skip_loop: - +skip_loop: + if len(excludeMode) > 0 || all_flag { // adds all users not in the excludeMode list add_x_users(excludeMode) } - // commit msg built commit := sb_build() diff --git a/src_code/go_src/cocommit_test.go b/src_code/go_src/cocommit_test.go index 7113b44..5c62140 100644 --- a/src_code/go_src/cocommit_test.go +++ b/src_code/go_src/cocommit_test.go @@ -98,6 +98,29 @@ func Test_exclude_by_default(t *testing.T) { } } +func Test_commit_with_grouping(t *testing.T) { + for k := range groups { + delete(groups, k) + } + + defExclude = []string{} + + groups["test1"] = []user{users["test1"]} + + excludeMode := group_selection(groups["test1"], []string{}) + + sb.Reset() + + add_x_users(excludeMode) + + commit := sb_build() + + if commit != "\nCo-authored-by: test1 " { + t.Fatalf("String built incorrectly. Strings did not match: Created -> %s Expected -> Co-authored-by: test ",commit) + } + +} +