@@ -1115,12 +1115,28 @@ func TestUpdateRetryPolicy(t *testing.T) {
11151115 }
11161116}
11171117
1118- func TestUpdateFilter (t * testing.T ) {
1118+ func TestSubscriptionFilter (t * testing.T ) {
11191119 ctx := context .Background ()
11201120 pclient , sclient , _ , cleanup := newFake (ctx , t )
11211121 defer cleanup ()
11221122
11231123 top := mustCreateTopic (ctx , t , pclient , & pb.Topic {Name : "projects/P/topics/T" })
1124+
1125+ // Creating a subscription with invalid filter should return an error.
1126+ _ , err := sclient .CreateSubscription (ctx , & pb.Subscription {
1127+ Name : "projects/p/subscriptions/s" ,
1128+ Topic : top .Name ,
1129+ AckDeadlineSeconds : 30 ,
1130+ EnableMessageOrdering : true ,
1131+ Filter : "bad filter" ,
1132+ })
1133+ if err == nil {
1134+ t .Fatal ("expected bad filter error, got nil" )
1135+ }
1136+ if st := status .Convert (err ); st .Code () != codes .InvalidArgument {
1137+ t .Fatalf ("got err status: %v, want: %v" , st .Code (), codes .InvalidArgument )
1138+ }
1139+
11241140 sub := mustCreateSubscription (ctx , t , sclient , & pb.Subscription {
11251141 AckDeadlineSeconds : minAckDeadlineSecs ,
11261142 Name : "projects/P/subscriptions/S" ,
@@ -1143,6 +1159,19 @@ func TestUpdateFilter(t *testing.T) {
11431159 if got , want := updated .Filter , update .Filter ; got != want {
11441160 t .Fatalf ("got %v, want %v" , got , want )
11451161 }
1162+
1163+ // Updating a subscription with bad filter should return an error.
1164+ update .Filter = "bad filter"
1165+ updated , err = sclient .UpdateSubscription (ctx , & pb.UpdateSubscriptionRequest {
1166+ Subscription : update ,
1167+ UpdateMask : & field_mask.FieldMask {Paths : []string {"filter" }},
1168+ })
1169+ if err == nil {
1170+ t .Fatal ("expected bad filter error, got nil" )
1171+ }
1172+ if st := status .Convert (err ); st .Code () != codes .InvalidArgument {
1173+ t .Fatalf ("got err status: %v, want: %v" , st .Code (), codes .InvalidArgument )
1174+ }
11461175}
11471176
11481177func TestUpdateEnableExactlyOnceDelivery (t * testing.T ) {
0 commit comments