From df5ee9d654bb133a0f85a9ba942841b6c64d90c3 Mon Sep 17 00:00:00 2001 From: arraykeys Date: Mon, 8 Jan 2024 16:50:16 +0800 Subject: [PATCH] gfile --- util/file/file.go | 6 ------ util/file/file_test.go | 34 ---------------------------------- 2 files changed, 40 deletions(-) diff --git a/util/file/file.go b/util/file/file.go index 7b56e671..aee31da7 100644 --- a/util/file/file.go +++ b/util/file/file.go @@ -156,12 +156,6 @@ func Bytes(file string) (d []byte) { return } -// Content returns the contents of file, -// if read fail, returns "". -func Content(file string) (d string) { - return string(Bytes(file)) -} - // Write writes []byte to file. func Write(file string, data []byte, append bool) (err error) { mode := os.O_CREATE | os.O_WRONLY diff --git a/util/file/file_test.go b/util/file/file_test.go index 8fb2d871..3a228dda 100644 --- a/util/file/file_test.go +++ b/util/file/file_test.go @@ -178,37 +178,3 @@ func TestCopyFile(t *testing.T) { t.Logf("Expected error: %v", err) } } - -func TestContent(t *testing.T) { - // Create a temporary file for testing - content := "This is a test file content." - tmpFile, err := ioutil.TempFile("", "testfile.txt") - if err != nil { - t.Fatal(err) - } - defer os.Remove(tmpFile.Name()) - - // Write content to the temporary file - _, err = tmpFile.WriteString(content) - if err != nil { - t.Fatal(err) - } - tmpFile.Close() - - // Run the Content function with the temporary file - result := Content(tmpFile.Name()) - - // Check if the result matches the expected content - if result != content { - t.Errorf("Content(%s) = %s, want %s", tmpFile.Name(), result, content) - } - - // Test case for a non-existing file - nonExistentFile := "nonexistentfile.txt" - result = Content(nonExistentFile) - - // Check if the result is an empty string for a non-existing file - if result != "" { - t.Errorf("Content(%s) = %s, want %s", nonExistentFile, result, "") - } -}