| 1 | package matrix_testscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/testing/integration/matrix_test`/ |
| 2 | |
| 3 | import ( |
| 4 | "net/urlscip-go gomod github.com/golang/go/src . `net/url`/" |
| 5 | "testingscip-go gomod github.com/golang/go/src . testing/" |
| 6 | |
| 7 | "github.com/stretchr/testify/requirescip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/" |
| 8 | |
| 9 | "github.com/nicholas-fedor/shoutrrr/pkg/services/chat/matrixscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/matrix`/" |
| 10 | ) |
| 11 | |
| 12 | func TestConfigSetURLscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/testing/integration/matrix_test`/TestConfigSetURL().(t *testingscip-go gomod github.com/golang/go/src . testing/.Tscip-go gomod github.com/golang/go/src . testing/T#) { |
| 13 | t.Parallelscip-go gomod github.com/golang/go/src . testing/T#Parallel().() |
| 14 | |
| 15 | tests := []struct { |
| 16 | name string |
| 17 | serviceURL string |
| 18 | }{ |
| 19 | { |
| 20 | name: "basic URL with password", |
| 21 | serviceURL: "matrix://user:[email protected]", |
| 22 | }, |
| 23 | { |
| 24 | name: "URL with special characters in password", |
| 25 | serviceURL: "matrix://user:p%[email protected]", |
| 26 | }, |
| 27 | { |
| 28 | name: "URL with port", |
| 29 | serviceURL: "matrix://user:[email protected]:8080", |
| 30 | }, |
| 31 | } |
| 32 | |
| 33 | for _, tt := range tests { |
| 34 | t.Runscip-go gomod github.com/golang/go/src . testing/T#Run().(tt.name, func(t *testingscip-go gomod github.com/golang/go/src . testing/.Tscip-go gomod github.com/golang/go/src . testing/T#) { |
| 35 | t.Parallelscip-go gomod github.com/golang/go/src . testing/T#Parallel().() |
| 36 | |
| 37 | config := &matrixscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/matrix`/.Configscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/matrix`/Config#{} |
| 38 | |
| 39 | parsedURL, err := urlscip-go gomod github.com/golang/go/src . `net/url`/.Parsescip-go gomod github.com/golang/go/src . `net/url`/Parse().(tt.serviceURL) |
| 40 | 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, "URL should be parseable for %s", tt.name) |
| 41 | |
| 42 | err = config.SetURLscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/matrix`/Config#SetURL().(parsedURL) |
| 43 | |
| 44 | 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, "Expected no error for %s", tt.name) |
| 45 | requirescip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/.NotEmptyscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/NotEmpty().(t, config.Passwordscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/matrix`/Config#Password., "Password should be set for %s", tt.name) |
| 46 | }) |
| 47 | } |
| 48 | } |
| 49 | |
| 50 | func TestConfigSetURLErrorsscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/testing/integration/matrix_test`/TestConfigSetURLErrors().(t *testingscip-go gomod github.com/golang/go/src . testing/.Tscip-go gomod github.com/golang/go/src . testing/T#) { |
| 51 | t.Parallelscip-go gomod github.com/golang/go/src . testing/T#Parallel().() |
| 52 | |
| 53 | tests := []struct { |
| 54 | name string |
| 55 | serviceURL string |
| 56 | errMsg string |
| 57 | }{ |
| 58 | { |
| 59 | name: "missing password", |
| 60 | serviceURL: "matrix://matrix.example.com", |
| 61 | errMsg: "password or access token is required", |
| 62 | }, |
| 63 | { |
| 64 | name: "empty host", |
| 65 | serviceURL: "matrix://user:token@", |
| 66 | errMsg: "host is required", |
| 67 | }, |
| 68 | } |
| 69 | |
| 70 | for _, tt := range tests { |
| 71 | t.Runscip-go gomod github.com/golang/go/src . testing/T#Run().(tt.name, func(t *testingscip-go gomod github.com/golang/go/src . testing/.Tscip-go gomod github.com/golang/go/src . testing/T#) { |
| 72 | t.Parallelscip-go gomod github.com/golang/go/src . testing/T#Parallel().() |
| 73 | |
| 74 | config := &matrixscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/matrix`/.Configscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/matrix`/Config#{} |
| 75 | |
| 76 | parsedURL, err := urlscip-go gomod github.com/golang/go/src . `net/url`/.Parsescip-go gomod github.com/golang/go/src . `net/url`/Parse().(tt.serviceURL) |
| 77 | 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, "URL should be parseable for %s", tt.name) |
| 78 | |
| 79 | err = config.SetURLscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/matrix`/Config#SetURL().(parsedURL) |
| 80 | |
| 81 | 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, "Expected error for %s", tt.name) |
| 82 | 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(), tt.errMsg, |
| 83 | "Error message should contain %q", tt.errMsg) |
| 84 | }) |
| 85 | } |
| 86 | } |
| 87 | |
| 88 | func TestConfigGetURLscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/testing/integration/matrix_test`/TestConfigGetURL().(t *testingscip-go gomod github.com/golang/go/src . testing/.Tscip-go gomod github.com/golang/go/src . testing/T#) { |
| 89 | t.Parallelscip-go gomod github.com/golang/go/src . testing/T#Parallel().() |
| 90 | |
| 91 | tests := []struct { |
| 92 | name string |
| 93 | serviceURL string |
| 94 | expectedHost string |
| 95 | expectedUser string |
| 96 | expectedPass string |
| 97 | }{ |
| 98 | { |
| 99 | name: "basic config", |
| 100 | serviceURL: "matrix://user:[email protected]", |
| 101 | expectedHost: "matrix.example.com", |
| 102 | expectedUser: "user", |
| 103 | expectedPass: "token", |
| 104 | }, |
| 105 | } |
| 106 | |
| 107 | for _, tt := range tests { |
| 108 | t.Runscip-go gomod github.com/golang/go/src . testing/T#Run().(tt.name, func(t *testingscip-go gomod github.com/golang/go/src . testing/.Tscip-go gomod github.com/golang/go/src . testing/T#) { |
| 109 | t.Parallelscip-go gomod github.com/golang/go/src . testing/T#Parallel().() |
| 110 | |
| 111 | config := &matrixscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/matrix`/.Configscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/matrix`/Config#{} |
| 112 | |
| 113 | parsedURL, err := urlscip-go gomod github.com/golang/go/src . `net/url`/.Parsescip-go gomod github.com/golang/go/src . `net/url`/Parse().(tt.serviceURL) |
| 114 | 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, "URL should be parseable for %s", tt.name) |
| 115 | |
| 116 | err = config.SetURLscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/matrix`/Config#SetURL().(parsedURL) |
| 117 | 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, "Expected no error for %s", tt.name) |
| 118 | |
| 119 | resultURL := config.GetURLscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/matrix`/Config#GetURL().() |
| 120 | |
| 121 | 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.expectedHost, resultURL.Hostscip-go gomod github.com/golang/go/src . `net/url`/URL#Host., |
| 122 | "Host mismatch for %s", tt.name) |
| 123 | |
| 124 | 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.expectedUser, resultURL.Userscip-go gomod github.com/golang/go/src . `net/url`/URL#User..Usernamescip-go gomod github.com/golang/go/src . `net/url`/Userinfo#Username().(), |
| 125 | "User mismatch for %s", tt.name) |
| 126 | |
| 127 | actualPass, ok := resultURL.Userscip-go gomod github.com/golang/go/src . `net/url`/URL#User..Passwordscip-go gomod github.com/golang/go/src . `net/url`/Userinfo#Password().() |
| 128 | requirescip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/.Truescip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/True().(t, ok, "Password should be present for %s", tt.name) |
| 129 | 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.expectedPass, actualPass, |
| 130 | "Password mismatch for %s", tt.name) |
| 131 | }) |
| 132 | } |
| 133 | } |
| 134 | |
| 135 | func TestConfigQueryParamsscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/testing/integration/matrix_test`/TestConfigQueryParams().(t *testingscip-go gomod github.com/golang/go/src . testing/.Tscip-go gomod github.com/golang/go/src . testing/T#) { |
| 136 | t.Parallelscip-go gomod github.com/golang/go/src . testing/T#Parallel().() |
| 137 | |
| 138 | tests := []struct { |
| 139 | name string |
| 140 | serviceURL string |
| 141 | wantTitle string |
| 142 | wantTLS bool |
| 143 | }{ |
| 144 | { |
| 145 | name: "with title", |
| 146 | serviceURL: "matrix://user:[email protected]?title=MyTitle", |
| 147 | wantTitle: "MyTitle", |
| 148 | wantTLS: false, |
| 149 | }, |
| 150 | { |
| 151 | name: "with TLS disabled", |
| 152 | serviceURL: "matrix://user:[email protected]?disableTLS=true", |
| 153 | wantTitle: "", |
| 154 | wantTLS: true, |
| 155 | }, |
| 156 | { |
| 157 | name: "with title and TLS", |
| 158 | serviceURL: "matrix://user:[email protected]?title=Alert&disableTLS=true", |
| 159 | wantTitle: "Alert", |
| 160 | wantTLS: true, |
| 161 | }, |
| 162 | } |
| 163 | |
| 164 | for _, tt := range tests { |
| 165 | t.Runscip-go gomod github.com/golang/go/src . testing/T#Run().(tt.name, func(t *testingscip-go gomod github.com/golang/go/src . testing/.Tscip-go gomod github.com/golang/go/src . testing/T#) { |
| 166 | t.Parallelscip-go gomod github.com/golang/go/src . testing/T#Parallel().() |
| 167 | |
| 168 | config := &matrixscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/matrix`/.Configscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/matrix`/Config#{} |
| 169 | |
| 170 | parsedURL, err := urlscip-go gomod github.com/golang/go/src . `net/url`/.Parsescip-go gomod github.com/golang/go/src . `net/url`/Parse().(tt.serviceURL) |
| 171 | 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, "URL should be parseable for %s", tt.name) |
| 172 | |
| 173 | err = config.SetURLscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/matrix`/Config#SetURL().(parsedURL) |
| 174 | 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, "Expected no error for %s", tt.name) |
| 175 | |
| 176 | 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.wantTitle, config.Titlescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/matrix`/Config#Title., |
| 177 | "Title mismatch for %s", tt.name) |
| 178 | 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.wantTLS, config.DisableTLSscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/matrix`/Config#DisableTLS., |
| 179 | "DisableTLS mismatch for %s", tt.name) |
| 180 | }) |
| 181 | } |
| 182 | } |
| 183 | |
| 184 | func TestConfigWithRoomsDirectscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/testing/integration/matrix_test`/TestConfigWithRoomsDirect().(t *testingscip-go gomod github.com/golang/go/src . testing/.Tscip-go gomod github.com/golang/go/src . testing/T#) { |
| 185 | t.Parallelscip-go gomod github.com/golang/go/src . testing/T#Parallel().() |
| 186 | |
| 187 | // Test setting rooms directly on config (not via URL) |
| 188 | config := &matrixscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/matrix`/.Configscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/matrix`/Config#{ |
| 189 | Roomsscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/matrix`/Config#Rooms.: []string{"#room1:example.com", "!room2:example.com"}, |
| 190 | } |
| 191 | |
| 192 | requirescip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/.Lenscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/Len().(t, config.Roomsscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/matrix`/Config#Rooms., 2) |
| 193 | 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, "#room1:example.com", config.Roomsscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/matrix`/Config#Rooms.[0]) |
| 194 | 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, "!room2:example.com", config.Roomsscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/matrix`/Config#Rooms.[1]) |
| 195 | } |