| 1 | package mqtt_testscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/testing/integration/mqtt_test`/ |
| 2 | |
| 3 | import ( |
| 4 | "contextscip-go gomod github.com/golang/go/src . context/" |
| 5 | "net/urlscip-go gomod github.com/golang/go/src . `net/url`/" |
| 6 | "testingscip-go gomod github.com/golang/go/src . testing/" |
| 7 | |
| 8 | "github.com/eclipse/paho.golang/pahoscip-go gomod github.com/eclipse/paho.golang v0.23.0 `github.com/eclipse/paho.golang/paho`/" |
| 9 | "github.com/stretchr/testify/mockscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/mock`/" |
| 10 | "github.com/stretchr/testify/requirescip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/" |
| 11 | |
| 12 | "github.com/nicholas-fedor/shoutrrr/pkg/services/push/mqttscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/mqtt`/" |
| 13 | "github.com/nicholas-fedor/shoutrrr/pkg/typesscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/types`/" |
| 14 | ) |
| 15 | |
| 16 | // MockConnectionManager is a testify mock that implements the ConnectionManager interface. |
| 17 | type MockConnectionManagerscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/testing/integration/mqtt_test`/MockConnectionManager# struct { |
| 18 | mockscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/mock`/.Mockscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/testing/integration/mqtt_test`/MockConnectionManager#Mock. |
| 19 | } |
| 20 | |
| 21 | // mockLogger is a simple logger implementation for testing. |
| 22 | type mockLoggerscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/testing/integration/mqtt_test`/mockLogger# struct{} |
| 23 | |
| 24 | // publishMethodName is the constant for the Publish method to avoid string duplication. |
| 25 | const publishMethodNamescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/testing/integration/mqtt_test`/publishMethodName. = "Publish" |
| 26 | |
| 27 | func (m *mockLoggerscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/testing/integration/mqtt_test`/mockLogger#) Printscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/testing/integration/mqtt_test`/mockLogger#Print().(_ ...any) {} |
| 28 | func (m *mockLoggerscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/testing/integration/mqtt_test`/mockLogger#) Printfscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/testing/integration/mqtt_test`/mockLogger#Printf().(_ string, _ ...any) {} |
| 29 | func (m *mockLoggerscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/testing/integration/mqtt_test`/mockLogger#) Printlnscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/testing/integration/mqtt_test`/mockLogger#Println().(_ ...any) {} |
| 30 | |
| 31 | // AwaitConnection mocks waiting for the MQTT connection to be established. |
| 32 | func (m *MockConnectionManagerscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/testing/integration/mqtt_test`/MockConnectionManager#) AwaitConnectionscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/testing/integration/mqtt_test`/MockConnectionManager#AwaitConnection().(ctx contextscip-go gomod github.com/golang/go/src . context/.Contextscip-go gomod github.com/golang/go/src . context/Context#) error { |
| 33 | args := m.Calledscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/mock`/Mock#Called().(ctx) |
| 34 | |
| 35 | return args.Errorscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/mock`/Arguments#Error().(0) |
| 36 | } |
| 37 | |
| 38 | // Disconnect mocks gracefully closing the MQTT connection. |
| 39 | func (m *MockConnectionManagerscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/testing/integration/mqtt_test`/MockConnectionManager#) Disconnectscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/testing/integration/mqtt_test`/MockConnectionManager#Disconnect().(ctx contextscip-go gomod github.com/golang/go/src . context/.Contextscip-go gomod github.com/golang/go/src . context/Context#) error { |
| 40 | args := m.Calledscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/mock`/Mock#Called().(ctx) |
| 41 | |
| 42 | return args.Errorscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/mock`/Arguments#Error().(0) |
| 43 | } |
| 44 | |
| 45 | // Publish mocks sending an MQTT message to the broker. |
| 46 | func (m *MockConnectionManagerscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/testing/integration/mqtt_test`/MockConnectionManager#) Publishscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/testing/integration/mqtt_test`/MockConnectionManager#Publish().( |
| 47 | ctx contextscip-go gomod github.com/golang/go/src . context/.Contextscip-go gomod github.com/golang/go/src . context/Context#, |
| 48 | publish *pahoscip-go gomod github.com/eclipse/paho.golang v0.23.0 `github.com/eclipse/paho.golang/paho`/.Publishscip-go gomod github.com/eclipse/paho.golang v0.23.0 `github.com/eclipse/paho.golang/paho`/Publish#, |
| 49 | ) (*pahoscip-go gomod github.com/eclipse/paho.golang v0.23.0 `github.com/eclipse/paho.golang/paho`/.PublishResponsescip-go gomod github.com/eclipse/paho.golang v0.23.0 `github.com/eclipse/paho.golang/paho`/PublishResponse#, error) { |
| 50 | args := m.Calledscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/mock`/Mock#Called().(ctx, publish) |
| 51 | |
| 52 | if args.Getscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/mock`/Arguments#Get().(0) == nil { |
| 53 | return nil, args.Errorscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/mock`/Arguments#Error().(1) |
| 54 | } |
| 55 | |
| 56 | return args.Getscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/mock`/Arguments#Get().(0).(*pahoscip-go gomod github.com/eclipse/paho.golang v0.23.0 `github.com/eclipse/paho.golang/paho`/.PublishResponsescip-go gomod github.com/eclipse/paho.golang v0.23.0 `github.com/eclipse/paho.golang/paho`/PublishResponse#), args.Errorscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/mock`/Arguments#Error().(1) |
| 57 | } |
| 58 | |
| 59 | // assertPublishCalled asserts that Publish was called with the expected topic. |
| 60 | func assertPublishCalledscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/testing/integration/mqtt_test`/assertPublishCalled().(t *testingscip-go gomod github.com/golang/go/src . testing/.Tscip-go gomod github.com/golang/go/src . testing/T#, mockManager *MockConnectionManagerscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/testing/integration/mqtt_test`/MockConnectionManager#, expectedTopic string) { |
| 61 | t.Helperscip-go gomod github.com/golang/go/src . testing/common#Helper().() |
| 62 | |
| 63 | found := false |
| 64 | |
| 65 | for i := range mockManager.Callsscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/mock`/Mock#Calls. { |
| 66 | call := &mockManager.Callsscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/mock`/Mock#Calls.[i] |
| 67 | if call.Methodscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/mock`/Call#Method. == publishMethodNamescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/testing/integration/mqtt_test`/publishMethodName. { |
| 68 | publish := call.Argumentsscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/mock`/Call#Arguments.[1].(*pahoscip-go gomod github.com/eclipse/paho.golang v0.23.0 `github.com/eclipse/paho.golang/paho`/.Publishscip-go gomod github.com/eclipse/paho.golang v0.23.0 `github.com/eclipse/paho.golang/paho`/Publish#) |
| 69 | if publish.Topicscip-go gomod github.com/eclipse/paho.golang v0.23.0 `github.com/eclipse/paho.golang/paho`/Publish#Topic. == expectedTopic { |
| 70 | found = true |
| 71 | |
| 72 | break |
| 73 | } |
| 74 | } |
| 75 | } |
| 76 | |
| 77 | if !found { |
| 78 | t.Errorfscip-go gomod github.com/golang/go/src . testing/common#Errorf().("Expected Publish call with topic %q, but no matching call found", expectedTopic) |
| 79 | } |
| 80 | } |
| 81 | |
| 82 | // assertPublishPayload asserts that Publish was called with the expected payload. |
| 83 | func assertPublishPayloadscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/testing/integration/mqtt_test`/assertPublishPayload().( |
| 84 | t *testingscip-go gomod github.com/golang/go/src . testing/.Tscip-go gomod github.com/golang/go/src . testing/T#, |
| 85 | mockManager *MockConnectionManagerscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/testing/integration/mqtt_test`/MockConnectionManager#, |
| 86 | expectedPayload string, |
| 87 | ) { |
| 88 | t.Helperscip-go gomod github.com/golang/go/src . testing/common#Helper().() |
| 89 | |
| 90 | found := false |
| 91 | |
| 92 | for i := range mockManager.Callsscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/mock`/Mock#Calls. { |
| 93 | call := &mockManager.Callsscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/mock`/Mock#Calls.[i] |
| 94 | if call.Methodscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/mock`/Call#Method. == publishMethodNamescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/testing/integration/mqtt_test`/publishMethodName. { |
| 95 | publish := call.Argumentsscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/mock`/Call#Arguments.[1].(*pahoscip-go gomod github.com/eclipse/paho.golang v0.23.0 `github.com/eclipse/paho.golang/paho`/.Publishscip-go gomod github.com/eclipse/paho.golang v0.23.0 `github.com/eclipse/paho.golang/paho`/Publish#) |
| 96 | if string(publish.Payloadscip-go gomod github.com/eclipse/paho.golang v0.23.0 `github.com/eclipse/paho.golang/paho`/Publish#Payload.) == expectedPayload { |
| 97 | found = true |
| 98 | |
| 99 | break |
| 100 | } |
| 101 | } |
| 102 | } |
| 103 | |
| 104 | if !found { |
| 105 | t.Errorfscip-go gomod github.com/golang/go/src . testing/common#Errorf().( |
| 106 | "Expected Publish call with payload %q, but no matching call found", |
| 107 | expectedPayload, |
| 108 | ) |
| 109 | } |
| 110 | } |
| 111 | |
| 112 | // assertPublishQoS asserts that Publish was called with the expected QoS level. |
| 113 | func assertPublishQoSscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/testing/integration/mqtt_test`/assertPublishQoS().(t *testingscip-go gomod github.com/golang/go/src . testing/.Tscip-go gomod github.com/golang/go/src . testing/T#, mockManager *MockConnectionManagerscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/testing/integration/mqtt_test`/MockConnectionManager#, expectedQoS byte) { |
| 114 | t.Helperscip-go gomod github.com/golang/go/src . testing/common#Helper().() |
| 115 | |
| 116 | found := false |
| 117 | |
| 118 | for i := range mockManager.Callsscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/mock`/Mock#Calls. { |
| 119 | call := &mockManager.Callsscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/mock`/Mock#Calls.[i] |
| 120 | if call.Methodscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/mock`/Call#Method. == publishMethodNamescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/testing/integration/mqtt_test`/publishMethodName. { |
| 121 | publish := call.Argumentsscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/mock`/Call#Arguments.[1].(*pahoscip-go gomod github.com/eclipse/paho.golang v0.23.0 `github.com/eclipse/paho.golang/paho`/.Publishscip-go gomod github.com/eclipse/paho.golang v0.23.0 `github.com/eclipse/paho.golang/paho`/Publish#) |
| 122 | if publish.QoSscip-go gomod github.com/eclipse/paho.golang v0.23.0 `github.com/eclipse/paho.golang/paho`/Publish#QoS. == expectedQoS { |
| 123 | found = true |
| 124 | |
| 125 | break |
| 126 | } |
| 127 | } |
| 128 | } |
| 129 | |
| 130 | if !found { |
| 131 | t.Errorfscip-go gomod github.com/golang/go/src . testing/common#Errorf().("Expected Publish call with QoS %d, but no matching call found", expectedQoS) |
| 132 | } |
| 133 | } |
| 134 | |
| 135 | // assertPublishRetained asserts that Publish was called with the expected retained flag. |
| 136 | func assertPublishRetainedscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/testing/integration/mqtt_test`/assertPublishRetained().( |
| 137 | t *testingscip-go gomod github.com/golang/go/src . testing/.Tscip-go gomod github.com/golang/go/src . testing/T#, |
| 138 | mockManager *MockConnectionManagerscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/testing/integration/mqtt_test`/MockConnectionManager#, |
| 139 | expectedRetained bool, |
| 140 | ) { |
| 141 | t.Helperscip-go gomod github.com/golang/go/src . testing/common#Helper().() |
| 142 | |
| 143 | found := false |
| 144 | |
| 145 | for i := range mockManager.Callsscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/mock`/Mock#Calls. { |
| 146 | call := &mockManager.Callsscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/mock`/Mock#Calls.[i] |
| 147 | if call.Methodscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/mock`/Call#Method. == publishMethodNamescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/testing/integration/mqtt_test`/publishMethodName. { |
| 148 | publish := call.Argumentsscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/mock`/Call#Arguments.[1].(*pahoscip-go gomod github.com/eclipse/paho.golang v0.23.0 `github.com/eclipse/paho.golang/paho`/.Publishscip-go gomod github.com/eclipse/paho.golang v0.23.0 `github.com/eclipse/paho.golang/paho`/Publish#) |
| 149 | if publish.Retainscip-go gomod github.com/eclipse/paho.golang v0.23.0 `github.com/eclipse/paho.golang/paho`/Publish#Retain. == expectedRetained { |
| 150 | found = true |
| 151 | |
| 152 | break |
| 153 | } |
| 154 | } |
| 155 | } |
| 156 | |
| 157 | if !found { |
| 158 | t.Errorfscip-go gomod github.com/golang/go/src . testing/common#Errorf().( |
| 159 | "Expected Publish call with Retain=%v, but no matching call found", |
| 160 | expectedRetained, |
| 161 | ) |
| 162 | } |
| 163 | } |
| 164 | |
| 165 | // createMockPublishResponse creates a mock publish response with the given reason code. |
| 166 | func createMockPublishResponsescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/testing/integration/mqtt_test`/createMockPublishResponse().(reasonCode byte) *pahoscip-go gomod github.com/eclipse/paho.golang v0.23.0 `github.com/eclipse/paho.golang/paho`/.PublishResponsescip-go gomod github.com/eclipse/paho.golang v0.23.0 `github.com/eclipse/paho.golang/paho`/PublishResponse# { |
| 167 | return &pahoscip-go gomod github.com/eclipse/paho.golang v0.23.0 `github.com/eclipse/paho.golang/paho`/.PublishResponsescip-go gomod github.com/eclipse/paho.golang v0.23.0 `github.com/eclipse/paho.golang/paho`/PublishResponse#{ |
| 168 | ReasonCodescip-go gomod github.com/eclipse/paho.golang v0.23.0 `github.com/eclipse/paho.golang/paho`/PublishResponse#ReasonCode.: reasonCode, |
| 169 | Propertiesscip-go gomod github.com/eclipse/paho.golang v0.23.0 `github.com/eclipse/paho.golang/paho`/PublishResponse#Properties.: &pahoscip-go gomod github.com/eclipse/paho.golang v0.23.0 `github.com/eclipse/paho.golang/paho`/.PublishResponsePropertiesscip-go gomod github.com/eclipse/paho.golang v0.23.0 `github.com/eclipse/paho.golang/paho`/PublishResponseProperties#{}, |
| 170 | } |
| 171 | } |
| 172 | |
| 173 | // createMockPublishResponseWithReason creates a mock publish response with reason code and string. |
| 174 | func createMockPublishResponseWithReasonscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/testing/integration/mqtt_test`/createMockPublishResponseWithReason().( |
| 175 | reasonCode byte, |
| 176 | reasonString string, |
| 177 | ) *pahoscip-go gomod github.com/eclipse/paho.golang v0.23.0 `github.com/eclipse/paho.golang/paho`/.PublishResponsescip-go gomod github.com/eclipse/paho.golang v0.23.0 `github.com/eclipse/paho.golang/paho`/PublishResponse# { |
| 178 | return &pahoscip-go gomod github.com/eclipse/paho.golang v0.23.0 `github.com/eclipse/paho.golang/paho`/.PublishResponsescip-go gomod github.com/eclipse/paho.golang v0.23.0 `github.com/eclipse/paho.golang/paho`/PublishResponse#{ |
| 179 | ReasonCodescip-go gomod github.com/eclipse/paho.golang v0.23.0 `github.com/eclipse/paho.golang/paho`/PublishResponse#ReasonCode.: reasonCode, |
| 180 | Propertiesscip-go gomod github.com/eclipse/paho.golang v0.23.0 `github.com/eclipse/paho.golang/paho`/PublishResponse#Properties.: &pahoscip-go gomod github.com/eclipse/paho.golang v0.23.0 `github.com/eclipse/paho.golang/paho`/.PublishResponsePropertiesscip-go gomod github.com/eclipse/paho.golang v0.23.0 `github.com/eclipse/paho.golang/paho`/PublishResponseProperties#{ |
| 181 | ReasonStringscip-go gomod github.com/eclipse/paho.golang v0.23.0 `github.com/eclipse/paho.golang/paho`/PublishResponseProperties#ReasonString.: reasonString, |
| 182 | }, |
| 183 | } |
| 184 | } |
| 185 | |
| 186 | // createTestParams creates test parameters with the given key-value pairs. |
| 187 | func createTestParamsscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/testing/integration/mqtt_test`/createTestParams().(pairs ...string) *typesscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/types`/.Paramsscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/types`/Params# { |
| 188 | params := make(typesscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/types`/.Paramsscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/types`/Params#) |
| 189 | |
| 190 | for i := 0; i < len(pairs); i += 2 { |
| 191 | if i+1 < len(pairs) { |
| 192 | params[pairs[i]] = pairs[i+1] |
| 193 | } |
| 194 | } |
| 195 | |
| 196 | return ¶ms |
| 197 | } |
| 198 | |
| 199 | // createTestService creates an MQTT service instance configured for testing. |
| 200 | // If a mockConnectionManager is provided, it will be injected into the service |
| 201 | // to bypass the normal connection initialization. |
| 202 | func createTestServicescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/testing/integration/mqtt_test`/createTestService().( |
| 203 | t *testingscip-go gomod github.com/golang/go/src . testing/.Tscip-go gomod github.com/golang/go/src . testing/T#, |
| 204 | mqttURL string, |
| 205 | mockConnectionManager ...mqttscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/mqtt`/.ConnectionManagerscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/mqtt`/ConnectionManager#, |
| 206 | ) *mqttscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/mqtt`/.Servicescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/mqtt`/Service# { |
| 207 | t.Helperscip-go gomod github.com/golang/go/src . testing/common#Helper().() |
| 208 | |
| 209 | service := &mqttscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/mqtt`/.Servicescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/mqtt`/Service#{} |
| 210 | |
| 211 | parsedURL, err := urlscip-go gomod github.com/golang/go/src . `net/url`/.Parsescip-go gomod github.com/golang/go/src . `net/url`/Parse().(mqttURL) |
| 212 | requirescip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/.NoErrorscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/NoError().(t, err) |
| 213 | |
| 214 | err = service.Initializescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/mqtt`/Service#Initialize().(parsedURL, &mockLoggerscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/testing/integration/mqtt_test`/mockLogger#{}) |
| 215 | requirescip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/.NoErrorscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/NoError().(t, err) |
| 216 | |
| 217 | // Inject mock connection manager if provided |
| 218 | if len(mockConnectionManager) > 0 && mockConnectionManager[0] != nil { |
| 219 | service.SetConnectionManagerscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/mqtt`/Service#SetConnectionManager().(mockConnectionManager[0]) |
| 220 | } |
| 221 | |
| 222 | return service |
| 223 | } |
| 224 | |
| 225 | // getPublishCall retrieves the publish struct from the first Publish call. |
| 226 | // Returns nil if no Publish call was made. |
| 227 | func getPublishCallscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/testing/integration/mqtt_test`/getPublishCall().(mockManager *MockConnectionManagerscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/testing/integration/mqtt_test`/MockConnectionManager#) *pahoscip-go gomod github.com/eclipse/paho.golang v0.23.0 `github.com/eclipse/paho.golang/paho`/.Publishscip-go gomod github.com/eclipse/paho.golang v0.23.0 `github.com/eclipse/paho.golang/paho`/Publish# { |
| 228 | for i := range mockManager.Callsscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/mock`/Mock#Calls. { |
| 229 | call := &mockManager.Callsscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/mock`/Mock#Calls.[i] |
| 230 | if call.Methodscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/mock`/Call#Method. == publishMethodNamescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/testing/integration/mqtt_test`/publishMethodName. { |
| 231 | if publish, ok := call.Argumentsscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/mock`/Call#Arguments.[1].(*pahoscip-go gomod github.com/eclipse/paho.golang v0.23.0 `github.com/eclipse/paho.golang/paho`/.Publishscip-go gomod github.com/eclipse/paho.golang v0.23.0 `github.com/eclipse/paho.golang/paho`/Publish#); ok { |
| 232 | return publish |
| 233 | } |
| 234 | } |
| 235 | } |
| 236 | |
| 237 | return nil |
| 238 | } |