test: add unit tests and sample notes
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
package store
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestMemoryNoteStore_CRUD(t *testing.T) {
|
||||
s := NewMemoryNoteStore()
|
||||
ctx := context.Background()
|
||||
|
||||
note := &Note{ID: "test-1", Title: "Test Note", Content: "Hello", Tags: []string{"test"}}
|
||||
if err := s.Create(ctx, note); err != nil {
|
||||
t.Fatalf("Create: %v", err)
|
||||
}
|
||||
|
||||
got, err := s.GetByID(ctx, "test-1")
|
||||
if err != nil {
|
||||
t.Fatalf("GetByID: %v", err)
|
||||
}
|
||||
if got.Title != "Test Note" {
|
||||
t.Errorf("Title = %q, want %q", got.Title, "Test Note")
|
||||
}
|
||||
|
||||
list, err := s.List(ctx)
|
||||
if err != nil || len(list) != 1 {
|
||||
t.Fatalf("List: len=%d, err=%v", len(list), err)
|
||||
}
|
||||
|
||||
if err := s.Delete(ctx, "test-1"); err != nil {
|
||||
t.Fatalf("Delete: %v", err)
|
||||
}
|
||||
_, err = s.GetByID(ctx, "test-1")
|
||||
if err == nil {
|
||||
t.Fatal("expected error after delete")
|
||||
}
|
||||
}
|
||||
|
||||
func TestMemoryNoteStore_SearchByKeyword(t *testing.T) {
|
||||
s := NewMemoryNoteStore()
|
||||
ctx := context.Background()
|
||||
|
||||
s.Create(ctx, &Note{ID: "1", Title: "Go Concurrency", Content: "goroutine patterns"})
|
||||
s.Create(ctx, &Note{ID: "2", Title: "Python Basics", Content: "variables and types"})
|
||||
|
||||
results, err := s.SearchByKeyword(ctx, "goroutine")
|
||||
if err != nil {
|
||||
t.Fatalf("SearchByKeyword: %v", err)
|
||||
}
|
||||
if len(results) != 1 || results[0].ID != "1" {
|
||||
t.Errorf("expected 1 result with ID=1, got %d", len(results))
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user