Skip to content

An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作

1.3 KB
Raw Blame
// SiYuan - https://github.com/siyuan-note/siyuan
// Copyright (c) 2020-present, b3log.org
// SPDX-License-Identifier: AGPL-3.0-or-later

//go:build fts5

package sql

import "testing"

func TestBookmarkIndexDatabaseInitialization(t *testing.T) {
	for _, encrypted := range []bool{false, true} {
		database := newDeletePathTestDB(t, encrypted)
		for _, name := range []string{"idx_attributes_bookmark_block_id", "idx_spans_tag_path"} {
			var count int
			if err := database.QueryRow("SELECT COUNT(*) FROM sqlite_master WHERE type = 'index' AND name = ?", name).Scan(&count); err != nil {
				t.Fatal(err)
			}
			if count != 1 {
				t.Fatalf("encrypted=%v: index %s missing", encrypted, name)
			}
		}
		if _, err := database.Exec("INSERT INTO attributes VALUES ('bookmark', 'bookmark', '<b>', 'b', 'block', 'root', 'box', '/doc.sy')"); err != nil {
			t.Fatal(err)
		}
		if encrypted {
			if err := initEncryptedDBTables(database); err != nil {
				t.Fatal(err)
			}
		} else if err := ensureBookmarkAttributesIndex(database); err != nil {
			t.Fatal(err)
		}
		var value string
		if err := database.QueryRow("SELECT value FROM attributes WHERE id = 'bookmark'").Scan(&value); err != nil {
			t.Fatal(err)
		}
		if value != "<b>" {
			t.Fatal("index initialization changed stored bookmark data")
		}
	}
}