File tree Expand file tree Collapse file tree 2 files changed +45
-4
lines changed
Expand file tree Collapse file tree 2 files changed +45
-4
lines changed Original file line number Diff line number Diff line change @@ -120,13 +120,14 @@ func (m *Message) GetExtension(name string) interface{} {
120120}
121121
122122// Finish marks the message to be forgotten.
123- // If err is nil, the underlying Psubsub message will be acked;
124- // otherwise nacked.
123+ // If err is nil, the underlying Pubsub message will be acked;
124+ // otherwise nacked and return the error .
125125func (m * Message ) Finish (err error ) error {
126126 if err != nil {
127127 m .internal .Nack ()
128- } else {
129- m .internal .Ack ()
128+ return err
130129 }
130+
131+ m .internal .Ack ()
131132 return nil
132133}
Original file line number Diff line number Diff line change @@ -7,6 +7,7 @@ package pubsub
77
88import (
99 "context"
10+ "fmt"
1011 "testing"
1112
1213 "cloud.google.com/go/pubsub"
@@ -45,3 +46,42 @@ func TestReadStructured(t *testing.T) {
4546 })
4647 }
4748}
49+
50+ func TestFinish (t * testing.T ) {
51+ tests := []struct {
52+ name string
53+ pm * pubsub.Message
54+ err error
55+ wantErr bool
56+ }{
57+ {
58+ name : "return error" ,
59+ pm : & pubsub.Message {
60+ ID : "testid" ,
61+ },
62+ err : fmt .Errorf ("error" ),
63+ wantErr : true ,
64+ },
65+ {
66+ name : "no errors" ,
67+ pm : & pubsub.Message {
68+ ID : "testid" ,
69+ },
70+ wantErr : false ,
71+ },
72+ }
73+ for _ , tc := range tests {
74+ t .Run (tc .name , func (t * testing.T ) {
75+ msg := NewMessage (tc .pm )
76+ err := msg .Finish (tc .err )
77+ if tc .wantErr {
78+ if err != tc .err {
79+ t .Errorf ("Error mismatch. got: %v, want: %v" , err , tc .err )
80+ }
81+ }
82+ if ! tc .wantErr && err != nil {
83+ t .Errorf ("Should not error but got: %v" , err )
84+ }
85+ })
86+ }
87+ }
You can’t perform that action at this time.
0 commit comments