codegen: fix defining the 'err' variable multiple times in foreign key checking test
This commit is contained in:
parent
0f9a57dd85
commit
8c29d455ff
@ -310,11 +310,11 @@ func GenerateModelTestAST(tbl pkgschema.Table, schema pkgschema.Schema, gomodNam
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
shouldDefineErr := true
|
||||||
for _, col := range tbl.Columns {
|
for _, col := range tbl.Columns {
|
||||||
if col.IsForeignKey {
|
if col.IsForeignKey {
|
||||||
shouldIncludeTestFkCheck = true
|
shouldIncludeTestFkCheck = true
|
||||||
stmts = append(stmts, []ast.Stmt{
|
stmts = append(stmts, []ast.Stmt{
|
||||||
|
|
||||||
// post.QuotedPostID = 94354538969386985
|
// post.QuotedPostID = 94354538969386985
|
||||||
&ast.AssignStmt{
|
&ast.AssignStmt{
|
||||||
Lhs: []ast.Expr{
|
Lhs: []ast.Expr{
|
||||||
@ -335,7 +335,7 @@ func GenerateModelTestAST(tbl pkgschema.Table, schema pkgschema.Schema, gomodNam
|
|||||||
// err := db.SavePost(&post)
|
// err := db.SavePost(&post)
|
||||||
&ast.AssignStmt{
|
&ast.AssignStmt{
|
||||||
Lhs: []ast.Expr{ast.NewIdent("err")},
|
Lhs: []ast.Expr{ast.NewIdent("err")},
|
||||||
Tok: token.DEFINE,
|
Tok: map[bool]token.Token{true: token.DEFINE, false: token.ASSIGN}[shouldDefineErr],
|
||||||
Rhs: []ast.Expr{
|
Rhs: []ast.Expr{
|
||||||
&ast.CallExpr{
|
&ast.CallExpr{
|
||||||
Fun: &ast.SelectorExpr{
|
Fun: &ast.SelectorExpr{
|
||||||
@ -371,6 +371,7 @@ func GenerateModelTestAST(tbl pkgschema.Table, schema pkgschema.Schema, gomodNam
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
}...)
|
}...)
|
||||||
|
shouldDefineErr = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return stmts
|
return stmts
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user