Fix engine tests (#3034)

Fix tests
This commit is contained in:
Zoltan Papp 2024-12-12 14:24:38 +01:00 committed by GitHub
parent eea02a4220
commit 589456a393
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 18 additions and 14 deletions

View File

@ -46,7 +46,7 @@ jobs:
if: matrix.os == 'ubuntu-latest' if: matrix.os == 'ubuntu-latest'
run: sudo apt update && sudo apt install -y -q libgtk-3-dev libayatana-appindicator3-dev libgl1-mesa-dev xorg-dev libpcap-dev run: sudo apt update && sudo apt install -y -q libgtk-3-dev libayatana-appindicator3-dev libgl1-mesa-dev xorg-dev libpcap-dev
- name: golangci-lint - name: golangci-lint
uses: golangci/golangci-lint-action@v3 uses: golangci/golangci-lint-action@v4
with: with:
version: latest version: latest
args: --timeout=12m args: --timeout=12m --out-format colored-line-number

View File

@ -14,9 +14,14 @@ type MockServer struct {
StopFunc func() StopFunc func()
UpdateDNSServerFunc func(serial uint64, update nbdns.Config) error UpdateDNSServerFunc func(serial uint64, update nbdns.Config) error
RegisterHandlerFunc func([]string, dns.Handler) error RegisterHandlerFunc func([]string, dns.Handler) error
UnregisterHandlerFunc func([]string) error
DeregisterHandlerFunc func([]string) error DeregisterHandlerFunc func([]string) error
} }
func (m *MockServer) UnregisterHandler(domains []string) error {
panic("implement me")
}
func (m *MockServer) RegisterHandler(domains []string, handler dns.Handler) error { func (m *MockServer) RegisterHandler(domains []string, handler dns.Handler) error {
if m.RegisterHandlerFunc != nil { if m.RegisterHandlerFunc != nil {
return m.RegisterHandlerFunc(domains, handler) return m.RegisterHandlerFunc(domains, handler)

View File

@ -1566,15 +1566,13 @@ func (e *Engine) updateDNSForwarder(domains []string) {
log.Infof("update domain router service for domains: %v", domains) log.Infof("update domain router service for domains: %v", domains)
e.dnsForwardMgr.UpdateDomains(domains) e.dnsForwardMgr.UpdateDomains(domains)
} }
} else { } else if e.dnsForwardMgr != nil {
if e.dnsForwardMgr != nil {
log.Infof("disable domain router service") log.Infof("disable domain router service")
if err := e.dnsForwardMgr.Stop(context.Background()); err != nil { if err := e.dnsForwardMgr.Stop(context.Background()); err != nil {
log.Errorf("failed to stop DNS forward: %v", err) log.Errorf("failed to stop DNS forward: %v", err)
} }
e.dnsForwardMgr = nil e.dnsForwardMgr = nil
} }
}
} }
// isChecksEqual checks if two slices of checks are equal. // isChecksEqual checks if two slices of checks are equal.

View File

@ -394,8 +394,8 @@ func TestEngine_UpdateNetworkMap(t *testing.T) {
return return
} }
if len(engine.peerConns) != c.expectedLen { if len(engine.peerStore.PeersPubKey()) != c.expectedLen {
t.Errorf("expecting Engine.peerConns to be of size %d, got %d", c.expectedLen, len(engine.peerConns)) t.Errorf("expecting Engine.peerConns to be of size %d, got %d", c.expectedLen, len(engine.peerStore.PeersPubKey()))
} }
if engine.networkSerial != c.expectedSerial { if engine.networkSerial != c.expectedSerial {
@ -403,7 +403,7 @@ func TestEngine_UpdateNetworkMap(t *testing.T) {
} }
for _, p := range c.expectedPeers { for _, p := range c.expectedPeers {
conn, ok := engine.peerConns[p.GetWgPubKey()] conn, ok := engine.peerStore.PeerConn(p.GetWgPubKey())
if !ok { if !ok {
t.Errorf("expecting Engine.peerConns to contain peer %s", p) t.Errorf("expecting Engine.peerConns to contain peer %s", p)
} }
@ -1240,7 +1240,8 @@ func getConnectedPeers(e *Engine) int {
e.syncMsgMux.Lock() e.syncMsgMux.Lock()
defer e.syncMsgMux.Unlock() defer e.syncMsgMux.Unlock()
i := 0 i := 0
for _, conn := range e.peerConns { for _, id := range e.peerStore.PeersPubKey() {
conn, _ := e.peerStore.PeerConn(id)
if conn.Status() == peer.StatusConnected { if conn.Status() == peer.StatusConnected {
i++ i++
} }
@ -1252,5 +1253,5 @@ func getPeers(e *Engine) int {
e.syncMsgMux.Lock() e.syncMsgMux.Lock()
defer e.syncMsgMux.Unlock() defer e.syncMsgMux.Unlock()
return len(e.peerConns) return len(e.peerStore.PeersPubKey())
} }