From 9b367ba86ed88940749ed5613ecfd6bea8da3635 Mon Sep 17 00:00:00 2001 From: Slug-Boi Date: Fri, 11 Apr 2025 15:49:02 +0200 Subject: [PATCH] test: create temp file when testing the git commit command --- src/cmd/utils/util_test.go | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/src/cmd/utils/util_test.go b/src/cmd/utils/util_test.go index a3431e0..af52499 100644 --- a/src/cmd/utils/util_test.go +++ b/src/cmd/utils/util_test.go @@ -556,6 +556,26 @@ func Test_GitWrapper(t *testing.T) { defer teardown() utils.Define_users("author_file_test") + // create a temporary file to test git wrapper + tmpFile, err := os.CreateTemp("", "test_git_wrapper") + if err != nil { + t.Fatalf("Failed to create temporary file: %v", err) + } + + defer os.Remove(tmpFile.Name()) + defer tmpFile.Close() + + // Write some content to the temporary file + _, err = tmpFile.WriteString("Test content") + if err != nil { + t.Fatalf("Failed to write to temporary file: %v", err) + } + + // Close the file to flush the content + err = tmpFile.Close() + if err != nil { + t.Fatalf("Failed to close temporary file: %v", err) + } // Test GitWrapper with --dry-run flag authors := []string{"te"} @@ -564,7 +584,7 @@ func Test_GitWrapper(t *testing.T) { commit := utils.Commit(message, authors) flags := []string{"-a","--dry-run"} - err := utils.GitWrapper(commit, flags) + err = utils.GitWrapper(commit, flags) if err != nil { t.Errorf("GitWrapper() returned error: %v", err) }