testdb

package
v0.0.18 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 15, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package testdb는 database case 하나가 혼자 쓰는 database(case database)를 만든다.

ORM_TEST_MYSQL_DSN과 ORM_TEST_POSTGRES_DSN이 가리키는 database는 여러 실행과 session이 함께 쓰므로 비어 있다고 가정할 수 없다. schema를 설치하거나 빈 database를 확인하는 case는 New로 자기 database를 만들고, database는 case가 끝날 때(실패한 뒤에도) 지워진다. 공유 DSN은 admin 연결로만 쓰고 그 database에는 아무것도 만들지 않는다.

PostgreSQL도 schema가 아니라 database를 만든다. Empty()는 public이 아닌 schema를 내용으로 세므로 공유 database 안의 case schema로는 빈 database를 확인할 수 없다.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DatabaseOf

func DatabaseOf(t testing.TB, dsn string) string

DatabaseOf는 MySQL이나 PostgreSQL DSN의 database 이름이다.

func Name

func Name() string

Name은 다음 case database 이름 orm_case_<pid>_<번호>를 돌려준다. PgBouncer가 하나의 database에 묶은 case처럼 database를 만들 수 없는 case가 자기 table 이름으로 쓴다.

func New

func New(t testing.TB, driver string) string

New는 driver("sqlite", "mysql", "postgres")의 case database를 만들고 그 DSN을 돌려준다. MySQL과 PostgreSQL은 ORM_TEST_<DRIVER>_DSN의 server에 orm_case_<pid>_<번호> database를 만들고 DSN의 path만 그 이름으로 바꾼다(query는 그대로다). SQLite는 OS temp directory의 새 file orm-case-<pid>-<번호>.sqlite다. 만들고 지운 일은 t를 감싼 case(testcase.Of)의 STEP 줄로 보고하고, 지우기는 t.Cleanup에서 실행되므로 실패한 case 뒤에도 실행된다. 지우지 못하면 database 이름과 함께 case를 실패시킨다.

func Open

func Open(t testing.TB, driver, dsn string) *sql.DB

Open은 MySQL이나 PostgreSQL client DSN의 database를 native database/sql driver로 연다.

func Retarget

func Retarget(t testing.TB, dsn, name string) string

Retarget은 dsn의 path를 database name으로 바꾼 DSN이다. case database를 다른 server (replica)에서 같은 이름으로 열 때 쓴다.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL