feat(release): v0.1.0
commit06ed2c3cbeAuthor: adminoo <git@kadath.corp> Date: Tue Feb 3 11:34:24 2026 +0100 fix: changed detected by scanner but no updated by render layer commit01dcaf882aAuthor: adminoo <git@kadath.corp> Date: Tue Feb 3 10:19:05 2026 +0100 feat: VERSION bumb commit229223f77aAuthor: adminoo <git@kadath.corp> Date: Tue Feb 3 09:53:08 2026 +0100 feat: filter and search by tag commitcb11e34798Author: adminoo <git@kadath.corp> Date: Tue Feb 3 09:41:03 2026 +0100 feat: tag system commit3f5cf0d673Author: adminoo <git@kadath.corp> Date: Tue Feb 3 09:15:29 2026 +0100 feat: sqlite storage draft commitd6617cec02Author: adminoo <git@kadath.corp> Date: Tue Feb 3 09:04:11 2026 +0100 feat: metadata draft commit7238d02a13Author: adminoo <git@kadath.corp> Date: Mon Feb 2 10:18:42 2026 +0100 fix: body overflowing commit16ff836274Author: adminoo <git@kadath.corp> Date: Mon Feb 2 10:09:01 2026 +0100 feat: tests for http handlers and render package commit36ac3f03aaAuthor: adminoo <git@kadath.corp> Date: Mon Feb 2 09:45:29 2026 +0100 feat: Dark theme, placeholder metadata panel commite6923fa4f5Author: adminoo <git@kadath.corp> Date: Sun Feb 1 18:26:59 2026 +0100 fix: uneeded func + uneeded bogus note creation logic commit4458ba2d15Author: adminoo <git@kadath.corp> Date: Sun Feb 1 18:26:21 2026 +0100 feat: log when changing note states commit92a6f84540Author: adminoo <git@kadath.corp> Date: Sun Feb 1 16:55:40 2026 +0100 possibly first working draft commite27aadc603Author: adminoo <git@kadath.corp> Date: Sun Feb 1 11:55:16 2026 +0100 draft shits
This commit is contained in:
238
internal/storage/sqlite_test.go
Normal file
238
internal/storage/sqlite_test.go
Normal file
@ -0,0 +1,238 @@
|
||||
package storage
|
||||
|
||||
import (
|
||||
"path/filepath"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"donniemarko/internal/note"
|
||||
)
|
||||
|
||||
func newSQLiteStorage(t *testing.T) *SQLiteStorage {
|
||||
t.Helper()
|
||||
|
||||
dbPath := filepath.Join(t.TempDir(), "notes.db")
|
||||
st, err := NewSQLiteStorage(dbPath)
|
||||
if err != nil {
|
||||
t.Fatalf("new sqlite storage: %v", err)
|
||||
}
|
||||
t.Cleanup(func() {
|
||||
_ = st.Close()
|
||||
})
|
||||
|
||||
return st
|
||||
}
|
||||
|
||||
func sampleNote(id, path, title, content string, tstamp time.Time) *note.Note {
|
||||
return ¬e.Note{
|
||||
ID: id,
|
||||
Path: path,
|
||||
Title: title,
|
||||
Content: content,
|
||||
UpdatedAt: tstamp.Add(2 * time.Hour),
|
||||
Size: int64(len(content)),
|
||||
Published: true,
|
||||
}
|
||||
}
|
||||
|
||||
func TestSQLiteStorage_CreateGet(t *testing.T) {
|
||||
st := newSQLiteStorage(t)
|
||||
|
||||
ts := time.Date(2026, 2, 3, 12, 0, 0, 0, time.UTC)
|
||||
n := sampleNote("n1", "notes/alpha.md", "Alpha", "# Alpha", ts)
|
||||
|
||||
if err := st.Create(n); err != nil {
|
||||
t.Fatalf("create note: %v", err)
|
||||
}
|
||||
|
||||
got, err := st.Get("n1")
|
||||
if err != nil {
|
||||
t.Fatalf("get note: %v", err)
|
||||
}
|
||||
|
||||
if got.Title != n.Title || got.Path != n.Path || got.Content != n.Content {
|
||||
t.Fatalf("unexpected note fields: %+v", got)
|
||||
}
|
||||
if !got.UpdatedAt.Equal(n.UpdatedAt) || got.Size != n.Size {
|
||||
t.Fatalf("unexpected time fields: %+v", got)
|
||||
}
|
||||
if !got.Published {
|
||||
t.Fatalf("expected published to be true")
|
||||
}
|
||||
}
|
||||
|
||||
func TestSQLiteStorage_GetAll(t *testing.T) {
|
||||
st := newSQLiteStorage(t)
|
||||
|
||||
ts := time.Date(2026, 2, 3, 12, 0, 0, 0, time.UTC)
|
||||
if err := st.Create(sampleNote("n1", "notes/alpha.md", "Alpha", "one", ts)); err != nil {
|
||||
t.Fatalf("create note: %v", err)
|
||||
}
|
||||
if err := st.Create(sampleNote("n2", "notes/beta.md", "Beta", "two", ts)); err != nil {
|
||||
t.Fatalf("create note: %v", err)
|
||||
}
|
||||
|
||||
all := st.GetAll()
|
||||
if len(all) != 2 {
|
||||
t.Fatalf("expected 2 notes, got %d", len(all))
|
||||
}
|
||||
}
|
||||
|
||||
func TestSQLiteStorage_Update(t *testing.T) {
|
||||
st := newSQLiteStorage(t)
|
||||
|
||||
ts := time.Date(2026, 2, 3, 12, 0, 0, 0, time.UTC)
|
||||
n := sampleNote("n1", "notes/alpha.md", "Alpha", "one", ts)
|
||||
if err := st.Create(n); err != nil {
|
||||
t.Fatalf("create note: %v", err)
|
||||
}
|
||||
|
||||
updated := sampleNote("n1", "notes/alpha.md", "Alpha Updated", "two", ts.Add(24*time.Hour))
|
||||
st.Update("n1", updated)
|
||||
|
||||
got, err := st.Get("n1")
|
||||
if err != nil {
|
||||
t.Fatalf("get note: %v", err)
|
||||
}
|
||||
if got.Title != "Alpha Updated" || got.Content != "two" {
|
||||
t.Fatalf("update did not persist: %+v", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSQLiteStorage_Delete(t *testing.T) {
|
||||
st := newSQLiteStorage(t)
|
||||
|
||||
ts := time.Date(2026, 2, 3, 12, 0, 0, 0, time.UTC)
|
||||
if err := st.Create(sampleNote("n1", "notes/alpha.md", "Alpha", "one", ts)); err != nil {
|
||||
t.Fatalf("create note: %v", err)
|
||||
}
|
||||
|
||||
st.Delete("n1")
|
||||
|
||||
if st.Count() != 0 {
|
||||
t.Fatalf("expected count 0 after delete")
|
||||
}
|
||||
|
||||
if _, err := st.Get("n1"); err == nil {
|
||||
t.Fatalf("expected error for missing note")
|
||||
}
|
||||
}
|
||||
|
||||
func TestSQLiteStorage_Search(t *testing.T) {
|
||||
st := newSQLiteStorage(t)
|
||||
|
||||
ts := time.Date(2026, 2, 3, 12, 0, 0, 0, time.UTC)
|
||||
if err := st.Create(sampleNote("n1", "notes/alpha.md", "Alpha", "Rust tips", ts)); err != nil {
|
||||
t.Fatalf("create note: %v", err)
|
||||
}
|
||||
if err := st.Create(sampleNote("n2", "notes/beta.md", "Beta", "Golang tutorial", ts)); err != nil {
|
||||
t.Fatalf("create note: %v", err)
|
||||
}
|
||||
|
||||
results := st.Search("rust")
|
||||
if len(results) != 1 {
|
||||
t.Fatalf("expected 1 result, got %d", len(results))
|
||||
}
|
||||
if results[0].ID != "n1" {
|
||||
t.Fatalf("expected rust match to be n1")
|
||||
}
|
||||
}
|
||||
|
||||
func TestSQLiteStorage_Count(t *testing.T) {
|
||||
st := newSQLiteStorage(t)
|
||||
|
||||
if st.Count() != 0 {
|
||||
t.Fatalf("expected empty count to be 0")
|
||||
}
|
||||
|
||||
ts := time.Date(2026, 2, 3, 12, 0, 0, 0, time.UTC)
|
||||
if err := st.Create(sampleNote("n1", "notes/alpha.md", "Alpha", "one", ts)); err != nil {
|
||||
t.Fatalf("create note: %v", err)
|
||||
}
|
||||
if err := st.Create(sampleNote("n2", "notes/beta.md", "Beta", "two", ts)); err != nil {
|
||||
t.Fatalf("create note: %v", err)
|
||||
}
|
||||
|
||||
if st.Count() != 2 {
|
||||
t.Fatalf("expected count 2")
|
||||
}
|
||||
}
|
||||
|
||||
func TestSQLiteStorage_Tags(t *testing.T) {
|
||||
st := newSQLiteStorage(t)
|
||||
|
||||
ts := time.Date(2026, 2, 3, 12, 0, 0, 0, time.UTC)
|
||||
if err := st.Create(sampleNote("n1", "notes/alpha.md", "Alpha", "one", ts)); err != nil {
|
||||
t.Fatalf("create note: %v", err)
|
||||
}
|
||||
|
||||
if err := st.AddTag("n1", "go"); err != nil {
|
||||
t.Fatalf("add tag: %v", err)
|
||||
}
|
||||
if err := st.AddTag("n1", "rust"); err != nil {
|
||||
t.Fatalf("add tag: %v", err)
|
||||
}
|
||||
|
||||
tags := st.GetTags("n1")
|
||||
if len(tags) != 2 {
|
||||
t.Fatalf("expected 2 tags, got %d", len(tags))
|
||||
}
|
||||
|
||||
if err := st.RemoveTag("n1", "go"); err != nil {
|
||||
t.Fatalf("remove tag: %v", err)
|
||||
}
|
||||
|
||||
tags = st.GetTags("n1")
|
||||
if len(tags) != 1 || tags[0] != "rust" {
|
||||
t.Fatalf("expected remaining tag rust, got %+v", tags)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSQLiteStorage_SearchByTag(t *testing.T) {
|
||||
st := newSQLiteStorage(t)
|
||||
|
||||
ts := time.Date(2026, 2, 3, 12, 0, 0, 0, time.UTC)
|
||||
if err := st.Create(sampleNote("n1", "notes/alpha.md", "Alpha", "no match", ts)); err != nil {
|
||||
t.Fatalf("create note: %v", err)
|
||||
}
|
||||
if err := st.Create(sampleNote("n2", "notes/beta.md", "Beta", "content", ts)); err != nil {
|
||||
t.Fatalf("create note: %v", err)
|
||||
}
|
||||
|
||||
if err := st.AddTag("n2", "Go"); err != nil {
|
||||
t.Fatalf("add tag: %v", err)
|
||||
}
|
||||
|
||||
results := st.Search("go")
|
||||
if len(results) != 1 {
|
||||
t.Fatalf("expected 1 result, got %d", len(results))
|
||||
}
|
||||
if results[0].ID != "n2" {
|
||||
t.Fatalf("expected tag match to be n2")
|
||||
}
|
||||
}
|
||||
|
||||
func TestSQLiteStorage_Create_Upsert(t *testing.T) {
|
||||
st := newSQLiteStorage(t)
|
||||
|
||||
ts := time.Date(2026, 2, 3, 12, 0, 0, 0, time.UTC)
|
||||
n := sampleNote("n1", "notes/alpha.md", "Alpha", "one", ts)
|
||||
if err := st.Create(n); err != nil {
|
||||
t.Fatalf("create note: %v", err)
|
||||
}
|
||||
|
||||
n.Content = "updated"
|
||||
n.Title = "Alpha Updated"
|
||||
n.UpdatedAt = ts.Add(2 * time.Hour)
|
||||
if err := st.Create(n); err != nil {
|
||||
t.Fatalf("upsert note: %v", err)
|
||||
}
|
||||
|
||||
got, err := st.Get("n1")
|
||||
if err != nil {
|
||||
t.Fatalf("get note: %v", err)
|
||||
}
|
||||
if got.Title != "Alpha Updated" || got.Content != "updated" {
|
||||
t.Fatalf("expected note to be updated, got %+v", got)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user