Debian Codegraph @

testing/e2e/mqtt/suite_test.go

raw symbols SCIP
1 package e2e_testscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/testing/e2e/mqtt_test`/
2
3 import (
4 "bufioscip-go gomod github.com/golang/go/src . bufio/"
5 "net/urlscip-go gomod github.com/golang/go/src . `net/url`/"
6 "osscip-go gomod github.com/golang/go/src . os/"
7 "stringsscip-go gomod github.com/golang/go/src . strings/"
8 "testingscip-go gomod github.com/golang/go/src . testing/"
9 "timescip-go gomod github.com/golang/go/src . time/"
10
11 "github.com/onsi/ginkgo/v2scip-go gomod github.com/onsi/ginkgo/v2 v2.32.1 `github.com/onsi/ginkgo/v2`/"
12 "github.com/onsi/gomegascip-go gomod github.com/onsi/gomega v1.42.1 `github.com/onsi/gomega`/"
13 )
14
15 // envValueTrue is the string value for boolean true in environment variables.
16 const envValueTruescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/testing/e2e/mqtt_test`/envValueTrue. = "true"
17
18 //nolint:paralleltest // Avoid using parallel test when making external calls
19 func Test_MQTT_E2Escip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/testing/e2e/mqtt_test`/Test_MQTT_E2E().(t *testingscip-go gomod github.com/golang/go/src . testing/.Tscip-go gomod github.com/golang/go/src . testing/T#) {
20 // Load .env file if it exists
21 loadEnvFilescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/testing/e2e/mqtt_test`/loadEnvFile().(".env")
22
23 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().)
24
25 // Add delay between tests to respect broker rate limits
26 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() {
27 // Add a small delay between tests to avoid overwhelming the broker
28 timescip-go gomod github.com/golang/go/src . time/.Sleepscip-go gomod github.com/golang/go/src . time/Sleep().(100 * timescip-go gomod github.com/golang/go/src . time/.Millisecondscip-go gomod github.com/golang/go/src . time/Millisecond.)
29 })
30
31 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, "MQTT E2E Tests")
32 }
33
34 // addCredentialsToURL adds username and password from environment variables to the URL
35 // if they are set. Returns the modified URL string.
36 func addCredentialsToURLscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/testing/e2e/mqtt_test`/addCredentialsToURL().(envURL string) string {
37 username := osscip-go gomod github.com/golang/go/src . os/.Getenvscip-go gomod github.com/golang/go/src . os/Getenv().("SHOUTRRR_MQTT_USERNAME")
38 password := osscip-go gomod github.com/golang/go/src . os/.Getenvscip-go gomod github.com/golang/go/src . os/Getenv().("SHOUTRRR_MQTT_PASSWORD")
39
40 // If either username or password is set, add them to the URL
41 if username != "" || password != "" {
42 serviceURL, err := urlscip-go gomod github.com/golang/go/src . `net/url`/.Parsescip-go gomod github.com/golang/go/src . `net/url`/Parse().(envURL)
43 if err != nil {
44 return envURL
45 }
46
47 // Build host with credentials
48 host := serviceURL.Hostscip-go gomod github.com/golang/go/src . `net/url`/URL#Host.
49
50 if username != "" {
51 if password != "" {
52 host = username + ":" + password + "@" + host
53 } else {
54 host = username + "@" + host
55 }
56 }
57
58 // Reconstruct URL with credentials
59 newURL := serviceURL.Schemescip-go gomod github.com/golang/go/src . `net/url`/URL#Scheme. + "://" + host + serviceURL.Pathscip-go gomod github.com/golang/go/src . `net/url`/URL#Path.
60 if serviceURL.RawQueryscip-go gomod github.com/golang/go/src . `net/url`/URL#RawQuery. != "" {
61 newURL += "?" + serviceURL.RawQueryscip-go gomod github.com/golang/go/src . `net/url`/URL#RawQuery.
62 }
63
64 return newURL
65 }
66
67 return envURL
68 }
69
70 // addTLSParam adds TLS skip verify parameter to URL if enabled via environment variable.
71 func addTLSParamscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/testing/e2e/mqtt_test`/addTLSParam().(rawURL string) string {
72 tlsSkipVerify := osscip-go gomod github.com/golang/go/src . os/.Getenvscip-go gomod github.com/golang/go/src . os/Getenv().("SHOUTRRR_MQTT_TLS_SKIP_VERIFY")
73 if tlsSkipVerify == envValueTruescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/testing/e2e/mqtt_test`/envValueTrue. {
74 if stringsscip-go gomod github.com/golang/go/src . strings/.Containsscip-go gomod github.com/golang/go/src . strings/Contains().(rawURL, "?") {
75 return rawURL + "&disabletlsverification=yes"
76 }
77
78 return rawURL + "?disabletlsverification=yes"
79 }
80
81 return rawURL
82 }
83
84 // loadEnvFile loads environment variables from a .env file.
85 func loadEnvFilescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/testing/e2e/mqtt_test`/loadEnvFile().(filename string) {
86 file, err := osscip-go gomod github.com/golang/go/src . os/.Openscip-go gomod github.com/golang/go/src . os/Open().(filename)
87 if err != nil {
88 // .env file doesn't exist, skip loading
89 return
90 }
91
92 defer func() { _ = file.Closescip-go gomod github.com/golang/go/src . os/File#Close().() }()
93
94 scanner := bufioscip-go gomod github.com/golang/go/src . bufio/.NewScannerscip-go gomod github.com/golang/go/src . bufio/NewScanner().(file)
95 for scanner.Scanscip-go gomod github.com/golang/go/src . bufio/Scanner#Scan().() {
96 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().())
97 if line == "" || stringsscip-go gomod github.com/golang/go/src . strings/.HasPrefixscip-go gomod github.com/golang/go/src . strings/HasPrefix().(line, "#") {
98 continue
99 }
100
101 parts := stringsscip-go gomod github.com/golang/go/src . strings/.SplitNscip-go gomod github.com/golang/go/src . strings/SplitN().(line, "=", 2)
102 if len(parts) == 2 {
103 key := stringsscip-go gomod github.com/golang/go/src . strings/.TrimSpacescip-go gomod github.com/golang/go/src . strings/TrimSpace().(parts[0])
104 value := stringsscip-go gomod github.com/golang/go/src . strings/.TrimSpacescip-go gomod github.com/golang/go/src . strings/TrimSpace().(parts[1])
105 // Remove quotes if present
106 value = stringsscip-go gomod github.com/golang/go/src . strings/.Trimscip-go gomod github.com/golang/go/src . strings/Trim().(value, `"'`)
107 _ = 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
108 }
109 }
110
111 if err := scanner.Errscip-go gomod github.com/golang/go/src . bufio/Scanner#Err().(); err != nil {
112 return
113 }
114 }