Skip to content

Commit dcea884

Browse files
ci: Start implementing integration tests for xmpp
1 parent fe828cc commit dcea884

19 files changed

Lines changed: 923 additions & 192 deletions

File tree

.github/workflows/codeql-analysis.yml

Lines changed: 0 additions & 71 deletions
This file was deleted.

.github/workflows/development.yml

Lines changed: 81 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,87 @@
11
name: Development
22
on: [push, pull_request]
33
jobs:
4-
lint:
5-
name: golangci-lint
4+
# lint:
5+
# name: golangci-lint
6+
# runs-on: ubuntu-latest
7+
# steps:
8+
# - uses: actions/checkout@v3
9+
# with:
10+
# fetch-depth: 20
11+
# - name: Run golangci-lint
12+
# uses: golangci/golangci-lint-action@v3
13+
# with:
14+
# version: latest
15+
# args: "-v --new-from-rev HEAD~5 --timeout=5m"
16+
# test-build-upload:
17+
# strategy:
18+
# matrix:
19+
# go-version: [1.22.x]
20+
# platform: [ubuntu-latest]
21+
# runs-on: ${{ matrix.platform }}
22+
# steps:
23+
# - name: Install Go
24+
# uses: actions/setup-go@v3
25+
# with:
26+
# go-version: ${{ matrix.go-version }}
27+
# stable: false
28+
# - name: Checkout code
29+
# uses: actions/checkout@v3
30+
# with:
31+
# fetch-depth: 0
32+
# - name: Test
33+
# run: go test ./... -mod=vendor
34+
# - name: Build
35+
# run: |
36+
# mkdir -p output/{win,lin,arm,mac}
37+
# VERSION=$(git describe --tags)
38+
# CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags "-s -X github.com/42wim/matterbridge/version.GitHash=$(git log --pretty=format:'%h' -n 1)" -o output/lin/matterbridge-$VERSION-linux-amd64
39+
# CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build -ldflags "-s -X github.com/42wim/matterbridge/version.GitHash=$(git log --pretty=format:'%h' -n 1)" -o output/win/matterbridge-$VERSION-windows-amd64.exe
40+
# CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build -ldflags "-s -X github.com/42wim/matterbridge/version.GitHash=$(git log --pretty=format:'%h' -n 1)" -o output/mac/matterbridge-$VERSION-darwin-amd64
41+
# - name: Upload linux 64-bit
42+
# if: startsWith(matrix.go-version,'1.22')
43+
# uses: actions/upload-artifact@v3
44+
# with:
45+
# name: matterbridge-linux-64bit
46+
# path: output/lin
47+
# - name: Upload windows 64-bit
48+
# if: startsWith(matrix.go-version,'1.22')
49+
# uses: actions/upload-artifact@v3
50+
# with:
51+
# name: matterbridge-windows-64bit
52+
# path: output/win
53+
# - name: Upload darwin 64-bit
54+
# if: startsWith(matrix.go-version,'1.22')
55+
# uses: actions/upload-artifact@v3
56+
# with:
57+
# name: matterbridge-darwin-64bit
58+
# path: output/mac
59+
integration:
60+
name: Integration tests
661
runs-on: ubuntu-latest
762
steps:
8-
- uses: actions/checkout@v3
63+
- uses: actions/checkout@v5
64+
- uses: actions/setup-go@v6
965
with:
10-
fetch-depth: 20
11-
- name: Run golangci-lint
12-
uses: golangci/golangci-lint-action@v3
13-
with:
14-
version: latest
15-
args: "-v --new-from-rev HEAD~5 --timeout=5m"
16-
test-build-upload:
17-
strategy:
18-
matrix:
19-
go-version: [1.22.x]
20-
platform: [ubuntu-latest]
21-
runs-on: ${{ matrix.platform }}
22-
steps:
23-
- name: Install Go
24-
uses: actions/setup-go@v3
25-
with:
26-
go-version: ${{ matrix.go-version }}
27-
stable: false
28-
- name: Checkout code
29-
uses: actions/checkout@v3
30-
with:
31-
fetch-depth: 0
32-
- name: Test
33-
run: go test ./... -mod=vendor
34-
- name: Build
35-
run: |
36-
mkdir -p output/{win,lin,arm,mac}
37-
VERSION=$(git describe --tags)
38-
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags "-s -X github.com/42wim/matterbridge/version.GitHash=$(git log --pretty=format:'%h' -n 1)" -o output/lin/matterbridge-$VERSION-linux-amd64
39-
CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build -ldflags "-s -X github.com/42wim/matterbridge/version.GitHash=$(git log --pretty=format:'%h' -n 1)" -o output/win/matterbridge-$VERSION-windows-amd64.exe
40-
CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build -ldflags "-s -X github.com/42wim/matterbridge/version.GitHash=$(git log --pretty=format:'%h' -n 1)" -o output/mac/matterbridge-$VERSION-darwin-amd64
41-
- name: Upload linux 64-bit
42-
if: startsWith(matrix.go-version,'1.22')
43-
uses: actions/upload-artifact@v3
44-
with:
45-
name: matterbridge-linux-64bit
46-
path: output/lin
47-
- name: Upload windows 64-bit
48-
if: startsWith(matrix.go-version,'1.22')
49-
uses: actions/upload-artifact@v3
50-
with:
51-
name: matterbridge-windows-64bit
52-
path: output/win
53-
- name: Upload darwin 64-bit
54-
if: startsWith(matrix.go-version,'1.22')
55-
uses: actions/upload-artifact@v3
56-
with:
57-
name: matterbridge-darwin-64bit
58-
path: output/mac
66+
go-version: stable
67+
# Install prosody's latest release from upstream
68+
- run: sudo wget https://prosody.im/downloads/repos/$(lsb_release -sc)/prosody.sources -O/etc/apt/sources.list.d/prosody.sources
69+
- run: sudo apt update
70+
- run: sudo apt install -y mercurial lua5.4
71+
- run: sudo update-alternatives --set lua-interpreter /usr/bin/lua5.4
72+
- run: sudo apt install -y prosody
73+
# Setup prosody community modules
74+
- run: hg clone https://hg.prosody.im/prosody-modules/ prosody-modules
75+
# Copy mod_auth_any to global prosody modules
76+
- run: sudo cp -R prosody-modules/mod_auth_any /usr/lib/prosody/modules/
77+
# Only one test is run for now
78+
- run: ./tests/test.sh xmpp outgoing-message
79+
# Upload logs when it failed
80+
- run: cat tests/xmpp/setup.log
81+
if: ${{ failure() }}
82+
- run: cat tests/xmpp/matterbridge.log
83+
if: ${{ failure() }}
84+
- run: cat tests/xmpp/xmpp.log
85+
if: ${{ failure() }}
86+
- run: cat tests/xmpp/api.log
87+
if: ${{ failure() }}

.github/workflows/docker.yml

Lines changed: 0 additions & 68 deletions
This file was deleted.

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,5 @@ matterbridge.toml
77

88
# Exclude IDE Files
99
.vscode
10+
11+
tests/**/*.log

bridge/xmpp/xmpp.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,8 @@ func (b *Bxmpp) JoinChannel(channel config.ChannelInfo) error {
6262
b.Log.Debugf("using key %s for channel %s", channel.Options.Key, channel.Name)
6363
b.xc.JoinProtectedMUC(channel.Name+"@"+b.GetString("Muc"), b.GetString("Nick"), channel.Options.Key, xmpp.NoHistory, 0, nil)
6464
} else {
65-
b.xc.JoinMUCNoHistory(channel.Name+"@"+b.GetString("Muc"), b.GetString("Nick"))
65+
// TODO: tihs creates the room if it doesn't exist yet, should it be the default?
66+
b.xc.JoinOrCreateMUCNoHistoryDoNotUseOutsideTests(channel.Name+"@"+b.GetString("Muc"), b.GetString("Nick"))
6667
}
6768
return nil
6869
}

tests/README.md

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
# Integration tests
2+
3+
This directory is for integration tests only. Unit tests reside in their
4+
respective modules.
5+
6+
## Motivation
7+
8+
Unit testing only checks that assumptions within the code are held. Integration
9+
tests can provide real-life testing capabilities to ensure that a feature is
10+
implemented properly, even when going through the remote chat service.
11+
12+
## Methodology
13+
14+
Each matterbrige supported protocol has its own corresponding folder in this
15+
`tests` folder. Each protocol's integration's tests:
16+
17+
- are run in a specific CI job with a specific environment
18+
- are documented to be run locally with a specific environment
19+
- provides implementation for incoming tests, and outgoing tests to avoid
20+
feature mismatch (for example, a bridge that could receive attachments
21+
from other networks but not the other way around)
22+
- are run sequentially, although different protocols are tested in parallel
23+
24+
> [!NOTE]
25+
> `incoming` refers to a message received on that protocol (to be delivered
26+
> to others via matterbridge), while `outgoing` refers to a message received
27+
> from another matterbridge protocol to be delivered to this protocol.
28+
29+
## Architecture
30+
31+
At the moment, integration tests require 3 components to play together:
32+
33+
- a real matterbridge instance configured with a protocol account (`pa`) to a protocol room (`pr`)
34+
- another protocol client (`pc`), connected to the same protocol room (`pr`), following a test scenario
35+
- a matterbridge API client (`ac`), connected client following the same test scenario (called `ac`)
36+
37+
> [!NOTE]
38+
> For each tested protocol, the test suite requires two accounts on the remote server.
39+
40+
The `matterbridge.toml` in each integration test folder determines the config
41+
used for the matterbridge daemon used in the tests.
42+
43+
The API client is located in `tests/api/api.go` and accepts as arguments:
44+
45+
- one of the supported tests (eg. `incoming-message`)
46+
- a timeout in seconds, after which it will automatically fail (default: 5)
47+
48+
The protocol client is located in `tests/PROTOCOL/PROTOCOL.go`, is a proper
49+
go module that can be run with `go run .`, and accepts as arguments:
50+
51+
- one of the supported tests (eg. `incoming-message`)
52+
- a timeout in seconds, after which it will automatically fail (default: 5)
53+
54+
Both binaries:
55+
56+
- run in the background, with the same set of CLI arguments
57+
- fail the entire pipeline if they individually fail
58+
- success as soon as the testing criteria is met
59+
60+
For example, in the case of the `incoming-message` test, the protocol client
61+
will successfully exit as soon as the message is sent without errors,
62+
but the API client will wait and either:
63+
64+
- successfully exit when receiving the `test-incoming-message`
65+
- fail after the timeout was reached
66+
67+
## Supported tests
68+
69+
The following test scenarios are supported at the moment:
70+
71+
- `incoming-message` steps:
72+
- `pc` sends `test-incoming-message` in `pr` using the native protocol
73+
- `ac` receives `<pc> test-incoming-message` in `pr` using the matterbridge API
74+
- `outgoing-message` steps:
75+
- `ac` sends `test-outgoing-message` in `pr` using the matterbridge API
76+
- `pc` receives `<ac> test-outgoing-message` in `pr` using the native protocol

tests/api/api

8.33 MB
Binary file not shown.

0 commit comments

Comments
 (0)