summaryrefslogtreecommitdiff
path: root/internal/storage/db_test.go
blob: 5415235d1ed353098668225d396a011f1f0897a0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package storage

import (
	"context"
	"errors"
	"os"
	"path/filepath"
	"testing"
)

func TestOpen_ContextCanceled(t *testing.T) {
	ctx, cancel := context.WithCancel(context.Background())
	cancel()
	path := filepath.Join(t.TempDir(), "records.db")
	_, err := Open(ctx, path)
	if err == nil {
		t.Fatal("expected error")
	}
	if !errors.Is(err, context.Canceled) {
		t.Fatalf("expected context.Canceled, got %v", err)
	}
}

func TestOpen_PingFailsOnDirectoryPath(t *testing.T) {
	ctx := context.Background()
	dir := filepath.Join(t.TempDir(), "isdir")
	if err := os.Mkdir(dir, 0o755); err != nil {
		t.Fatal(err)
	}
	_, err := Open(ctx, dir)
	if err == nil {
		t.Fatal("expected error opening sqlite at directory path")
	}
}