@@ -785,27 +785,55 @@ func TestStarWalker(t *testing.T) {
785785func TestInvalidQueries (t * testing.T ) {
786786 for i , tc := range []struct {
787787 stmt string
788+ msg string
788789 }{
789790 {
790791 `
791792 CREATE TABLE foo (id text not null);
792793 -- name: ListFoos
793794 SELECT id FROM foo;
794795 ` ,
796+ "invalid query comment: -- name: ListFoos" ,
795797 },
796798 {
797799 `
798800 CREATE TABLE foo (id text not null);
799801 -- name: ListFoos :one :many
800802 SELECT id FROM foo;
801803 ` ,
804+ "invalid query comment: -- name: ListFoos :one :many" ,
802805 },
803806 {
804807 `
805808 CREATE TABLE foo (id text not null);
806809 -- name: ListFoos :two
807810 SELECT id FROM foo;
808811 ` ,
812+ "invalid query type: :two" ,
813+ },
814+ {
815+ `
816+ CREATE TABLE foo (id text not null);
817+ -- name: DeleteFoo :one
818+ DELETE FROM foo WHERE id = $1;
819+ ` ,
820+ `query "DeleteFoo" specifies parameter ":one" without containing a RETURNING clause` ,
821+ },
822+ {
823+ `
824+ CREATE TABLE foo (id text not null);
825+ -- name: UpdateFoo :one
826+ UPDATE foo SET id = $2 WHERE id = $1;
827+ ` ,
828+ `query "UpdateFoo" specifies parameter ":one" without containing a RETURNING clause` ,
829+ },
830+ {
831+ `
832+ CREATE TABLE foo (id text not null);
833+ -- name: InsertFoo :one
834+ INSERT INTO foo (id) VALUES ($1);
835+ ` ,
836+ `query "InsertFoo" specifies parameter ":one" without containing a RETURNING clause` ,
809837 },
810838 } {
811839 test := tc
@@ -814,6 +842,9 @@ func TestInvalidQueries(t *testing.T) {
814842 if err == nil {
815843 t .Errorf ("expected err, got nil" )
816844 }
845+ if diff := cmp .Diff (test .msg , err .Error ()); diff != "" {
846+ t .Errorf ("error message differs: \n %s" , diff )
847+ }
817848 })
818849 }
819850}
0 commit comments