aboutsummaryrefslogtreecommitdiff
path: root/tests/dedo.go
diff options
context:
space:
mode:
authorEuAndreh <eu@euandre.org>2024-12-30 18:22:57 -0300
committerEuAndreh <eu@euandre.org>2024-12-30 18:22:57 -0300
commit10b782837d7fc359aa52e9cbbef75ab21392425c (patch)
treee118590cfae36c7eb59c5aec0f867b1b375dbbd5 /tests/dedo.go
parentsrc/dedo.go: Move type definitions to the beginning of the file (diff)
downloaddedo-10b782837d7fc359aa52e9cbbef75ab21392425c.tar.gz
dedo-10b782837d7fc359aa52e9cbbef75ab21392425c.tar.xz
src/dedo.go: Remove DB.ReadOnly option
Diffstat (limited to 'tests/dedo.go')
-rw-r--r--tests/dedo.go51
1 files changed, 51 insertions, 0 deletions
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 },