From 10b782837d7fc359aa52e9cbbef75ab21392425c Mon Sep 17 00:00:00 2001 From: EuAndreh Date: Mon, 30 Dec 2024 18:22:57 -0300 Subject: src/dedo.go: Remove DB.ReadOnly option --- tests/dedo.go | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) (limited to 'tests/dedo.go') diff --git a/tests/dedo.go b/tests/dedo.go index 94f34de..719194e 100644 --- a/tests/dedo.go +++ b/tests/dedo.go @@ -25,8 +25,57 @@ import ( "testing/quick" "time" "unsafe" + + g "gobang" ) + + +func test_openFile() { + g.TestStart("openFile()") + + g.Testing("error when parent directory does not exist", func() { + path := tempfile() + tempfile() + defer os.Remove(path) + + _, err := openFile(path) + g.TErrorNil(err) + }) + + g.Testing("success when file doesn't exist yet", func() { + path := tempfile() + defer os.Remove(path) + + file, err := openFile(path) + defer file.Close() + g.TErrorIf(err) + }) + + g.Testing("success when file is read/write", func() { + path := tempfile() + defer os.Remove(path) + + file, err := os.OpenFile(path, os.O_CREATE, 0o600) + g.TErrorIf(err) + file.Close() + + _, err = openFile(path) + g.TErrorIf(err) + }) + + g.Testing("success when file is read-only", func() { + path := tempfile() + defer os.Remove(path) + + file, err := os.OpenFile(path, os.O_CREATE, 0o400) + g.TErrorIf(err) + file.Close() + + _, err = openFile(path) + g.TErrorIf(err) + }) +} + // Ensure that a bucket that gets a non-existent key returns nil. func TestBucket_Get_NonExistent(t *testing.T) { db := MustOpenDB() @@ -6211,6 +6260,8 @@ func walkBucket(parent *Bucket, k []byte, v []byte, w io.Writer) error { func MainTest() { tempdir = getTempdir() + test_openFile() + tests := []testing.InternalTest{ { "TestBucket_Get_NonExistent", TestBucket_Get_NonExistent }, { "TestBucket_Get_FromNode", TestBucket_Get_FromNode }, -- cgit v1.2.3