| 1 |
package matrix_test |
| 2 |
|
| 3 |
import ( |
| 4 |
"fmt" |
| 5 |
"net/url" |
| 6 |
"testing" |
| 7 |
|
| 8 |
"github.com/nicholas-fedor/shoutrrr/pkg/services/chat/matrix" |
| 9 |
) |
| 10 |
|
| 11 |
// testLogger implements types.StdLogger for testing. |
| 12 |
type testLogger struct { |
| 13 |
messages []string |
| 14 |
} |
| 15 |
|
| 16 |
// Print logs an info message. |
| 17 |
func (l *testLogger) Print(v ...any) { |
| 18 |
l.messages = append(l.messages, fmt.Sprint(v...)) |
| 19 |
} |
| 20 |
|
| 21 |
// Printf logs a formatted info message. |
| 22 |
func (l *testLogger) Printf(format string, v ...any) { |
| 23 |
l.messages = append(l.messages, fmt.Sprintf(format, v...)) |
| 24 |
} |
| 25 |
|
| 26 |
// Println logs an info message with newline. |
| 27 |
func (l *testLogger) Println(v ...any) { |
| 28 |
l.messages = append(l.messages, fmt.Sprintln(v...)) |
| 29 |
} |
| 30 |
|
| 31 |
// createTestService creates a matrix service with the given URL string. |
| 32 |
// Uses the "dummy" URL special case to avoid actual client initialization. |
| 33 |
func createTestService(t *testing.T, serviceURL string) (*matrix.Service, error) { |
| 34 |
t.Helper() |
| 35 |
|
| 36 |
parsedURL, err := url.Parse(serviceURL) |
| 37 |
if err != nil { |
| 38 |
t.Fatalf("failed to parse URL: %v", err) |
| 39 |
} |
| 40 |
|
| 41 |
service := &matrix.Service{} |
| 42 |
|
| 43 |
err = service.Initialize(parsedURL, &testLogger{}) |
| 44 |
if err != nil { |
| 45 |
return nil, err |
| 46 |
} |
| 47 |
|
| 48 |
return service, nil |
| 49 |
} |