| 1 |
# Discord Integration Tests |
| 2 |
|
| 3 |
This directory contains integration tests for the Discord service in Shoutrrr. |
| 4 |
The tests validate Discord webhook functionality by mocking HTTP requests to Discord's API, ensuring feature parity with Discord's webhook API. |
| 5 |
|
| 6 |
## Test Coverage |
| 7 |
|
| 8 |
### Content Field Support |
| 9 |
|
| 10 |
- Plain text messages with various scenarios (special characters, long messages, empty/whitespace handling) |
| 11 |
|
| 12 |
### Enhanced Embed Features |
| 13 |
|
| 14 |
- Author information (name, URL, icon URL) |
| 15 |
- Image and thumbnail URLs |
| 16 |
- Custom fields array |
| 17 |
- Timestamps |
| 18 |
- Multiple embeds with different features |
| 19 |
- Message levels with color coding (Error, Warning, Info, Debug) |
| 20 |
|
| 21 |
### File Attachments |
| 22 |
|
| 23 |
- Single and multiple file attachments |
| 24 |
- Large file handling (1MB+) |
| 25 |
- Different file types (PDF, PNG, JS, CSV, etc.) |
| 26 |
- Special characters in filenames |
| 27 |
- Rich embeds combined with file attachments |
| 28 |
|
| 29 |
### Thread Creation and Messaging |
| 30 |
|
| 31 |
- Creating new threads with `thread_name` |
| 32 |
- Posting to existing threads with `thread_id` |
| 33 |
- Whitespace handling in thread IDs |
| 34 |
- Embed messages in threads |
| 35 |
- File attachments in threads |
| 36 |
|
| 37 |
### Configuration Options |
| 38 |
|
| 39 |
- Custom username and avatar overrides |
| 40 |
- Color customization (default and per-level colors) |
| 41 |
- JSON mode for raw payloads |
| 42 |
- Message chunking for long content |
| 43 |
- Split lines option for multi-line messages |
| 44 |
|
| 45 |
### External API Interaction |
| 46 |
|
| 47 |
- HTTP request construction and sending |
| 48 |
- Response handling from mocked Discord API |
| 49 |
- Service behavior based on external API responses |
| 50 |
- Error handling for network and API failures |
| 51 |
|
| 52 |
### Error Handling and Edge Cases |
| 53 |
|
| 54 |
- HTTP error responses (400, etc.) |
| 55 |
- Network errors and invalid configurations |
| 56 |
- Malformed JSON handling |
| 57 |
- Empty file attachments |
| 58 |
- Very long filenames |
| 59 |
- Messages exceeding Discord's limits |
| 60 |
|
| 61 |
## Running the Tests |
| 62 |
|
| 63 |
### Mocked Integration Tests (Default) |
| 64 |
|
| 65 |
Run all integration tests with mocked Discord API responses: |
| 66 |
|
| 67 |
```bash |
| 68 |
go test ./testing/integration/discord/ -v |
| 69 |
``` |
| 70 |
|
| 71 |
Or run specific test files: |
| 72 |
|
| 73 |
```bash |
| 74 |
# Run specific test categories |
| 75 |
go test ./testing/integration/discord/ -run TestAPICompliance -v |
| 76 |
go test ./testing/integration/discord/ -run TestContent -v |
| 77 |
go test ./testing/integration/discord/ -run TestEdgeCases -v |
| 78 |
go test ./testing/integration/discord/ -run TestEmbeds -v |
| 79 |
go test ./testing/integration/discord/ -run TestThreads -v |
| 80 |
go test ./testing/integration/discord/ -run TestConfig -v |
| 81 |
go test ./testing/integration/discord/ -run TestFiles -v |
| 82 |
go test ./testing/integration/discord/ -run TestErrors -v |
| 83 |
go test ./testing/integration/discord/ -run TestHTTP -v |
| 84 |
``` |
| 85 |
|
| 86 |
## Test Structure |
| 87 |
|
| 88 |
The test suite is organized as a flat directory structure with individual test files for each feature category: |
| 89 |
|
| 90 |
```bash |
| 91 |
testing/integration/discord/ |
| 92 |
├── api_compliance_test.go # API compliance and webhook specification validation |
| 93 |
├── config_test.go # Configuration options (username, avatar, colors, JSON mode) |
| 94 |
├── content_test.go # Plain text message functionality |
| 95 |
├── edge_cases_test.go # Comprehensive edge case testing including empty messages, Unicode handling, control characters, very long messages up to Discord's 2000 char limit, invalid UTF-8, extremely large files 50MB+, special characters in filenames, concurrent requests, memory exhaustion scenarios, and rapid succession requests |
| 96 |
├── embeds_test.go # Embed features (author, image, thumbnail, fields, timestamps) |
| 97 |
├── errors_test.go # Error handling and edge cases |
| 98 |
├── files_test.go # File attachment functionality |
| 99 |
├── http_test.go # HTTP-related tests |
| 100 |
├── threads_test.go # Thread creation and messaging |
| 101 |
└── README.md # This documentation |
| 102 |
``` |
| 103 |
|
| 104 |
### Test Organization |
| 105 |
|
| 106 |
Each test file contains independent black-box tests for specific Discord service behaviors. |
| 107 |
Tests validate that the service correctly interacts with external APIs without inspecting internal data structures: |
| 108 |
|
| 109 |
- **API Compliance Tests** (`api_compliance_test.go`): Service behavior with different Discord API response scenarios |
| 110 |
- **Content Tests** (`content_test.go`): Service handling of various message types and external API responses |
| 111 |
- **Embed Tests** (`embeds_test.go`): Service processing of rich embed messages with mocked API responses |
| 112 |
- **Thread Tests** (`threads_test.go`): Service behavior for thread creation and messaging with external API interaction |
| 113 |
- **Config Tests** (`config_test.go`): Service configuration application in external API requests |
| 114 |
- **File Tests** (`files_test.go`): Service handling of file attachments with mocked multipart responses |
| 115 |
- **Error Tests** (`errors_test.go`): Service error handling when external APIs return failures |
| 116 |
- **Edge Cases Tests** (`edge_cases_test.go`): Service behavior under unusual conditions and API responses |