From ded0dc877977df50e9f35fc6ad136c28f018c127 Mon Sep 17 00:00:00 2001 From: Theis Date: Mon, 4 Mar 2024 22:47:23 +0100 Subject: [PATCH] added a test for excluding users --- src_code/go_src/cocommit_test.go | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/src_code/go_src/cocommit_test.go b/src_code/go_src/cocommit_test.go index f6bb5a9..cf08549 100644 --- a/src_code/go_src/cocommit_test.go +++ b/src_code/go_src/cocommit_test.go @@ -3,6 +3,7 @@ package main import ( "os" "os/exec" + "strings" "testing" ) @@ -53,6 +54,7 @@ func Test_add_all(t *testing.T) { for k := range users { delete(users, k) } + sb.Reset() users["test1"] = user{username: "test1", email: "test1"} users["test2"] = user{username: "test2", email: "test2"} users["test3"] = user{username: "test3", email: "test3"} @@ -60,13 +62,26 @@ func Test_add_all(t *testing.T) { add_x_users([]string{}) commit := sb_build() - - if commit != "\nCo-authored-by: test \nCo-authored-by: test1 \nCo-authored-by: test2 \nCo-authored-by: test3 " { + if !strings.Contains(commit, "\nCo-authored-by: test1 ") || + !strings.Contains(commit, "\nCo-authored-by: test2 ") || + !strings.Contains(commit, "\nCo-authored-by: test3 ") { t.Fatalf("String built incorrectly. Strings did not match: Created -> %s Expected -> Co-authored-by: test ",commit) } } - +func Test_exclude_user(t *testing.T) { + // Reusing users map from last test + excludeMode := []string{"test1"} + + sb.Reset() + + add_x_users(excludeMode) + + commit := sb_build() + if strings.Contains(commit, "\nCo-authored-by: test1 ") { + t.Fatalf("String built incorrectly. Strings did not match: Created -> %s Expected -> Co-authored-by: test ",commit) + } +}