| 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 | "errorsscip-go gomod github.com/golang/go/src . errors/" |
| 6 | "testingscip-go gomod github.com/golang/go/src . testing/" |
| 7 | "testing/synctestscip-go gomod github.com/golang/go/src . `testing/synctest`/" |
| 8 | |
| 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 | ) |
| 14 | |
| 15 | func TestSendWithConnectionErrorscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/testing/integration/mqtt_test`/TestSendWithConnectionError().(t *testingscip-go gomod github.com/golang/go/src . testing/.Tscip-go gomod github.com/golang/go/src . testing/T#) { |
| 16 | t.Parallelscip-go gomod github.com/golang/go/src . testing/T#Parallel().() |
| 17 | synctestscip-go gomod github.com/golang/go/src . `testing/synctest`/.Testscip-go gomod github.com/golang/go/src . `testing/synctest`/Test().(t, func(t *testingscip-go gomod github.com/golang/go/src . testing/.Tscip-go gomod github.com/golang/go/src . testing/T#) { |
| 18 | mockManager := &MockConnectionManagerscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/testing/integration/mqtt_test`/MockConnectionManager#{} |
| 19 | mockManager.Onscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/mock`/Mock#On().("AwaitConnection", mockscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/mock`/.Anythingscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/mock`/Anything.). |
| 20 | Returnscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/mock`/Call#Return().(errorsscip-go gomod github.com/golang/go/src . errors/.Newscip-go gomod github.com/golang/go/src . errors/New().("connection refused")). |
| 21 | Oncescip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/mock`/Call#Once().() |
| 22 | |
| 23 | service := createTestServicescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/testing/integration/mqtt_test`/createTestService().(t, "mqtt://broker.example.com/test/topic", mockManager) |
| 24 | |
| 25 | err := service.Sendscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/mqtt`/Service#Send().("Test message", nil) |
| 26 | requirescip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/.Errorscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/Error().(t, err) |
| 27 | requirescip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/.Containsscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/Contains().(t, err.Error(), "connecting to MQTT broker") |
| 28 | |
| 29 | mockManager.AssertExpectationsscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/mock`/Mock#AssertExpectations().(t) |
| 30 | }) |
| 31 | } |
| 32 | |
| 33 | func TestSendWithPublishErrorscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/testing/integration/mqtt_test`/TestSendWithPublishError().(t *testingscip-go gomod github.com/golang/go/src . testing/.Tscip-go gomod github.com/golang/go/src . testing/T#) { |
| 34 | t.Parallelscip-go gomod github.com/golang/go/src . testing/T#Parallel().() |
| 35 | synctestscip-go gomod github.com/golang/go/src . `testing/synctest`/.Testscip-go gomod github.com/golang/go/src . `testing/synctest`/Test().(t, func(t *testingscip-go gomod github.com/golang/go/src . testing/.Tscip-go gomod github.com/golang/go/src . testing/T#) { |
| 36 | mockManager := &MockConnectionManagerscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/testing/integration/mqtt_test`/MockConnectionManager#{} |
| 37 | mockManager.Onscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/mock`/Mock#On().("AwaitConnection", mockscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/mock`/.Anythingscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/mock`/Anything.).Returnscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/mock`/Call#Return().(nil) |
| 38 | mockManager.Onscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/mock`/Mock#On().("Publish", mockscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/mock`/.Anythingscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/mock`/Anything., mockscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/mock`/.Anythingscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/mock`/Anything.). |
| 39 | Returnscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/mock`/Call#Return().(nil, errorsscip-go gomod github.com/golang/go/src . errors/.Newscip-go gomod github.com/golang/go/src . errors/New().("network error")). |
| 40 | Oncescip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/mock`/Call#Once().() |
| 41 | |
| 42 | service := createTestServicescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/testing/integration/mqtt_test`/createTestService().(t, "mqtt://broker.example.com/test/topic", mockManager) |
| 43 | |
| 44 | err := service.Sendscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/mqtt`/Service#Send().("Test message", nil) |
| 45 | requirescip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/.Errorscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/Error().(t, err) |
| 46 | requirescip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/.Containsscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/Contains().(t, err.Error(), "publishing to MQTT topic") |
| 47 | |
| 48 | mockManager.AssertExpectationsscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/mock`/Mock#AssertExpectations().(t) |
| 49 | }) |
| 50 | } |
| 51 | |
| 52 | func TestSendWithFailureReasonCodescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/testing/integration/mqtt_test`/TestSendWithFailureReasonCode().(t *testingscip-go gomod github.com/golang/go/src . testing/.Tscip-go gomod github.com/golang/go/src . testing/T#) { |
| 53 | t.Parallelscip-go gomod github.com/golang/go/src . testing/T#Parallel().() |
| 54 | synctestscip-go gomod github.com/golang/go/src . `testing/synctest`/.Testscip-go gomod github.com/golang/go/src . `testing/synctest`/Test().(t, func(t *testingscip-go gomod github.com/golang/go/src . testing/.Tscip-go gomod github.com/golang/go/src . testing/T#) { |
| 55 | tests := []struct { |
| 56 | name string |
| 57 | reasonCode byte |
| 58 | reasonString string |
| 59 | }{ |
| 60 | { |
| 61 | name: "unspecified error", |
| 62 | reasonCode: 0x80, |
| 63 | reasonString: "Unspecified error", |
| 64 | }, |
| 65 | { |
| 66 | name: "malformed packet", |
| 67 | reasonCode: 0x81, |
| 68 | reasonString: "Malformed Packet", |
| 69 | }, |
| 70 | { |
| 71 | name: "protocol error", |
| 72 | reasonCode: 0x82, |
| 73 | reasonString: "Protocol Error", |
| 74 | }, |
| 75 | { |
| 76 | name: "implementation specific error", |
| 77 | reasonCode: 0x83, |
| 78 | reasonString: "Implementation specific error", |
| 79 | }, |
| 80 | { |
| 81 | name: "unsupported protocol version", |
| 82 | reasonCode: 0x84, |
| 83 | reasonString: "Unsupported Protocol Version", |
| 84 | }, |
| 85 | { |
| 86 | name: "client identifier not valid", |
| 87 | reasonCode: 0x85, |
| 88 | reasonString: "Client Identifier not valid", |
| 89 | }, |
| 90 | { |
| 91 | name: "bad user name or password", |
| 92 | reasonCode: 0x86, |
| 93 | reasonString: "Bad User Name or Password", |
| 94 | }, |
| 95 | { |
| 96 | name: "not authorized", |
| 97 | reasonCode: 0x87, |
| 98 | reasonString: "Not authorized", |
| 99 | }, |
| 100 | } |
| 101 | |
| 102 | for _, tt := range tests { |
| 103 | mockManager := &MockConnectionManagerscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/testing/integration/mqtt_test`/MockConnectionManager#{} |
| 104 | mockManager.Onscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/mock`/Mock#On().("AwaitConnection", mockscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/mock`/.Anythingscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/mock`/Anything.).Returnscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/mock`/Call#Return().(nil) |
| 105 | mockManager.Onscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/mock`/Mock#On().("Publish", mockscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/mock`/.Anythingscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/mock`/Anything., mockscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/mock`/.Anythingscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/mock`/Anything.). |
| 106 | Returnscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/mock`/Call#Return().(createMockPublishResponseWithReasonscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/testing/integration/mqtt_test`/createMockPublishResponseWithReason().(tt.reasonCode, tt.reasonString), nil). |
| 107 | Oncescip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/mock`/Call#Once().() |
| 108 | |
| 109 | service := createTestServicescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/testing/integration/mqtt_test`/createTestService().(t, "mqtt://broker.example.com/test/topic", mockManager) |
| 110 | |
| 111 | err := service.Sendscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/mqtt`/Service#Send().("Test message", nil) |
| 112 | requirescip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/.Errorscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/Error().(t, err) |
| 113 | |
| 114 | // Verify it's a PublishError |
| 115 | var publishErr mqttscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/mqtt`/.PublishErrorscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/mqtt`/PublishError# |
| 116 | requirescip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/.ErrorAsscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/ErrorAs().(t, err, &publishErr) |
| 117 | requirescip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/.Equalscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/Equal().(t, tt.reasonCode, publishErr.ReasonCodescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/mqtt`/PublishError#ReasonCode.) |
| 118 | requirescip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/.Equalscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/Equal().(t, tt.reasonString, publishErr.ReasonStringscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/mqtt`/PublishError#ReasonString.) |
| 119 | |
| 120 | mockManager.AssertExpectationsscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/mock`/Mock#AssertExpectations().(t) |
| 121 | } |
| 122 | }) |
| 123 | } |
| 124 | |
| 125 | func TestSendWithReasonCodeNoReasonStringscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/testing/integration/mqtt_test`/TestSendWithReasonCodeNoReasonString().(t *testingscip-go gomod github.com/golang/go/src . testing/.Tscip-go gomod github.com/golang/go/src . testing/T#) { |
| 126 | t.Parallelscip-go gomod github.com/golang/go/src . testing/T#Parallel().() |
| 127 | synctestscip-go gomod github.com/golang/go/src . `testing/synctest`/.Testscip-go gomod github.com/golang/go/src . `testing/synctest`/Test().(t, func(t *testingscip-go gomod github.com/golang/go/src . testing/.Tscip-go gomod github.com/golang/go/src . testing/T#) { |
| 128 | mockManager := &MockConnectionManagerscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/testing/integration/mqtt_test`/MockConnectionManager#{} |
| 129 | mockManager.Onscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/mock`/Mock#On().("AwaitConnection", mockscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/mock`/.Anythingscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/mock`/Anything.).Returnscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/mock`/Call#Return().(nil) |
| 130 | mockManager.Onscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/mock`/Mock#On().("Publish", mockscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/mock`/.Anythingscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/mock`/Anything., mockscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/mock`/.Anythingscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/mock`/Anything.). |
| 131 | Returnscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/mock`/Call#Return().(createMockPublishResponsescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/testing/integration/mqtt_test`/createMockPublishResponse().(0x80), nil). // Failure code without reason string |
| 132 | Oncescip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/mock`/Call#Once().() |
| 133 | |
| 134 | service := createTestServicescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/testing/integration/mqtt_test`/createTestService().(t, "mqtt://broker.example.com/test/topic", mockManager) |
| 135 | |
| 136 | err := service.Sendscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/mqtt`/Service#Send().("Test message", nil) |
| 137 | requirescip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/.Errorscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/Error().(t, err) |
| 138 | |
| 139 | var publishErr mqttscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/mqtt`/.PublishErrorscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/mqtt`/PublishError# |
| 140 | requirescip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/.ErrorAsscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/ErrorAs().(t, err, &publishErr) |
| 141 | requirescip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/.Equalscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/Equal().(t, byte(0x80), publishErr.ReasonCodescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/mqtt`/PublishError#ReasonCode.) |
| 142 | requirescip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/.Emptyscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/Empty().(t, publishErr.ReasonStringscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/mqtt`/PublishError#ReasonString.) |
| 143 | |
| 144 | mockManager.AssertExpectationsscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/mock`/Mock#AssertExpectations().(t) |
| 145 | }) |
| 146 | } |
| 147 | |
| 148 | func TestSendWithInvalidQoSscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/testing/integration/mqtt_test`/TestSendWithInvalidQoS().(t *testingscip-go gomod github.com/golang/go/src . testing/.Tscip-go gomod github.com/golang/go/src . testing/T#) { |
| 149 | t.Parallelscip-go gomod github.com/golang/go/src . testing/T#Parallel().() |
| 150 | synctestscip-go gomod github.com/golang/go/src . `testing/synctest`/.Testscip-go gomod github.com/golang/go/src . `testing/synctest`/Test().(t, func(t *testingscip-go gomod github.com/golang/go/src . testing/.Tscip-go gomod github.com/golang/go/src . testing/T#) { |
| 151 | // Create service without mock manager - it should fail before connection |
| 152 | service := createTestServicescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/testing/integration/mqtt_test`/createTestService().(t, "mqtt://broker.example.com/test/topic") |
| 153 | |
| 154 | // Manually set invalid QoS |
| 155 | service.Configscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/mqtt`/Service#Config..QoSscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/mqtt`/Config#QoS. = 3 |
| 156 | |
| 157 | err := service.Sendscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/mqtt`/Service#Send().("Test message", nil) |
| 158 | requirescip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/.Errorscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/Error().(t, err) |
| 159 | requirescip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/.Containsscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/Contains().(t, err.Error(), "validating QoS") |
| 160 | }) |
| 161 | } |
| 162 | |
| 163 | func TestSendWithNegativeQoSscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/testing/integration/mqtt_test`/TestSendWithNegativeQoS().(t *testingscip-go gomod github.com/golang/go/src . testing/.Tscip-go gomod github.com/golang/go/src . testing/T#) { |
| 164 | t.Parallelscip-go gomod github.com/golang/go/src . testing/T#Parallel().() |
| 165 | synctestscip-go gomod github.com/golang/go/src . `testing/synctest`/.Testscip-go gomod github.com/golang/go/src . `testing/synctest`/Test().(t, func(t *testingscip-go gomod github.com/golang/go/src . testing/.Tscip-go gomod github.com/golang/go/src . testing/T#) { |
| 166 | // Create service without mock manager - it should fail before connection |
| 167 | service := createTestServicescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/testing/integration/mqtt_test`/createTestService().(t, "mqtt://broker.example.com/test/topic") |
| 168 | |
| 169 | // Manually set invalid QoS |
| 170 | service.Configscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/mqtt`/Service#Config..QoSscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/mqtt`/Config#QoS. = -1 |
| 171 | |
| 172 | err := service.Sendscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/mqtt`/Service#Send().("Test message", nil) |
| 173 | requirescip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/.Errorscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/Error().(t, err) |
| 174 | requirescip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/.Containsscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/Contains().(t, err.Error(), "validating QoS") |
| 175 | }) |
| 176 | } |
| 177 | |
| 178 | func TestDisconnectErrorscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/testing/integration/mqtt_test`/TestDisconnectError().(t *testingscip-go gomod github.com/golang/go/src . testing/.Tscip-go gomod github.com/golang/go/src . testing/T#) { |
| 179 | t.Parallelscip-go gomod github.com/golang/go/src . testing/T#Parallel().() |
| 180 | synctestscip-go gomod github.com/golang/go/src . `testing/synctest`/.Testscip-go gomod github.com/golang/go/src . `testing/synctest`/Test().(t, func(t *testingscip-go gomod github.com/golang/go/src . testing/.Tscip-go gomod github.com/golang/go/src . testing/T#) { |
| 181 | mockManager := &MockConnectionManagerscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/testing/integration/mqtt_test`/MockConnectionManager#{} |
| 182 | mockManager.Onscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/mock`/Mock#On().("AwaitConnection", mockscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/mock`/.Anythingscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/mock`/Anything.).Returnscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/mock`/Call#Return().(nil) |
| 183 | mockManager.Onscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/mock`/Mock#On().("Publish", mockscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/mock`/.Anythingscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/mock`/Anything., mockscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/mock`/.Anythingscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/mock`/Anything.). |
| 184 | Returnscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/mock`/Call#Return().(createMockPublishResponsescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/testing/integration/mqtt_test`/createMockPublishResponse().(0), nil). |
| 185 | Oncescip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/mock`/Call#Once().() |
| 186 | mockManager.Onscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/mock`/Mock#On().("Disconnect", mockscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/mock`/.Anythingscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/mock`/Anything.). |
| 187 | Returnscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/mock`/Call#Return().(errorsscip-go gomod github.com/golang/go/src . errors/.Newscip-go gomod github.com/golang/go/src . errors/New().("disconnect error")). |
| 188 | Oncescip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/mock`/Call#Once().() |
| 189 | |
| 190 | service := createTestServicescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/testing/integration/mqtt_test`/createTestService().(t, "mqtt://broker.example.com/test/topic", mockManager) |
| 191 | |
| 192 | // Send a message first |
| 193 | err := service.Sendscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/mqtt`/Service#Send().("Test message", nil) |
| 194 | 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) |
| 195 | |
| 196 | // Close should return the disconnect error |
| 197 | err = service.Closescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/mqtt`/Service#Close().() |
| 198 | requirescip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/.Errorscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/Error().(t, err) |
| 199 | requirescip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/.Containsscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/Contains().(t, err.Error(), "disconnecting from MQTT broker") |
| 200 | |
| 201 | mockManager.AssertExpectationsscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/mock`/Mock#AssertExpectations().(t) |
| 202 | }) |
| 203 | } |
| 204 | |
| 205 | func TestCloseWithoutConnectionscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/testing/integration/mqtt_test`/TestCloseWithoutConnection().(t *testingscip-go gomod github.com/golang/go/src . testing/.Tscip-go gomod github.com/golang/go/src . testing/T#) { |
| 206 | t.Parallelscip-go gomod github.com/golang/go/src . testing/T#Parallel().() |
| 207 | synctestscip-go gomod github.com/golang/go/src . `testing/synctest`/.Testscip-go gomod github.com/golang/go/src . `testing/synctest`/Test().(t, func(t *testingscip-go gomod github.com/golang/go/src . testing/.Tscip-go gomod github.com/golang/go/src . testing/T#) { |
| 208 | // Create service without initializing connection |
| 209 | service := createTestServicescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/testing/integration/mqtt_test`/createTestService().(t, "mqtt://broker.example.com/test/topic") |
| 210 | |
| 211 | // Close should not error when connection was never established |
| 212 | err := service.Closescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/mqtt`/Service#Close().() |
| 213 | 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) |
| 214 | }) |
| 215 | } |
| 216 | |
| 217 | func TestCloseIdempotentscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/testing/integration/mqtt_test`/TestCloseIdempotent().(t *testingscip-go gomod github.com/golang/go/src . testing/.Tscip-go gomod github.com/golang/go/src . testing/T#) { |
| 218 | t.Parallelscip-go gomod github.com/golang/go/src . testing/T#Parallel().() |
| 219 | synctestscip-go gomod github.com/golang/go/src . `testing/synctest`/.Testscip-go gomod github.com/golang/go/src . `testing/synctest`/Test().(t, func(t *testingscip-go gomod github.com/golang/go/src . testing/.Tscip-go gomod github.com/golang/go/src . testing/T#) { |
| 220 | mockManager := &MockConnectionManagerscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/testing/integration/mqtt_test`/MockConnectionManager#{} |
| 221 | mockManager.Onscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/mock`/Mock#On().("AwaitConnection", mockscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/mock`/.Anythingscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/mock`/Anything.).Returnscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/mock`/Call#Return().(nil) |
| 222 | mockManager.Onscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/mock`/Mock#On().("Publish", mockscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/mock`/.Anythingscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/mock`/Anything., mockscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/mock`/.Anythingscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/mock`/Anything.). |
| 223 | Returnscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/mock`/Call#Return().(createMockPublishResponsescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/testing/integration/mqtt_test`/createMockPublishResponse().(0), nil). |
| 224 | Oncescip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/mock`/Call#Once().() |
| 225 | mockManager.Onscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/mock`/Mock#On().("Disconnect", mockscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/mock`/.Anythingscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/mock`/Anything.).Returnscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/mock`/Call#Return().(nil).Oncescip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/mock`/Call#Once().() |
| 226 | |
| 227 | service := createTestServicescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/testing/integration/mqtt_test`/createTestService().(t, "mqtt://broker.example.com/test/topic", mockManager) |
| 228 | |
| 229 | // Send a message first |
| 230 | err := service.Sendscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/mqtt`/Service#Send().("Test message", nil) |
| 231 | 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) |
| 232 | |
| 233 | // First close |
| 234 | err = service.Closescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/mqtt`/Service#Close().() |
| 235 | 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) |
| 236 | |
| 237 | // Second close should return same result (no error, no panic) |
| 238 | err = service.Closescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/mqtt`/Service#Close().() |
| 239 | 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) |
| 240 | |
| 241 | // Disconnect should only be called once |
| 242 | mockManager.AssertExpectationsscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/mock`/Mock#AssertExpectations().(t) |
| 243 | }) |
| 244 | } |
| 245 | |
| 246 | func TestContextCancellationDuringAwaitConnectionscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/testing/integration/mqtt_test`/TestContextCancellationDuringAwaitConnection().(t *testingscip-go gomod github.com/golang/go/src . testing/.Tscip-go gomod github.com/golang/go/src . testing/T#) { |
| 247 | t.Parallelscip-go gomod github.com/golang/go/src . testing/T#Parallel().() |
| 248 | synctestscip-go gomod github.com/golang/go/src . `testing/synctest`/.Testscip-go gomod github.com/golang/go/src . `testing/synctest`/Test().(t, func(t *testingscip-go gomod github.com/golang/go/src . testing/.Tscip-go gomod github.com/golang/go/src . testing/T#) { |
| 249 | mockManager := &MockConnectionManagerscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/testing/integration/mqtt_test`/MockConnectionManager#{} |
| 250 | mockManager.Onscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/mock`/Mock#On().("AwaitConnection", mockscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/mock`/.Anythingscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/mock`/Anything.). |
| 251 | Returnscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/mock`/Call#Return().(contextscip-go gomod github.com/golang/go/src . context/.Canceledscip-go gomod github.com/golang/go/src . context/Canceled.). |
| 252 | Oncescip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/mock`/Call#Once().() |
| 253 | |
| 254 | service := createTestServicescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/testing/integration/mqtt_test`/createTestService().(t, "mqtt://broker.example.com/test/topic", mockManager) |
| 255 | |
| 256 | err := service.Sendscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/mqtt`/Service#Send().("Test message", nil) |
| 257 | requirescip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/.Errorscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/Error().(t, err) |
| 258 | requirescip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/.Containsscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/Contains().(t, err.Error(), "connecting to MQTT broker") |
| 259 | |
| 260 | mockManager.AssertExpectationsscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/mock`/Mock#AssertExpectations().(t) |
| 261 | }) |
| 262 | } |
| 263 | |
| 264 | func TestContextDeadlineExceededDuringAwaitConnectionscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/testing/integration/mqtt_test`/TestContextDeadlineExceededDuringAwaitConnection().(t *testingscip-go gomod github.com/golang/go/src . testing/.Tscip-go gomod github.com/golang/go/src . testing/T#) { |
| 265 | t.Parallelscip-go gomod github.com/golang/go/src . testing/T#Parallel().() |
| 266 | synctestscip-go gomod github.com/golang/go/src . `testing/synctest`/.Testscip-go gomod github.com/golang/go/src . `testing/synctest`/Test().(t, func(t *testingscip-go gomod github.com/golang/go/src . testing/.Tscip-go gomod github.com/golang/go/src . testing/T#) { |
| 267 | mockManager := &MockConnectionManagerscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/testing/integration/mqtt_test`/MockConnectionManager#{} |
| 268 | mockManager.Onscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/mock`/Mock#On().("AwaitConnection", mockscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/mock`/.Anythingscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/mock`/Anything.). |
| 269 | Returnscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/mock`/Call#Return().(contextscip-go gomod github.com/golang/go/src . context/.DeadlineExceededscip-go gomod github.com/golang/go/src . context/DeadlineExceeded.). |
| 270 | Oncescip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/mock`/Call#Once().() |
| 271 | |
| 272 | service := createTestServicescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/testing/integration/mqtt_test`/createTestService().(t, "mqtt://broker.example.com/test/topic", mockManager) |
| 273 | |
| 274 | err := service.Sendscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/mqtt`/Service#Send().("Test message", nil) |
| 275 | requirescip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/.Errorscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/Error().(t, err) |
| 276 | requirescip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/.Containsscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/Contains().(t, err.Error(), "connecting to MQTT broker") |
| 277 | |
| 278 | mockManager.AssertExpectationsscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/mock`/Mock#AssertExpectations().(t) |
| 279 | }) |
| 280 | } |
| 281 | |
| 282 | func TestPublishErrorErrorMethodscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/testing/integration/mqtt_test`/TestPublishErrorErrorMethod().(t *testingscip-go gomod github.com/golang/go/src . testing/.Tscip-go gomod github.com/golang/go/src . testing/T#) { |
| 283 | t.Parallelscip-go gomod github.com/golang/go/src . testing/T#Parallel().() |
| 284 | |
| 285 | tests := []struct { |
| 286 | name string |
| 287 | reasonCode byte |
| 288 | reasonString string |
| 289 | expectedMsg string |
| 290 | }{ |
| 291 | { |
| 292 | name: "with reason string", |
| 293 | reasonCode: 0x87, |
| 294 | reasonString: "Not authorized", |
| 295 | expectedMsg: "MQTT publish failed: reason code 0x87 - Not authorized", |
| 296 | }, |
| 297 | { |
| 298 | name: "without reason string", |
| 299 | reasonCode: 0x80, |
| 300 | reasonString: "", |
| 301 | expectedMsg: "MQTT publish failed: reason code 0x80", |
| 302 | }, |
| 303 | } |
| 304 | |
| 305 | for _, tt := range tests { |
| 306 | err := mqttscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/mqtt`/.PublishErrorscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/mqtt`/PublishError#{ |
| 307 | ReasonCodescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/mqtt`/PublishError#ReasonCode.: tt.reasonCode, |
| 308 | ReasonStringscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/mqtt`/PublishError#ReasonString.: tt.reasonString, |
| 309 | } |
| 310 | |
| 311 | requirescip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/.Equalscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/Equal().(t, tt.expectedMsg, err.Errorscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/mqtt`/PublishError#Error().()) |
| 312 | } |
| 313 | } |
| 314 | |
| 315 | func TestIsFailureCodescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/testing/integration/mqtt_test`/TestIsFailureCode().(t *testingscip-go gomod github.com/golang/go/src . testing/.Tscip-go gomod github.com/golang/go/src . testing/T#) { |
| 316 | t.Parallelscip-go gomod github.com/golang/go/src . testing/T#Parallel().() |
| 317 | |
| 318 | tests := []struct { |
| 319 | code byte |
| 320 | expected bool |
| 321 | }{ |
| 322 | {0x00, false}, // Success |
| 323 | {0x01, false}, // Granted QoS 1 |
| 324 | {0x02, false}, // Granted QoS 2 |
| 325 | {0x10, false}, // No matching subscribers (not a failure) |
| 326 | {0x7F, false}, // Just below threshold |
| 327 | {0x80, true}, // Unspecified error |
| 328 | {0x87, true}, // Not authorized |
| 329 | {0xFF, true}, // Maximum value |
| 330 | } |
| 331 | |
| 332 | for _, tt := range tests { |
| 333 | result := mqttscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/mqtt`/.IsFailureCodescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/mqtt`/IsFailureCode().(tt.code) |
| 334 | requirescip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/.Equalscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/Equal().(t, tt.expected, result, "IsFailureCode(0x%02X)", tt.code) |
| 335 | } |
| 336 | } |