package dbsync

import "testing"

func TestNormalizeSQLiteDSN(t *testing.T) {
	got := normalizeSQLiteDSN(`file:E:\data\remote.db`)
	if got != "file:E:/data/remote.db?_pragma=busy_timeout(5000)" {
		t.Fatalf("got %q", got)
	}
	got = normalizeSQLiteDSN(`E:\data\remote.db`)
	if got != "file:E:/data/remote.db?_pragma=busy_timeout(5000)" {
		t.Fatalf("bare path got %q", got)
	}
	got = normalizeSQLiteDSN(`file:E:/data/remote.db?_pragma=foreign_keys(1)`)
	if got != "file:E:/data/remote.db?_pragma=foreign_keys(1)&_pragma=busy_timeout(5000)" {
		t.Fatalf("keep query got %q", got)
	}
}

func TestIsRetryable(t *testing.T) {
	if !IsRetryable(Retryable("x")) {
		t.Fatal("expected retryable")
	}
	if IsRetryable(fmtError("plain")) {
		t.Fatal("plain should not")
	}
}

type fmtError string

func (e fmtError) Error() string { return string(e) }
