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{} {
120
120
}
121
121
122
122
// 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 .
125
125
func (m * Message ) Finish (err error ) error {
126
126
if err != nil {
127
127
m .internal .Nack ()
128
- } else {
129
- m .internal .Ack ()
128
+ return err
130
129
}
130
+
131
+ m .internal .Ack ()
131
132
return nil
132
133
}
Original file line number Diff line number Diff line change @@ -7,6 +7,7 @@ package pubsub
7
7
8
8
import (
9
9
"context"
10
+ "fmt"
10
11
"testing"
11
12
12
13
"cloud.google.com/go/pubsub"
@@ -45,3 +46,42 @@ func TestReadStructured(t *testing.T) {
45
46
})
46
47
}
47
48
}
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