Debian Codegraph @

testing/e2e/matrix/matrix_suite_test.go

raw symbols SCIP
1 package e2e_testscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/testing/e2e/matrix_test`/
2
3 import (
4 "bufioscip-go gomod github.com/golang/go/src . bufio/"
5 "errorsscip-go gomod github.com/golang/go/src . errors/"
6 "fmtscip-go gomod github.com/golang/go/src . fmt/"
7 "net/urlscip-go gomod github.com/golang/go/src . `net/url`/"
8 "osscip-go gomod github.com/golang/go/src . os/"
9 "stringsscip-go gomod github.com/golang/go/src . strings/"
10 "syncscip-go gomod github.com/golang/go/src . sync/"
11 "testingscip-go gomod github.com/golang/go/src . testing/"
12 "timescip-go gomod github.com/golang/go/src . time/"
13
14 "github.com/onsi/ginkgo/v2scip-go gomod github.com/onsi/ginkgo/v2 v2.32.1 `github.com/onsi/ginkgo/v2`/"
15 "github.com/onsi/gomegascip-go gomod github.com/onsi/gomega v1.42.1 `github.com/onsi/gomega`/"
16
17 "github.com/nicholas-fedor/shoutrrr/internal/testutilsscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/internal/testutils`/"
18 "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`/"
19 )
20
21 const envValueTruescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/testing/e2e/matrix_test`/envValueTrue. = "true"
22
23 // sharedService is the authenticated Matrix service shared across tests.
24 // Initialized once in BeforeSuite to avoid repeated login operations.
25 var (
26 sharedServicescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/testing/e2e/matrix_test`/sharedService. *matrixscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/matrix`/.Servicescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/matrix`/Service#
27 sharedServiceOncescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/testing/e2e/matrix_test`/sharedServiceOnce. syncscip-go gomod github.com/golang/go/src . sync/.Oncescip-go gomod github.com/golang/go/src . sync/Once#
28 errSharedServiceInitscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/testing/e2e/matrix_test`/errSharedServiceInit. error
29 )
30
31 // Test_Matrix_E2E runs the Matrix E2E test suite using Ginkgo.
32 // These tests connect to a real Matrix server and verify actual behavior.
33 func Test_Matrix_E2Escip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/testing/e2e/matrix_test`/Test_Matrix_E2E().(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
36 // Load .env file if it exists
37 loadEnvFilescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/testing/e2e/matrix_test`/loadEnvFile().(".env")
38
39 gomegascip-go gomod github.com/onsi/gomega v1.42.1 `github.com/onsi/gomega`/.RegisterFailHandlerscip-go gomod github.com/onsi/gomega v1.42.1 `github.com/onsi/gomega`/RegisterFailHandler().(ginkgoscip-go gomod github.com/onsi/ginkgo/v2 v2.32.1 `github.com/onsi/ginkgo/v2`/.Failscip-go gomod github.com/onsi/ginkgo/v2 v2.32.1 `github.com/onsi/ginkgo/v2`/Fail().)
40
41 // Initialize shared service once before all tests
42 ginkgoscip-go gomod github.com/onsi/ginkgo/v2 v2.32.1 `github.com/onsi/ginkgo/v2`/.BeforeSuitescip-go gomod github.com/onsi/ginkgo/v2 v2.32.1 `github.com/onsi/ginkgo/v2`/BeforeSuite().(func() {
43 serviceURL := buildServiceURLscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/testing/e2e/matrix_test`/buildServiceURL().()
44 if serviceURL == "" {
45 return // tests will skip anyway
46 }
47
48 parsedURL, err := urlscip-go gomod github.com/golang/go/src . `net/url`/.Parsescip-go gomod github.com/golang/go/src . `net/url`/Parse().(serviceURL)
49 if err != nil {
50 return
51 }
52
53 // Create a local service instance and only assign to sharedService
54 // after Initialize succeeds to prevent tests from using an
55 // uninitialized client.
56 service := &matrixscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/matrix`/.Servicescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/matrix`/Service#{}
57 if err := service.Initializescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/matrix`/Service#Initialize().(parsedURL, testutilsscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/internal/testutils`/.TestLoggerscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/internal/testutils`/TestLogger().()); err != nil {
58 // Log but continue; individual tests will handle failures
59 fmtscip-go gomod github.com/golang/go/src . fmt/.Printfscip-go gomod github.com/golang/go/src . fmt/Printf().("Warning: shared service init failed: %v\n", err)
60
61 return
62 }
63
64 sharedServicescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/testing/e2e/matrix_test`/sharedService. = service
65 })
66
67 ginkgoscip-go gomod github.com/onsi/ginkgo/v2 v2.32.1 `github.com/onsi/ginkgo/v2`/.BeforeEachscip-go gomod github.com/onsi/ginkgo/v2 v2.32.1 `github.com/onsi/ginkgo/v2`/BeforeEach().(func() {
68 timescip-go gomod github.com/golang/go/src . time/.Sleepscip-go gomod github.com/golang/go/src . time/Sleep().(500 * timescip-go gomod github.com/golang/go/src . time/.Millisecondscip-go gomod github.com/golang/go/src . time/Millisecond.) // slightly longer safety delay
69 })
70
71 ginkgoscip-go gomod github.com/onsi/ginkgo/v2 v2.32.1 `github.com/onsi/ginkgo/v2`/.RunSpecsscip-go gomod github.com/onsi/ginkgo/v2 v2.32.1 `github.com/onsi/ginkgo/v2`/RunSpecs().(t, "Matrix E2E Tests")
72 }
73
74 // matrixServerURL returns the Matrix server URL from environment or default.
75 // Expected format: matrix://user:password@host:port
76 func matrixServerURLscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/testing/e2e/matrix_test`/matrixServerURL().() string {
77 // Check for URL in environment variable
78 envURL := osscip-go gomod github.com/golang/go/src . os/.Getenvscip-go gomod github.com/golang/go/src . os/Getenv().("SHOUTRRR_MATRIX_URL")
79 if envURL != "" {
80 return envURL
81 }
82
83 // Build URL from individual components
84 host := osscip-go gomod github.com/golang/go/src . os/.Getenvscip-go gomod github.com/golang/go/src . os/Getenv().("SHOUTRRR_MATRIX_HOST")
85 if host == "" {
86 host = "localhost:8008"
87 }
88
89 user := osscip-go gomod github.com/golang/go/src . os/.Getenvscip-go gomod github.com/golang/go/src . os/Getenv().("SHOUTRRR_MATRIX_USER")
90 password := osscip-go gomod github.com/golang/go/src . os/.Getenvscip-go gomod github.com/golang/go/src . os/Getenv().("SHOUTRRR_MATRIX_PASSWORD")
91
92 if user != "" && password != "" {
93 return "matrix://" + urlscip-go gomod github.com/golang/go/src . `net/url`/.UserPasswordscip-go gomod github.com/golang/go/src . `net/url`/UserPassword().(user, password).Stringscip-go gomod github.com/golang/go/src . `net/url`/Userinfo#String().() + "@" + host
94 }
95
96 // Return empty string if no credentials available
97 return ""
98 }
99
100 // matrixRoom returns the Matrix room from environment or default test room.
101 func matrixRoomscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/testing/e2e/matrix_test`/matrixRoom().() string {
102 room := osscip-go gomod github.com/golang/go/src . os/.Getenvscip-go gomod github.com/golang/go/src . os/Getenv().("SHOUTRRR_MATRIX_ROOM")
103 if room != "" {
104 return room
105 }
106
107 // Default test room alias
108 return "#test:localhost"
109 }
110
111 // matrixDisableTLS returns whether TLS should be disabled.
112 func matrixDisableTLSscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/testing/e2e/matrix_test`/matrixDisableTLS().() bool {
113 return osscip-go gomod github.com/golang/go/src . os/.Getenvscip-go gomod github.com/golang/go/src . os/Getenv().("SHOUTRRR_MATRIX_DISABLE_TLS") == envValueTruescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/testing/e2e/matrix_test`/envValueTrue.
114 }
115
116 // buildServiceURL builds a complete Matrix service URL with all parameters.
117 func buildServiceURLscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/testing/e2e/matrix_test`/buildServiceURL().() string {
118 baseURL := matrixServerURLscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/testing/e2e/matrix_test`/matrixServerURL().()
119
120 // If no URL from environment, return empty
121 if baseURL == "" {
122 return ""
123 }
124
125 // Parse to add query params
126 parsedURL, err := urlscip-go gomod github.com/golang/go/src . `net/url`/.Parsescip-go gomod github.com/golang/go/src . `net/url`/Parse().(baseURL)
127 if err != nil {
128 return ""
129 }
130
131 // Add room parameter
132 room := matrixRoomscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/testing/e2e/matrix_test`/matrixRoom().()
133 if room != "" {
134 q := parsedURL.Queryscip-go gomod github.com/golang/go/src . `net/url`/URL#Query().()
135 q.Addscip-go gomod github.com/golang/go/src . `net/url`/Values#Add().("room", room)
136 parsedURL.RawQueryscip-go gomod github.com/golang/go/src . `net/url`/URL#RawQuery. = q.Encodescip-go gomod github.com/golang/go/src . `net/url`/Values#Encode().()
137 }
138
139 // Add TLS disable if needed
140 if matrixDisableTLSscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/testing/e2e/matrix_test`/matrixDisableTLS().() {
141 q := parsedURL.Queryscip-go gomod github.com/golang/go/src . `net/url`/URL#Query().()
142 q.Addscip-go gomod github.com/golang/go/src . `net/url`/Values#Add().("disableTLS", "true")
143 parsedURL.RawQueryscip-go gomod github.com/golang/go/src . `net/url`/URL#RawQuery. = q.Encodescip-go gomod github.com/golang/go/src . `net/url`/Values#Encode().()
144 }
145
146 return parsedURL.Stringscip-go gomod github.com/golang/go/src . `net/url`/URL#String().()
147 }
148
149 // loadEnvFile loads environment variables from a .env file.
150 func loadEnvFilescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/testing/e2e/matrix_test`/loadEnvFile().(filename string) {
151 file, err := osscip-go gomod github.com/golang/go/src . os/.Openscip-go gomod github.com/golang/go/src . os/Open().(filename)
152 if err != nil {
153 // .env file doesn't exist, skip loading
154 return
155 }
156
157 defer func() { _ = file.Closescip-go gomod github.com/golang/go/src . os/File#Close().() }()
158
159 scanner := bufioscip-go gomod github.com/golang/go/src . bufio/.NewScannerscip-go gomod github.com/golang/go/src . bufio/NewScanner().(file)
160 for scanner.Scanscip-go gomod github.com/golang/go/src . bufio/Scanner#Scan().() {
161 line := stringsscip-go gomod github.com/golang/go/src . strings/.TrimSpacescip-go gomod github.com/golang/go/src . strings/TrimSpace().(scanner.Textscip-go gomod github.com/golang/go/src . bufio/Scanner#Text().())
162 if line == "" || stringsscip-go gomod github.com/golang/go/src . strings/.HasPrefixscip-go gomod github.com/golang/go/src . strings/HasPrefix().(line, "#") {
163 continue
164 }
165
166 parts := stringsscip-go gomod github.com/golang/go/src . strings/.SplitNscip-go gomod github.com/golang/go/src . strings/SplitN().(line, "=", 2)
167 if len(parts) == 2 {
168 key := stringsscip-go gomod github.com/golang/go/src . strings/.TrimSpacescip-go gomod github.com/golang/go/src . strings/TrimSpace().(parts[0])
169 value := stringsscip-go gomod github.com/golang/go/src . strings/.TrimSpacescip-go gomod github.com/golang/go/src . strings/TrimSpace().(parts[1])
170 // Remove quotes if present
171 value = stringsscip-go gomod github.com/golang/go/src . strings/.Trimscip-go gomod github.com/golang/go/src . strings/Trim().(value, `"'`)
172 // Only set if not already present in the environment
173 if _, exists := osscip-go gomod github.com/golang/go/src . os/.LookupEnvscip-go gomod github.com/golang/go/src . os/LookupEnv().(key); !exists {
174 _ = osscip-go gomod github.com/golang/go/src . os/.Setenvscip-go gomod github.com/golang/go/src . os/Setenv().(key, value) // Ignore error as it's test setup
175 }
176 }
177 }
178
179 if err := scanner.Errscip-go gomod github.com/golang/go/src . bufio/Scanner#Err().(); err != nil {
180 return
181 }
182 }
183
184 // getOrInitSharedService initializes the shared Matrix service once in a
185 // thread-safe manner if it hasn't been initialized yet. If BeforeSuite has
186 // already initialized sharedService, it returns the existing instance without
187 // re-initializing.
188 func getOrInitSharedServicescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/testing/e2e/matrix_test`/getOrInitSharedService().() error {
189 // Check if sharedService was already initialized (e.g., by BeforeSuite)
190 if sharedServicescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/testing/e2e/matrix_test`/sharedService. != nil {
191 return nil
192 }
193
194 sharedServiceOncescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/testing/e2e/matrix_test`/sharedServiceOnce..Doscip-go gomod github.com/golang/go/src . sync/Once#Do().(func() {
195 serviceURL := buildServiceURLscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/testing/e2e/matrix_test`/buildServiceURL().()
196 if serviceURL == "" {
197 errSharedServiceInitscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/testing/e2e/matrix_test`/errSharedServiceInit. = errorsscip-go gomod github.com/golang/go/src . errors/.Newscip-go gomod github.com/golang/go/src . errors/New().("Matrix server not configured")
198
199 return
200 }
201
202 parsedURL, err := urlscip-go gomod github.com/golang/go/src . `net/url`/.Parsescip-go gomod github.com/golang/go/src . `net/url`/Parse().(serviceURL)
203 if err != nil {
204 errSharedServiceInitscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/testing/e2e/matrix_test`/errSharedServiceInit. = fmtscip-go gomod github.com/golang/go/src . fmt/.Errorfscip-go gomod github.com/golang/go/src . fmt/Errorf().("parsing service URL: %w", err)
205
206 return
207 }
208
209 // Create a local service instance and only assign to sharedService
210 // after Initialize succeeds to prevent tests from using an
211 // uninitialized client.
212 service := &matrixscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/matrix`/.Servicescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/matrix`/Service#{}
213 if err := service.Initializescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/matrix`/Service#Initialize().(parsedURL, testutilsscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/internal/testutils`/.TestLoggerscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/internal/testutils`/TestLogger().()); err != nil {
214 errSharedServiceInitscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/testing/e2e/matrix_test`/errSharedServiceInit. = fmtscip-go gomod github.com/golang/go/src . fmt/.Errorfscip-go gomod github.com/golang/go/src . fmt/Errorf().("initializing service: %w", err)
215
216 return
217 }
218
219 sharedServicescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/testing/e2e/matrix_test`/sharedService. = service
220 })
221
222 return errSharedServiceInitscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/testing/e2e/matrix_test`/errSharedServiceInit.
223 }