From 1c1dad1c7d3135cd00f3455c7b3ac18687d10313 Mon Sep 17 00:00:00 2001 From: Ushakov Michale Date: Thu, 7 Nov 2024 17:18:11 +0500 Subject: [PATCH] append seems to be working now --- file_utils_test.go | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/file_utils_test.go b/file_utils_test.go index 75f8335..dde6dad 100644 --- a/file_utils_test.go +++ b/file_utils_test.go @@ -105,7 +105,7 @@ func TestWriteAllLines(t *testing.T) { " \"name\": \"Michael Ushakov\"", "}", } - testFile := "sample_test.txt" + testFile := "write_all_lines_test.txt" err := gfu.WriteAllLines(testFile, lines, "\n") assert.NoError(t, err) readLines, err := gfu.ReadAllLines(testFile, true) @@ -115,5 +115,34 @@ func TestWriteAllLines(t *testing.T) { } func TestAppendAllLines(t *testing.T) { + lines := []string{ + "Line one", + "Line two", + "Line three", + "Line four", + "{", + " \"id\": 1,", + " \"name\": \"Michael Ushakov\"", + "}", + } + testFile := "append_all_lines_test.txt" + err := gfu.WriteAllLines(testFile, lines, "\n") + assert.NoError(t, err) + + appendingLines := []string{ + "Line five", + "Line six", + "This is the simplest demo page

Main page header

", + "Line seven", + } + err = gfu.AppendAllLines(testFile, appendingLines, "\n") + assert.NoError(t, err) + expectedLines := make([]string, 0) + expectedLines = append(expectedLines, lines...) + expectedLines = append(expectedLines, appendingLines...) + actualLines, err := gfu.ReadAllLines(testFile, true) + assert.NoError(t, err) + testingutils.CheckStrings(t, expectedLines, actualLines, true, true) + _ = os.Remove(testFile) }