Modern Docker Management, Designed for Everyone
Go composecontainer-managementcontainersdockerdocker-composedocker-managementgoself-hostedsveltekittypescriptweb-ui
package notifications
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestBuildMatrixURL(t *testing.T) {
tests := []struct {
name string
config MatrixConfig
wantErr bool
expected string
}{
{
name: "basic config (host + token)",
config: MatrixConfig{
Host: "matrix.example.com",
Password: "t0ken",
},
wantErr: false,
expected: "matrix://:[email protected]",
},
{
name: "config with host + token + room",
config: MatrixConfig{
Host: "matrix.example.com",
Password: "t0ken",
Rooms: "!roomId",
},
wantErr: false,
expected: "matrix://:[email protected]?rooms=!roomId",
},
{
name: "config with host + username + password + room",
config: MatrixConfig{
Host: "matrix.example.com",
Username: "A12345678901234",
Password: "passw0rd",
Rooms: "!roomId",
},
wantErr: false,
expected: "matrix://A12345678901234:[email protected]?rooms=!roomId",
},
{
name: "config with host + port + username + password + room",
config: MatrixConfig{
Host: "matrix.example.com",
Port: 8443,
Username: "A12345678901234",
Password: "passw0rd",
Rooms: "!roomId",
},
wantErr: false,
expected: "matrix://A12345678901234:[email protected]:8443?rooms=!roomId",
},
{
name: "config with all options",
config: MatrixConfig{
Host: "matrix.example.com",
Port: 8443,
Username: "A12345678901234",
Password: "passw0rd",
Rooms: "!room1",
DisableTLSVerification: true,
},
wantErr: false,
expected: "matrix://A12345678901234:[email protected]:8443?disabletls=yes&rooms=!room1",
},
{
name: "missing host",
config: MatrixConfig{
Username: "A12345678901234",
},
wantErr: true,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
gotURL, err := BuildMatrixURL(tt.config)
if tt.wantErr {
require.Error(t, err)
} else {
require.NoError(t, err)
assert.Equal(t, tt.expected, gotURL)
}
})
}
}