Fix tests

This commit is contained in:
9seconds
2026-02-24 13:58:16 +01:00
parent 8b34c1b104
commit 5b91edf5c4
6 changed files with 95 additions and 109 deletions
@@ -14,7 +14,7 @@ import (
type PublicConfigUpdaterTestSuite struct {
UpdaterTestSuiteBase
u PublicConfigUpdater
u *PublicConfigUpdater
lock sync.Mutex
srv *httptest.Server
responseHandler func(w http.ResponseWriter)
@@ -42,39 +42,27 @@ func (s *PublicConfigUpdaterTestSuite) SetupTest() {
}
func (s *PublicConfigUpdaterTestSuite) Test502StatusCode() {
done := false
s.responseHandler = func(w http.ResponseWriter) {
w.WriteHeader(http.StatusBadGateway)
done = true
}
go s.u.Run(s.ctx, s.srv.URL, "tcp4")
s.u.Run(s.ctx, s.srv.URL, "tcp4")
s.Eventually(func() bool {
s.lock.Lock()
defer s.lock.Unlock()
return done
}, time.Second, 10*time.Millisecond)
time.Sleep(100 * time.Millisecond)
s.ctxCancel()
s.u.Wait()
s.Len(s.u.tg.view.publicConfigs.v4, 0)
}
func (s *PublicConfigUpdaterTestSuite) TestEmptyFile() {
done := false
s.responseHandler = func(w http.ResponseWriter) {
done = true
w.WriteHeader(http.StatusOK)
}
go s.u.Run(s.ctx, s.srv.URL, "tcp4")
s.u.Run(s.ctx, s.srv.URL, "tcp4")
s.Eventually(func() bool {
s.lock.Lock()
defer s.lock.Unlock()
return done
}, time.Second, 10*time.Millisecond)
time.Sleep(100 * time.Millisecond)
s.ctxCancel()
s.u.Wait()
s.Len(s.u.tg.view.publicConfigs.v4, 0)
}
@@ -85,21 +73,16 @@ proxy_for -1 -1;
proxy_for 100 100.10.0.0:3333;
lala 0 0
`
done := false
s.responseHandler = func(w http.ResponseWriter) {
done = true
w.WriteHeader(http.StatusOK)
w.Write([]byte(result)) //nolint: errcheck
}
go s.u.Run(s.ctx, s.srv.URL, "tcp4")
s.u.Run(s.ctx, s.srv.URL, "tcp4")
s.Eventually(func() bool {
s.lock.Lock()
defer s.lock.Unlock()
return done
}, time.Second, 10*time.Millisecond)
time.Sleep(100 * time.Millisecond)
s.ctxCancel()
s.u.Wait()
s.Len(s.u.tg.view.publicConfigs.v4, 0)
}
@@ -109,21 +92,16 @@ func (s *PublicConfigUpdaterTestSuite) TestOk() {
proxy_for 203 100.10.0.0:3333;
proxy_for -100 101.10.0.0:3333;
`
done := false
s.responseHandler = func(w http.ResponseWriter) {
done = true
w.WriteHeader(http.StatusOK)
w.Write([]byte(result)) //nolint: errcheck
}
go s.u.Run(s.ctx, s.srv.URL, "tcp4")
s.u.Run(s.ctx, s.srv.URL, "tcp4")
s.Eventually(func() bool {
s.lock.Lock()
defer s.lock.Unlock()
return done
}, time.Second, 10*time.Millisecond)
time.Sleep(100 * time.Millisecond)
s.ctxCancel()
s.u.Wait()
s.Len(s.u.tg.view.publicConfigs.v4, 1)
s.Len(s.u.tg.view.publicConfigs.v4[203], 1)