tests: add integration test for blob fields
All checks were successful
CI / build-docker (push) Successful in 6s
CI / build-docker-bootstrap (push) Has been skipped
CI / release-test (push) Successful in 2m24s

This commit is contained in:
~wispem-wantex 2026-02-14 18:33:41 -08:00
parent 29787b5521
commit fcf266eb1d
2 changed files with 37 additions and 10 deletions

View File

@ -41,6 +41,7 @@ create table items (
rowid integer primary key, rowid integer primary key,
description text not null default '', description text not null default '',
flavor integer references item_flavor(rowid), flavor integer references item_flavor(rowid),
data blob not null,
thing text not null unique, thing text not null unique,
created_at integer not null, created_at integer not null,
updated_at integer not null updated_at integer not null

View File

@ -32,6 +32,24 @@ func GenerateModelTestAST(tbl pkgschema.Table, schema pkgschema.Schema, gomodNam
Results: []ast.Expr{ Results: []ast.Expr{
&ast.CompositeLit{ &ast.CompositeLit{
Type: ast.NewIdent(tbl.GoTypeName), Type: ast.NewIdent(tbl.GoTypeName),
Elts: []ast.Expr{
&ast.KeyValueExpr{
Key: ast.NewIdent("Data"),
Value: &ast.CompositeLit{
Type: &ast.ArrayType{
Elt: ast.NewIdent("byte"),
},
Elts: []ast.Expr{},
},
},
&ast.KeyValueExpr{
Key: ast.NewIdent("Description"),
Value: &ast.BasicLit{
Kind: token.STRING,
Value: `""`,
},
},
},
}, },
}, },
}, },
@ -41,7 +59,7 @@ func GenerateModelTestAST(tbl pkgschema.Table, schema pkgschema.Schema, gomodNam
testObj := ast.NewIdent("item") testObj := ast.NewIdent("item")
testObj2 := ast.NewIdent("item2") testObj2 := ast.NewIdent("item2")
fieldName := ast.NewIdent("Description") fieldName := ast.NewIdent("Description") // TODO
description1 := `"an item"` description1 := `"an item"`
description2 := `"a big item"` description2 := `"a big item"`
testDB := ast.NewIdent("TestDB") testDB := ast.NewIdent("TestDB")
@ -72,19 +90,27 @@ func GenerateModelTestAST(tbl pkgschema.Table, schema pkgschema.Schema, gomodNam
stmts := []ast.Stmt{ stmts := []ast.Stmt{
Comment("Create"), Comment("Create"),
// item := Item{Description: "an item"} // item := MakeItem()
&ast.AssignStmt{ &ast.AssignStmt{
Lhs: []ast.Expr{testObj}, Lhs: []ast.Expr{testObj},
Tok: token.DEFINE, Tok: token.DEFINE,
Rhs: []ast.Expr{&ast.CompositeLit{ Rhs: []ast.Expr{&ast.CallExpr{Fun: ast.NewIdent("MakeItem"), Args: nil}},
Type: ast.NewIdent(tbl.GoTypeName), },
Elts: []ast.Expr{ // item.Description = "an item"
&ast.KeyValueExpr{ &ast.AssignStmt{
Key: fieldName, Lhs: []ast.Expr{
Value: &ast.BasicLit{Kind: token.STRING, Value: description1}, &ast.SelectorExpr{
}, X: ast.NewIdent("item"),
Sel: ast.NewIdent("Description"),
}, },
}}, },
Tok: token.ASSIGN,
Rhs: []ast.Expr{
&ast.BasicLit{
Kind: token.STRING,
Value: `"an item"`,
},
},
}, },
// TestDB.SaveItem(&item) // TestDB.SaveItem(&item)