Top AI Repos — open-source AI, indexed and scored
Top AI Repos tracks AI repositories on GitHub and answers two different questions about each one: is it moving right now, and would you bet a product on it.
Top AI Repos tracks AI repositories on GitHub and answers two different questions about each one: is it moving right now, and would you bet a product on it.
Ruby on Rails like test fixtures for Go. Write tests against a real database
| Date | Stars |
|---|---|
| 2026-07-24 | 1233 |
| 2026-07-25 | 1233 |
| 2026-07-28 | 1233 |
| 2026-07-30 | 1233 |
| 2026-08-06 | 1233 |
Today
— stars today
This week
— stars this week
This month
— stars this month
Momentum
0.0
growth rate 0.00%/day
# testfixtures
[](https://pkg.go.dev/github.com/go-testfixtures/testfixtures/v3?tab=doc)
> [!WARNING]
> This package will wipe the database data before loading the
fixtures! It is supposed to be used on a test database. Please, double check
if you are running it against the correct database.
> [!NOTE]
> There are options not described in this README page. It's
> recommended that you also check [the documentation][doc].
Writing tests is hard, even more when you have to deal with an SQL database.
This package aims to make writing functional tests for web apps written in
Go easier.
Basically this package mimics the ["Ruby on Rails' way"][railstests] of writing tests
for database applications, where sample data is kept in fixtures files. Before
the execution of every test, the test database is cleaned and the fixture data
is loaded into the database.
The idea is running tests against a real database, instead of relying in mocks,
which is boring to setup and may lead to production bugs not being caught in
the tests.
## Installation
First, import it like this:
```go
import (
"github.com/go-testfixtures/testfixtures/v3"
)
```
## Usage
Create a folder for the fixture files. Each file should contain data for a
single table and have the name `<table_name>.yml`:
```
myapp/
myapp.go
myapp_test.go
...
fixtures/
posts.yml
comments.yml
tags.yml
posts_tags.yml
...
```
The file would look like this (it can have as many record you want):
```yml
# comments.yml
- id: 1
post_id: 1
content: A comment...
author_name: John Doe
author_email: [email protected]
created_at: 2020-12-31 23:59:59
updated_at: 2020-12-31 23:59:59
- id: 2
post_id: 2
content: Another comment...
author_name: John Doe
author_email: [email protected]
created_at: 2020-12-31 23:59:59
updated_at: 2020-12-31 23:59:59
# ...
```
An YAML object or array will be converted to JSON. It will be stored on a native
JSON type like JSONB on PostgreSQL & CockroachDB or as a TEXT or VARCHAR column on other
databases.
```yml
- id: 1
post_attributes:
author: John Due
author_email: [email protected]
title: "..."
tags:
- programming
- go
- testing
post: "..."
```
Binary columns can be represented as hexadecimal strings (should start with `0x` and will be automatically converted to `[]byte`):
```yaml
- id: 1
binary_column: 0x1234567890abcdef
```
String values matching date/time formats (e.g., "2025-08-15", "20250815", "15/08/2025") will be automatically converted to `time.Time`. [See supported formats in time.go](https://github.com/go-testfixtures/testfixtures/blob/master/time.go#L8C1-L27C2). Use `RAW=` prefix to prevent conversion:
```yaml
- id: 1
created_at: 2025-08-15 # Will be converted to time.Time
updated_at: RAW=20250815 # Will remain as string
```
If you need to write raw SQL, probably to call a function, prefix the value
of the column with `RAW=`:
```yml
- id: 1
uuid_column: RAW=uuid_generate_v4()
postgis_type_column: RAW=ST_GeomFromText('params...')
created_at: RAW=NOW()
updated_at: RAW=NOW()
```
Your tests would look like this:
```go
package myapp
import (
"database/sql"
_ "github.com/lib/pq"
"github.com/go-testfixtures/testfixtures/v3"
)
var (
db *sql.DB
fixtures *testfixtures.Loader
)
func TestMain(m *testing.M) {
var err error
// Open connection to the test database.
// Do NOT import fixtures in a production database!
// Existing data would be deleted.
db, err = sql.Open("postgres", "dbname=myapp_test")
if err != nil {
...
}
fixtures, err = testfixtures.New(
testfixtures.Database(db), // You database connection
testfixtures.Dialect("postgres"), // Available: "postgresql", "timescaledb", "mysql", "mariadb", "sqlitExcerpt of 16,892 characters
Read on GitHubAndrey Nering · @charmbracelet · Brazil
323
114
26
3
3
3
3
3
2
@go-vikunja · Germany
2
2
2
2
2
2
1
1
1
1
1
Would you bet a product on this? Bounded 0–100 and slow moving.
matched fp:3be7fd533188a021, topic:testing