mirror of
https://github.com/matrix-org/dendrite.git
synced 2026-01-21 13:03:09 -06:00
Add test for SigningIdentityFor
This commit is contained in:
parent
08c6f23fed
commit
8a5095c0b0
|
|
@ -16,8 +16,10 @@ package config
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"reflect"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/matrix-org/gomatrixserverlib"
|
||||||
"gopkg.in/yaml.v2"
|
"gopkg.in/yaml.v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -290,3 +292,55 @@ func TestUnmarshalDataUnit(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func Test_SigningIdentityFor(t *testing.T) {
|
||||||
|
tests := []struct {
|
||||||
|
name string
|
||||||
|
virtualHosts []*VirtualHost
|
||||||
|
serverName gomatrixserverlib.ServerName
|
||||||
|
want *gomatrixserverlib.SigningIdentity
|
||||||
|
wantErr bool
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
name: "no virtual hosts defined",
|
||||||
|
wantErr: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "no identity found",
|
||||||
|
serverName: gomatrixserverlib.ServerName("doesnotexist"),
|
||||||
|
wantErr: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "found identity",
|
||||||
|
serverName: gomatrixserverlib.ServerName("main"),
|
||||||
|
want: &gomatrixserverlib.SigningIdentity{ServerName: "main"},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "identity found on virtual hosts",
|
||||||
|
serverName: gomatrixserverlib.ServerName("vh2"),
|
||||||
|
virtualHosts: []*VirtualHost{
|
||||||
|
{SigningIdentity: gomatrixserverlib.SigningIdentity{ServerName: "vh1"}},
|
||||||
|
{SigningIdentity: gomatrixserverlib.SigningIdentity{ServerName: "vh2"}},
|
||||||
|
},
|
||||||
|
want: &gomatrixserverlib.SigningIdentity{ServerName: "vh2"},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
for _, tt := range tests {
|
||||||
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
|
c := &Global{
|
||||||
|
VirtualHosts: tt.virtualHosts,
|
||||||
|
SigningIdentity: gomatrixserverlib.SigningIdentity{
|
||||||
|
ServerName: "main",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
got, err := c.SigningIdentityFor(tt.serverName)
|
||||||
|
if (err != nil) != tt.wantErr {
|
||||||
|
t.Errorf("SigningIdentityFor() error = %v, wantErr %v", err, tt.wantErr)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if !reflect.DeepEqual(got, tt.want) {
|
||||||
|
t.Errorf("SigningIdentityFor() got = %v, want %v", got, tt.want)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue