Debian Codegraph @

testing/integration/matrix/service_test.go

raw symbols SCIP
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 TestServiceInitializeWithValidURLscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/testing/integration/matrix_test`/TestServiceInitializeWithValidURL().(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: "dummy URL for testing",
21 serviceURL: "matrix://[email protected]",
22 },
23 {
24 name: "dummy URL with password",
25 serviceURL: "matrix://dummy:[email protected]",
26 },
27 {
28 name: "dummy URL with custom title",
29 serviceURL: "matrix://[email protected]?title=Notification",
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 // Use createTestService which handles URL parsing internally
38 service, err := createTestServicescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/testing/integration/matrix_test`/createTestService().(t, tt.serviceURL)
39 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)
40 requirescip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/.NotNilscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/NotNil().(t, service, "Service should be initialized for %s", tt.name)
41 requirescip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/.NotNilscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/NotNil().(t, service.Configscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/matrix`/Service#Config., "Config should be initialized for %s", tt.name)
42 })
43 }
44 }
45
46 func TestServiceInitializeWithInvalidURLscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/testing/integration/matrix_test`/TestServiceInitializeWithInvalidURL().(t *testingscip-go gomod github.com/golang/go/src . testing/.Tscip-go gomod github.com/golang/go/src . testing/T#) {
47 t.Parallelscip-go gomod github.com/golang/go/src . testing/T#Parallel().()
48
49 tests := []struct {
50 name string
51 serviceURL string
52 wantErr error
53 }{
54 {
55 name: "missing host",
56 serviceURL: "matrix://user:token@",
57 wantErr: matrixscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/matrix`/.ErrMissingHostscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/matrix`/ErrMissingHost.,
58 },
59 {
60 name: "missing credentials",
61 serviceURL: "matrix://matrix.example.com",
62 wantErr: matrixscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/matrix`/.ErrMissingCredentialsscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/matrix`/ErrMissingCredentials.,
63 },
64 }
65
66 for _, tt := range tests {
67 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#) {
68 t.Parallelscip-go gomod github.com/golang/go/src . testing/T#Parallel().()
69
70 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#{}
71
72 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)
73 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)
74
75 err = service.Initializescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/matrix`/Service#Initialize().(parsedURL, &testLoggerscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/testing/integration/matrix_test`/testLogger#{})
76
77 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)
78
79 if tt.wantErr != nil {
80 requirescip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/.ErrorIsscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/ErrorIs().(t, err, tt.wantErr,
81 "Expected error %v, got %v", tt.wantErr, err)
82 }
83 })
84 }
85 }
86
87 func TestServiceGetIDscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/testing/integration/matrix_test`/TestServiceGetID().(t *testingscip-go gomod github.com/golang/go/src . testing/.Tscip-go gomod github.com/golang/go/src . testing/T#) {
88 t.Parallelscip-go gomod github.com/golang/go/src . testing/T#Parallel().()
89
90 service, _ := createTestServicescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/testing/integration/matrix_test`/createTestService().(t, "matrix://[email protected]")
91
92 id := service.GetIDscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/matrix`/Service#GetID().()
93
94 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, "matrix", id, "Expected service ID to be 'matrix'")
95 }
96
97 func TestServiceSendWithDummyClientscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/testing/integration/matrix_test`/TestServiceSendWithDummyClient().(t *testingscip-go gomod github.com/golang/go/src . testing/.Tscip-go gomod github.com/golang/go/src . testing/T#) {
98 t.Parallelscip-go gomod github.com/golang/go/src . testing/T#Parallel().()
99
100 // When using the dummy URL, the client is not initialized
101 // and Send should return ErrClientNotInitialized
102 service, _ := createTestServicescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/testing/integration/matrix_test`/createTestService().(t, "matrix://[email protected]")
103
104 err := service.Sendscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/matrix`/Service#Send().("Test message", nil)
105
106 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 when sending with uninitialized client")
107 requirescip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/.ErrorIsscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/ErrorIs().(t, err, matrixscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/matrix`/.ErrClientNotInitializedscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/matrix`/ErrClientNotInitialized.,
108 "Expected ErrClientNotInitialized, got %v", err)
109 }
110
111 func TestServiceSendWithNilParamsscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/testing/integration/matrix_test`/TestServiceSendWithNilParams().(t *testingscip-go gomod github.com/golang/go/src . testing/.Tscip-go gomod github.com/golang/go/src . testing/T#) {
112 t.Parallelscip-go gomod github.com/golang/go/src . testing/T#Parallel().()
113
114 // Using dummy URL - client won't be initialized
115 service, _ := createTestServicescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/testing/integration/matrix_test`/createTestService().(t, "matrix://[email protected]")
116
117 // This will fail because the client is nil, but we can verify the behavior
118 err := service.Sendscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/matrix`/Service#Send().("Test message", nil)
119
120 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)
121 requirescip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/.ErrorIsscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/ErrorIs().(t, err, matrixscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/matrix`/.ErrClientNotInitializedscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/matrix`/ErrClientNotInitialized.)
122 }
123
124 func TestServiceSendWithEmptyMessagescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/testing/integration/matrix_test`/TestServiceSendWithEmptyMessage().(t *testingscip-go gomod github.com/golang/go/src . testing/.Tscip-go gomod github.com/golang/go/src . testing/T#) {
125 t.Parallelscip-go gomod github.com/golang/go/src . testing/T#Parallel().()
126
127 service, _ := createTestServicescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/testing/integration/matrix_test`/createTestService().(t, "matrix://[email protected]")
128
129 err := service.Sendscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/matrix`/Service#Send().("", nil)
130
131 // Even empty messages will fail with client not initialized
132 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)
133 }
134
135 func TestServiceSendWithValidConfigscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/testing/integration/matrix_test`/TestServiceSendWithValidConfig().(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 // This test verifies that the service can be created with valid config
139 // and the config values are correctly set
140 service, err := createTestServicescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/testing/integration/matrix_test`/createTestService().(t, "matrix://dummy:[email protected]")
141 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 dummy URL")
142 requirescip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/.NotNilscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/NotNil().(t, service, "Service should not be nil")
143
144 // Verify the config is set correctly
145 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, "dummy.com", service.Configscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/matrix`/Service#Config..Hostscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/matrix`/Config#Host.)
146 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, "token", service.Configscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/matrix`/Service#Config..Passwordscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/matrix`/Config#Password.)
147 }