fix conversion from int to string yields a string of one rune, not a string of digits

This commit is contained in:
Till Faelligen 2020-10-14 15:27:40 +02:00
parent 286dd408ae
commit 6998c8248e
2 changed files with 7 additions and 4 deletions

View file

@ -1,6 +1,8 @@
package caching package caching
import ( import (
"strconv"
"github.com/matrix-org/dendrite/roomserver/types" "github.com/matrix-org/dendrite/roomserver/types"
) )
@ -83,11 +85,11 @@ func (c Caches) GetRoomServerRoomNID(roomID string) (types.RoomNID, bool) {
func (c Caches) StoreRoomServerRoomNID(roomID string, roomNID types.RoomNID) { func (c Caches) StoreRoomServerRoomNID(roomID string, roomNID types.RoomNID) {
c.RoomServerRoomNIDs.Set(roomID, roomNID) c.RoomServerRoomNIDs.Set(roomID, roomNID)
c.RoomServerRoomIDs.Set(string(roomNID), roomID) c.RoomServerRoomIDs.Set(strconv.Itoa(int(roomNID)), roomID)
} }
func (c Caches) GetRoomServerRoomID(roomNID types.RoomNID) (string, bool) { func (c Caches) GetRoomServerRoomID(roomNID types.RoomNID) (string, bool) {
val, found := c.RoomServerRoomIDs.Get(string(roomNID)) val, found := c.RoomServerRoomIDs.Get(strconv.Itoa(int(roomNID)))
if found && val != nil { if found && val != nil {
if roomID, ok := val.(string); ok { if roomID, ok := val.(string); ok {
return roomID, true return roomID, true

View file

@ -14,6 +14,7 @@ package transactions
import ( import (
"net/http" "net/http"
"strconv"
"testing" "testing"
"github.com/matrix-org/util" "github.com/matrix-org/util"
@ -44,8 +45,8 @@ func TestCache(t *testing.T) {
for i := 1; i <= 100; i++ { for i := 1; i <= 100; i++ {
fakeTxnCache.AddTransaction( fakeTxnCache.AddTransaction(
fakeAccessToken, fakeAccessToken,
fakeTxnID+string(i), fakeTxnID+strconv.Itoa(i),
&util.JSONResponse{Code: http.StatusOK, JSON: fakeType{ID: string(i)}}, &util.JSONResponse{Code: http.StatusOK, JSON: fakeType{ID: strconv.Itoa(i)}},
) )
} }