Add vet linter (#240)

This commit is contained in:
Erik Johnston 2017-09-20 13:40:22 +01:00 committed by Mark Haines
parent 4d05492f43
commit b72142ace5
9 changed files with 38 additions and 29 deletions

View file

@ -10,6 +10,7 @@
"ineffassign", "ineffassign",
"gas", "gas",
"misspell", "misspell",
"errcheck" "errcheck",
"vet"
] ]
} }

View file

@ -15,6 +15,7 @@
"gas", "gas",
"misspell", "misspell",
"unparam", "unparam",
"errcheck" "errcheck",
"vet"
] ]
} }

View file

@ -163,12 +163,12 @@ func createRoom(req *http.Request, device *authtypes.Device,
{"m.room.member", userID, membershipContent}, {"m.room.member", userID, membershipContent},
{"m.room.power_levels", "", common.InitialPowerLevelsContent(userID)}, {"m.room.power_levels", "", common.InitialPowerLevelsContent(userID)},
// TODO: m.room.canonical_alias // TODO: m.room.canonical_alias
{"m.room.join_rules", "", common.JoinRulesContent{"public"}}, // FIXME: Allow this to be changed {"m.room.join_rules", "", common.JoinRulesContent{JoinRule: "public"}}, // FIXME: Allow this to be changed
{"m.room.history_visibility", "", common.HistoryVisibilityContent{"joined"}}, // FIXME: Allow this to be changed {"m.room.history_visibility", "", common.HistoryVisibilityContent{HistoryVisibility: "joined"}}, // FIXME: Allow this to be changed
{"m.room.guest_access", "", common.GuestAccessContent{"can_join"}}, // FIXME: Allow this to be changed {"m.room.guest_access", "", common.GuestAccessContent{GuestAccess: "can_join"}}, // FIXME: Allow this to be changed
// TODO: Other initial state items // TODO: Other initial state items
{"m.room.name", "", common.NameContent{r.Name}}, // FIXME: Only send the name event if a name is supplied, to avoid sending a false room name removal event {"m.room.name", "", common.NameContent{Name: r.Name}}, // FIXME: Only send the name event if a name is supplied, to avoid sending a false room name removal event
{"m.room.topic", "", common.TopicContent{r.Topic}}, {"m.room.topic", "", common.TopicContent{Topic: r.Topic}},
// TODO: invite events // TODO: invite events
// TODO: 3pid invite events // TODO: 3pid invite events
// TODO: m.room.aliases // TODO: m.room.aliases

View file

@ -67,7 +67,7 @@ func main() {
keyRing := gomatrixserverlib.KeyRing{ keyRing := gomatrixserverlib.KeyRing{
KeyFetchers: []gomatrixserverlib.KeyFetcher{ KeyFetchers: []gomatrixserverlib.KeyFetcher{
// TODO: Use perspective key fetchers for production. // TODO: Use perspective key fetchers for production.
&gomatrixserverlib.DirectKeyFetcher{federation.Client}, &gomatrixserverlib.DirectKeyFetcher{Client: federation.Client},
}, },
KeyDatabase: keyDB, KeyDatabase: keyDB,
} }

View file

@ -413,7 +413,7 @@ func fingerprintPEM(data []byte) *gomatrixserverlib.TLSFingerprint {
} }
if certDERBlock.Type == "CERTIFICATE" { if certDERBlock.Type == "CERTIFICATE" {
digest := sha256.Sum256(certDERBlock.Bytes) digest := sha256.Sum256(certDERBlock.Bytes)
return &gomatrixserverlib.TLSFingerprint{digest[:]} return &gomatrixserverlib.TLSFingerprint{SHA256: digest[:]}
} }
} }
} }

View file

@ -97,7 +97,8 @@ func (s *serverKeyStatements) bulkSelectServerKeys(
return nil, err return nil, err
} }
r := gomatrixserverlib.PublicKeyRequest{ r := gomatrixserverlib.PublicKeyRequest{
gomatrixserverlib.ServerName(serverName), gomatrixserverlib.KeyID(keyID), ServerName: gomatrixserverlib.ServerName(serverName),
KeyID: gomatrixserverlib.KeyID(keyID),
} }
results[r] = serverKeys results[r] = serverKeys
} }

View file

@ -44,7 +44,7 @@ func localKeys(cfg config.Dendrite, validUntil time.Time) (*gomatrixserverlib.Se
keys.VerifyKeys = map[gomatrixserverlib.KeyID]gomatrixserverlib.VerifyKey{ keys.VerifyKeys = map[gomatrixserverlib.KeyID]gomatrixserverlib.VerifyKey{
cfg.Matrix.KeyID: { cfg.Matrix.KeyID: {
gomatrixserverlib.Base64String(publicKey), Key: gomatrixserverlib.Base64String(publicKey),
}, },
} }

View file

@ -15,24 +15,29 @@
package input package input
import ( import (
"github.com/matrix-org/dendrite/roomserver/types"
"testing" "testing"
"github.com/matrix-org/dendrite/roomserver/types"
) )
func benchmarkStateEntryMapLookup(entries, lookups int64, b *testing.B) { func benchmarkStateEntryMapLookup(entries, lookups int64, b *testing.B) {
var list []types.StateEntry var list []types.StateEntry
for i := int64(0); i < entries; i++ { for i := int64(0); i < entries; i++ {
list = append(list, types.StateEntry{types.StateKeyTuple{ list = append(list, types.StateEntry{
types.EventTypeNID(i), StateKeyTuple: types.StateKeyTuple{
types.EventStateKeyNID(i), EventTypeNID: types.EventTypeNID(i),
}, types.EventNID(i)}) EventStateKeyNID: types.EventStateKeyNID(i),
},
EventNID: types.EventNID(i),
})
} }
for i := 0; i < b.N; i++ { for i := 0; i < b.N; i++ {
entryMap := stateEntryMap(list) entryMap := stateEntryMap(list)
for j := int64(0); j < lookups; j++ { for j := int64(0); j < lookups; j++ {
entryMap.lookup(types.StateKeyTuple{ entryMap.lookup(types.StateKeyTuple{
types.EventTypeNID(j), types.EventStateKeyNID(j), EventTypeNID: types.EventTypeNID(j),
EventStateKeyNID: types.EventStateKeyNID(j),
}) })
} }
} }
@ -56,9 +61,9 @@ func BenchmarkStateEntryMap1000Lookup10000(b *testing.B) {
func TestStateEntryMap(t *testing.T) { func TestStateEntryMap(t *testing.T) {
entryMap := stateEntryMap([]types.StateEntry{ entryMap := stateEntryMap([]types.StateEntry{
{types.StateKeyTuple{1, 1}, 1}, {StateKeyTuple: types.StateKeyTuple{EventTypeNID: 1, EventStateKeyNID: 1}, EventNID: 1},
{types.StateKeyTuple{1, 3}, 2}, {StateKeyTuple: types.StateKeyTuple{EventTypeNID: 1, EventStateKeyNID: 3}, EventNID: 2},
{types.StateKeyTuple{2, 1}, 3}, {StateKeyTuple: types.StateKeyTuple{EventTypeNID: 2, EventStateKeyNID: 1}, EventNID: 3},
}) })
testCases := []struct { testCases := []struct {
@ -78,7 +83,7 @@ func TestStateEntryMap(t *testing.T) {
} }
for _, testCase := range testCases { for _, testCase := range testCases {
keyTuple := types.StateKeyTuple{testCase.inputTypeNID, testCase.inputStateKey} keyTuple := types.StateKeyTuple{EventTypeNID: testCase.inputTypeNID, EventStateKeyNID: testCase.inputStateKey}
gotEventNID, gotOK := entryMap.lookup(keyTuple) gotEventNID, gotOK := entryMap.lookup(keyTuple)
if testCase.wantOK != gotOK { if testCase.wantOK != gotOK {
t.Fatalf("stateEntryMap lookup(%v): want ok to be %v, got %v", keyTuple, testCase.wantOK, gotOK) t.Fatalf("stateEntryMap lookup(%v): want ok to be %v, got %v", keyTuple, testCase.wantOK, gotOK)

View file

@ -15,8 +15,9 @@
package state package state
import ( import (
"github.com/matrix-org/dendrite/roomserver/types"
"testing" "testing"
"github.com/matrix-org/dendrite/roomserver/types"
) )
func TestFindDuplicateStateKeys(t *testing.T) { func TestFindDuplicateStateKeys(t *testing.T) {
@ -25,18 +26,18 @@ func TestFindDuplicateStateKeys(t *testing.T) {
Want []types.StateEntry Want []types.StateEntry
}{{ }{{
Input: []types.StateEntry{ Input: []types.StateEntry{
{types.StateKeyTuple{1, 1}, 1}, {StateKeyTuple: types.StateKeyTuple{EventTypeNID: 1, EventStateKeyNID: 1}, EventNID: 1},
{types.StateKeyTuple{1, 1}, 2}, {StateKeyTuple: types.StateKeyTuple{EventTypeNID: 1, EventStateKeyNID: 1}, EventNID: 2},
{types.StateKeyTuple{2, 2}, 3}, {StateKeyTuple: types.StateKeyTuple{EventTypeNID: 2, EventStateKeyNID: 2}, EventNID: 3},
}, },
Want: []types.StateEntry{ Want: []types.StateEntry{
{types.StateKeyTuple{1, 1}, 1}, {StateKeyTuple: types.StateKeyTuple{EventTypeNID: 1, EventStateKeyNID: 1}, EventNID: 1},
{types.StateKeyTuple{1, 1}, 2}, {StateKeyTuple: types.StateKeyTuple{EventTypeNID: 1, EventStateKeyNID: 1}, EventNID: 2},
}, },
}, { }, {
Input: []types.StateEntry{ Input: []types.StateEntry{
{types.StateKeyTuple{1, 1}, 1}, {StateKeyTuple: types.StateKeyTuple{EventTypeNID: 1, EventStateKeyNID: 1}, EventNID: 1},
{types.StateKeyTuple{1, 2}, 2}, {StateKeyTuple: types.StateKeyTuple{EventTypeNID: 1, EventStateKeyNID: 2}, EventNID: 2},
}, },
Want: nil, Want: nil,
}} }}