diff --git a/ops/gas_init_test.sh b/ops/gas_init_test.sh index 50d8c90..205138d 100755 --- a/ops/gas_init_test.sh +++ b/ops/gas_init_test.sh @@ -41,6 +41,7 @@ create table items ( rowid integer primary key, description text not null default '', flavor integer references item_flavor(rowid), + data blob not null, thing text not null unique, created_at integer not null, updated_at integer not null diff --git a/pkg/codegen/modelgenerate/generate_testfile.go b/pkg/codegen/modelgenerate/generate_testfile.go index ff9e181..94fc996 100644 --- a/pkg/codegen/modelgenerate/generate_testfile.go +++ b/pkg/codegen/modelgenerate/generate_testfile.go @@ -32,6 +32,24 @@ func GenerateModelTestAST(tbl pkgschema.Table, schema pkgschema.Schema, gomodNam Results: []ast.Expr{ &ast.CompositeLit{ 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") testObj2 := ast.NewIdent("item2") - fieldName := ast.NewIdent("Description") + fieldName := ast.NewIdent("Description") // TODO description1 := `"an item"` description2 := `"a big item"` testDB := ast.NewIdent("TestDB") @@ -72,19 +90,27 @@ func GenerateModelTestAST(tbl pkgschema.Table, schema pkgschema.Schema, gomodNam stmts := []ast.Stmt{ Comment("Create"), - // item := Item{Description: "an item"} + // item := MakeItem() &ast.AssignStmt{ Lhs: []ast.Expr{testObj}, Tok: token.DEFINE, - Rhs: []ast.Expr{&ast.CompositeLit{ - Type: ast.NewIdent(tbl.GoTypeName), - Elts: []ast.Expr{ - &ast.KeyValueExpr{ - Key: fieldName, - Value: &ast.BasicLit{Kind: token.STRING, Value: description1}, - }, + Rhs: []ast.Expr{&ast.CallExpr{Fun: ast.NewIdent("MakeItem"), Args: nil}}, + }, + // item.Description = "an item" + &ast.AssignStmt{ + Lhs: []ast.Expr{ + &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)