mirror of
https://github.com/matrix-org/dendrite.git
synced 2025-12-26 00:03:09 -06:00
Linting
This commit is contained in:
parent
88faf7104c
commit
0a7855c894
|
|
@ -117,10 +117,7 @@ func spacesHandler(db Database, rsAPI roomserver.RoomserverInternalAPI) func(*ht
|
|||
rsAPI: rsAPI,
|
||||
inMemoryBatchCache: inMemoryBatchCache,
|
||||
}
|
||||
res, resErr := w.walk()
|
||||
if resErr != nil {
|
||||
return *resErr
|
||||
}
|
||||
res := w.walk()
|
||||
return util.JSONResponse{
|
||||
Code: 200,
|
||||
JSON: res,
|
||||
|
|
@ -162,7 +159,8 @@ func (w *walker) markSent(id string) {
|
|||
w.inMemoryBatchCache[w.caller.UserID+"|"+w.caller.ID] = m
|
||||
}
|
||||
|
||||
func (w *walker) walk() (*SpacesResponse, *util.JSONResponse) {
|
||||
// nolint:gocyclo
|
||||
func (w *walker) walk() *SpacesResponse {
|
||||
var res SpacesResponse
|
||||
// Begin walking the graph starting with the room ID in the request in a queue of unvisited rooms
|
||||
unvisited := []string{w.rootRoomID}
|
||||
|
|
@ -255,7 +253,7 @@ func (w *walker) walk() (*SpacesResponse, *util.JSONResponse) {
|
|||
unvisited = append(unvisited, roomID)
|
||||
}
|
||||
}
|
||||
return &res, nil
|
||||
return &res
|
||||
}
|
||||
|
||||
func (w *walker) stateEvent(roomID, evType, stateKey string) *gomatrixserverlib.HeaderedEvent {
|
||||
|
|
@ -341,19 +339,6 @@ func (w *walker) references(roomID string) (eventLookup, error) {
|
|||
// NOT THREAD SAFE
|
||||
type eventLookup map[string][]*gomatrixserverlib.HeaderedEvent
|
||||
|
||||
func (el eventLookup) get(roomID, evType, stateKey string) *gomatrixserverlib.HeaderedEvent {
|
||||
evs := el[evType]
|
||||
if len(evs) == 0 {
|
||||
return nil
|
||||
}
|
||||
for _, ev := range evs {
|
||||
if ev.RoomID() == roomID && ev.StateKeyEquals(stateKey) {
|
||||
return ev
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (el eventLookup) set(ev *gomatrixserverlib.HeaderedEvent) {
|
||||
evs := el[ev.Type()]
|
||||
if evs == nil {
|
||||
|
|
|
|||
|
|
@ -18,15 +18,11 @@ import (
|
|||
"bytes"
|
||||
"context"
|
||||
"crypto/ed25519"
|
||||
"crypto/sha256"
|
||||
"encoding/base64"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"sort"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
|
|
@ -36,7 +32,6 @@ import (
|
|||
roomserver "github.com/matrix-org/dendrite/roomserver/api"
|
||||
"github.com/matrix-org/dendrite/setup"
|
||||
"github.com/matrix-org/dendrite/setup/config"
|
||||
"github.com/matrix-org/dendrite/setup/mscs/msc2836"
|
||||
"github.com/matrix-org/dendrite/setup/mscs/msc2946"
|
||||
userapi "github.com/matrix-org/dendrite/userapi/api"
|
||||
"github.com/matrix-org/gomatrixserverlib"
|
||||
|
|
@ -279,7 +274,7 @@ func newReq(t *testing.T, jsonBody map[string]interface{}) *msc2946.SpacesReques
|
|||
func runServer(t *testing.T, router *mux.Router) func() {
|
||||
t.Helper()
|
||||
externalServ := &http.Server{
|
||||
Addr: string(":8009"),
|
||||
Addr: string(":8010"),
|
||||
WriteTimeout: 60 * time.Second,
|
||||
Handler: router,
|
||||
}
|
||||
|
|
@ -302,7 +297,7 @@ func postSpaces(t *testing.T, expectCode int, accessToken, roomID string, req *m
|
|||
t.Fatalf("failed to marshal request: %s", err)
|
||||
}
|
||||
httpReq, err := http.NewRequest(
|
||||
"POST", "http://localhost:8009/_matrix/client/unstable/rooms/"+url.PathEscape(roomID)+"/spaces",
|
||||
"POST", "http://localhost:8010/_matrix/client/unstable/rooms/"+url.PathEscape(roomID)+"/spaces",
|
||||
bytes.NewBuffer(data),
|
||||
)
|
||||
httpReq.Header.Set("Authorization", "Bearer "+accessToken)
|
||||
|
|
@ -332,59 +327,6 @@ func postSpaces(t *testing.T, expectCode int, accessToken, roomID string, req *m
|
|||
return nil
|
||||
}
|
||||
|
||||
func assertContains(t *testing.T, result *msc2836.EventRelationshipResponse, wantEventIDs []string) {
|
||||
t.Helper()
|
||||
gotEventIDs := make([]string, len(result.Events))
|
||||
for i, ev := range result.Events {
|
||||
gotEventIDs[i] = ev.EventID
|
||||
}
|
||||
if len(gotEventIDs) != len(wantEventIDs) {
|
||||
t.Fatalf("length mismatch: got %v want %v", gotEventIDs, wantEventIDs)
|
||||
}
|
||||
for i := range gotEventIDs {
|
||||
if gotEventIDs[i] != wantEventIDs[i] {
|
||||
t.Errorf("wrong item in position %d - got %s want %s", i, gotEventIDs[i], wantEventIDs[i])
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func assertUnsignedChildren(t *testing.T, ev gomatrixserverlib.ClientEvent, relType string, wantCount int, childrenEventIDs []string) {
|
||||
t.Helper()
|
||||
unsigned := struct {
|
||||
Children map[string]int `json:"children"`
|
||||
Hash string `json:"children_hash"`
|
||||
}{}
|
||||
if err := json.Unmarshal(ev.Unsigned, &unsigned); err != nil {
|
||||
if wantCount == 0 {
|
||||
return // no children so possible there is no unsigned field at all
|
||||
}
|
||||
t.Fatalf("Failed to unmarshal unsigned field: %s", err)
|
||||
}
|
||||
// zero checks
|
||||
if wantCount == 0 {
|
||||
if len(unsigned.Children) != 0 || unsigned.Hash != "" {
|
||||
t.Fatalf("want 0 children but got unsigned fields %+v", unsigned)
|
||||
}
|
||||
return
|
||||
}
|
||||
gotCount := unsigned.Children[relType]
|
||||
if gotCount != wantCount {
|
||||
t.Errorf("Got %d count, want %d count for rel_type %s", gotCount, wantCount, relType)
|
||||
}
|
||||
// work out the hash
|
||||
sort.Strings(childrenEventIDs)
|
||||
var b strings.Builder
|
||||
for _, s := range childrenEventIDs {
|
||||
b.WriteString(s)
|
||||
}
|
||||
t.Logf("hashing %s", b.String())
|
||||
hashValBytes := sha256.Sum256([]byte(b.String()))
|
||||
wantHash := base64.RawStdEncoding.EncodeToString(hashValBytes[:])
|
||||
if wantHash != unsigned.Hash {
|
||||
t.Errorf("Got unsigned hash %s want hash %s", unsigned.Hash, wantHash)
|
||||
}
|
||||
}
|
||||
|
||||
type testUserAPI struct {
|
||||
accessTokens map[string]userapi.Device
|
||||
}
|
||||
|
|
|
|||
|
|
@ -30,10 +30,6 @@ var (
|
|||
ConstSpaceChildEventType: 1,
|
||||
ConstSpaceParentEventType: 2,
|
||||
}
|
||||
relTypesEnum = map[int]string{
|
||||
1: ConstSpaceChildEventType,
|
||||
2: ConstSpaceParentEventType,
|
||||
}
|
||||
)
|
||||
|
||||
type Database interface {
|
||||
|
|
|
|||
Loading…
Reference in a new issue