fixed linter errors and fixed tests

This commit is contained in:
Annika Hannig 2021-10-22 22:51:11 +02:00
parent 39e2605707
commit 1fc17d6b3e
5 changed files with 49 additions and 49 deletions

View File

@ -26,7 +26,7 @@ func StartHousekeeping(ctx context.Context, cfg *config.Config) {
// Expire the caches
log.Println("Expiring caches")
for _, source := range cfg.Sources {
count := source.getInstance().ExpireCaches()
count := source.GetInstance().ExpireCaches()
log.Println("Expired", count, "entries for source", source.Name)
}

View File

@ -21,7 +21,7 @@ type NeighborsIndex map[string]*api.Neighbor
type NeighborsStore struct {
neighborsMap map[string]NeighborsIndex
cfgMap map[string]*config.SourceConfig
statusMap map[string]StoreStatus
statusMap map[string]Status
refreshInterval time.Duration
refreshNeighborStatus bool
lastRefresh time.Time
@ -34,13 +34,13 @@ func NewNeighborsStore(cfg *config.Config) *NeighborsStore {
// Build source mapping
neighborsMap := make(map[string]NeighborsIndex)
cfgMap := make(map[string]*config.SourceConfig)
statusMap := make(map[string]StoreStatus)
statusMap := make(map[string]Status)
for _, source := range cfg.Sources {
id := source.ID
cfgMap[id] = source
statusMap[id] = StoreStatus{
State: STATE_INIT,
statusMap[id] = Status{
State: StateInit,
}
neighborsMap[id] = make(NeighborsIndex)
@ -89,7 +89,7 @@ func (s *NeighborsStore) init() {
// SourceStatus retrievs the status for a route server
// identified by sourceID.
func (s *NeighborsStore) SourceStatus(sourceID string) StoreStatus {
func (s *NeighborsStore) SourceStatus(sourceID string) Status {
s.RLock()
defer s.RUnlock()
return s.statusMap[sourceID]
@ -108,14 +108,14 @@ func (s *NeighborsStore) update() {
t0 := time.Now()
for sourceID := range s.neighborsMap {
// Get current state
if s.statusMap[sourceID].State == STATE_UPDATING {
if s.statusMap[sourceID].State == StateUpdating {
continue // nothing to do here. really.
}
// Start updating
s.Lock()
s.statusMap[sourceID] = StoreStatus{
State: STATE_UPDATING,
s.statusMap[sourceID] = Status{
State: StateUpdating,
}
s.Unlock()
@ -132,8 +132,8 @@ func (s *NeighborsStore) update() {
)
// That's sad.
s.Lock()
s.statusMap[sourceID] = StoreStatus{
State: STATE_ERROR,
s.statusMap[sourceID] = Status{
State: StateError,
LastError: err,
LastRefresh: time.Now(),
}
@ -155,9 +155,9 @@ func (s *NeighborsStore) update() {
s.Lock()
s.neighborsMap[sourceID] = index
// Update state
s.statusMap[sourceID] = StoreStatus{
s.statusMap[sourceID] = Status{
LastRefresh: time.Now(),
State: STATE_READY,
State: StateReady,
}
s.lastRefresh = time.Now().UTC()
s.Unlock()
@ -232,8 +232,8 @@ func (s *NeighborsStore) LookupNeighborsAt(
s.RUnlock()
asn := -1
if REGEX_MATCH_ASLOOKUP.MatchString(query) {
groups := REGEX_MATCH_ASLOOKUP.FindStringSubmatch(query)
if ReMatchASLookup.MatchString(query) {
groups := ReMatchASLookup.FindStringSubmatch(query)
if a, err := strconv.Atoi(groups[1]); err == nil {
asn = a
}
@ -299,15 +299,15 @@ func (s *NeighborsStore) FilterNeighbors(
}
// Stats exports some statistics for monitoring.
func (s *NeighborsStore) Stats() *NeighborsStoreStats {
func (s *NeighborsStore) Stats() *api.NeighborsStoreStats {
totalNeighbors := 0
rsStats := []RouteServerNeighborsStats{}
rsStats := []api.RouteServerNeighborsStats{}
s.RLock()
for sourceID, neighbors := range s.neighborsMap {
status := s.statusMap[sourceID]
totalNeighbors += len(neighbors)
serverStats := RouteServerNeighborsStats{
serverStats := api.RouteServerNeighborsStats{
Name: s.cfgMap[sourceID].Name,
State: stateToString(status.State),
Neighbors: len(neighbors),
@ -317,7 +317,7 @@ func (s *NeighborsStore) Stats() *NeighborsStoreStats {
}
s.RUnlock()
storeStats := &NeighborsStoreStats{
storeStats := &api.NeighborsStoreStats{
TotalNeighbors: totalNeighbors,
RouteServers: rsStats,
}

View File

@ -53,12 +53,12 @@ func makeTestNeighborsStore() *NeighborsStore {
"rs1": rs1,
"rs2": rs2,
},
statusMap: map[string]StoreStatus{
"rs1": StoreStatus{
State: STATE_READY,
statusMap: map[string]Status{
"rs1": Status{
State: StateReady,
},
"rs2": StoreStatus{
State: STATE_INIT,
"rs2": Status{
State: StateInit,
},
},
}
@ -69,11 +69,11 @@ func makeTestNeighborsStore() *NeighborsStore {
func TestGetSourceState(t *testing.T) {
store := makeTestNeighborsStore()
if store.SourceState("rs1") != STATE_READY {
if store.SourceState("rs1") != StateReady {
t.Error("Expected Source(1) to be STATE_READY")
}
if store.SourceState("rs2") == STATE_READY {
if store.SourceState("rs2") == StateReady {
t.Error("Expected Source(2) to be NOT STATE_READY")
}
}

View File

@ -16,7 +16,7 @@ import (
// of a backend by the API
type RoutesStore struct {
routesMap map[string]*api.RoutesResponse
statusMap map[string]StoreStatus
statusMap map[string]Status
cfgMap map[string]*config.SourceConfig
refreshInterval time.Duration
@ -35,7 +35,7 @@ func NewRoutesStore(
) *RoutesStore {
// Build mapping based on source instances
routesMap := make(map[string]*api.RoutesResponse)
statusMap := make(map[string]StoreStatus)
statusMap := make(map[string]Status)
cfgMap := make(map[string]*config.SourceConfig)
for _, source := range cfg.Sources {
@ -43,8 +43,8 @@ func NewRoutesStore(
cfgMap[id] = source
routesMap[id] = &api.RoutesResponse{}
statusMap[id] = StoreStatus{
State: STATE_INIT,
statusMap[id] = Status{
State: StateInit,
}
}
@ -100,14 +100,14 @@ func (rs *RoutesStore) update() {
source := sourceConfig.GetInstance()
// Get current update state
if rs.statusMap[sourceID].State == STATE_UPDATING {
if rs.statusMap[sourceID].State == StateUpdating {
continue // nothing to do here
}
// Set update state
rs.Lock()
rs.statusMap[sourceID] = StoreStatus{
State: STATE_UPDATING,
rs.statusMap[sourceID] = Status{
State: StateUpdating,
}
rs.Unlock()
@ -121,8 +121,8 @@ func (rs *RoutesStore) update() {
)
rs.Lock()
rs.statusMap[sourceID] = StoreStatus{
State: STATE_ERROR,
rs.statusMap[sourceID] = Status{
State: StateError,
LastError: err,
LastRefresh: time.Now(),
}
@ -136,9 +136,9 @@ func (rs *RoutesStore) update() {
// Update data
rs.routesMap[sourceID] = routes
// Update state
rs.statusMap[sourceID] = StoreStatus{
rs.statusMap[sourceID] = Status{
LastRefresh: time.Now(),
State: STATE_READY,
State: StateReady,
}
rs.lastRefresh = time.Now().UTC()
rs.Unlock()
@ -159,7 +159,7 @@ func (rs *RoutesStore) Stats() *api.RoutesStoreStats {
totalImported := 0
totalFiltered := 0
rsStats := []RouteServerRoutesStats{}
rsStats := []api.RouteServerRoutesStats{}
rs.RLock()
for sourceID, routes := range rs.routesMap {
@ -168,10 +168,10 @@ func (rs *RoutesStore) Stats() *api.RoutesStoreStats {
totalImported += len(routes.Imported)
totalFiltered += len(routes.Filtered)
serverStats := RouteServerRoutesStats{
serverStats := api.RouteServerRoutesStats{
Name: rs.cfgMap[sourceID].Name,
Routes: RoutesStats{
Routes: api.RoutesStats{
Filtered: len(routes.Filtered),
Imported: len(routes.Imported),
},
@ -185,8 +185,8 @@ func (rs *RoutesStore) Stats() *api.RoutesStoreStats {
rs.RUnlock()
// Make stats
storeStats := &RoutesStoreStats{
TotalRoutes: RoutesStats{
storeStats := &api.RoutesStoreStats{
TotalRoutes: api.RoutesStats{
Imported: totalImported,
Filtered: totalFiltered,
},

View File

@ -70,13 +70,13 @@ func testCheckPrefixesPresence(prefixes, resultset []string, t *testing.T) {
func makeTestRoutesStore() *RoutesStore {
neighborsStore := makeTestNeighborsStore()
neighborsStore := makeTestNeighborsStore()
rs1RoutesResponse := loadTestRoutesResponse()
// Build mapping based on source instances:
// rs : <response>
statusMap := make(map[string]StoreStatus)
statusMap := make(map[string]Status)
routesMap := map[string]*api.RoutesResponse{
"rs1": rs1RoutesResponse,
}
@ -98,10 +98,10 @@ func makeTestRoutesStore() *RoutesStore {
}
store := &RoutesStore{
routesMap: routesMap,
statusMap: statusMap,
cfgMap: configMap,
neighborsStore: neighborsStore,
routesMap: routesMap,
statusMap: statusMap,
cfgMap: configMap,
neighborsStore: neighborsStore,
}
return store
@ -206,7 +206,7 @@ func TestLookupPrefixForNeighbors(t *testing.T) {
// Query
results := store.LookupPrefixForNeighbors(neighbors)
t.Log(results)
t.Log(results)
// We should have retrived 8 prefixes,
if len(results) != 8 {