@@ -86,7 +86,6 @@ func TestFunctionContext_NewOutputMessage(t *testing.T) {
8686}
8787
8888func TestFunctionContext_NewOutputMessageWithError (t * testing.T ) {
89-
9089 testCases := []struct {
9190 name string
9291 outputFunc func (topic string ) (pulsar.Producer , error )
@@ -102,7 +101,7 @@ func TestFunctionContext_NewOutputMessageWithError(t *testing.T) {
102101 {
103102 name : "Test error" ,
104103 outputFunc : func (topic string ) (pulsar.Producer , error ) { return nil , errors .New ("test error" ) },
105- expectedError : false ,
104+ expectedError : true ,
106105 expectedProducerType : nil ,
107106 },
108107 }
@@ -113,12 +112,14 @@ func TestFunctionContext_NewOutputMessageWithError(t *testing.T) {
113112 fc := NewFuncContext ()
114113 publishTopic := "publish-topic"
115114
116- fc .outputMessageWithError = func (topic string ) (pulsar.Producer , error ) {
117- return & MockPulsarProducer {}, nil
118- }
115+ fc .outputMessageWithError = testCase .outputFunc
119116
120117 actualProducer , err := fc .NewOutputMessageWithError (publishTopic )
121- assert .IsType (t , testCase .expectedProducerType , actualProducer )
118+ if testCase .expectedProducerType == nil {
119+ assert .Nil (t , actualProducer )
120+ } else {
121+ assert .IsType (t , testCase .expectedProducerType , actualProducer )
122+ }
122123 assert .Equal (t , testCase .expectedError , err != nil )
123124 })
124125 }
0 commit comments