1
0

feat(GODT-2552): Add functional test.

This commit is contained in:
Romain LE JEUNE
2023-04-20 21:14:11 +02:00
committed by Romain Le Jeune
parent 67b5e7f96a
commit d88bee68c6
12 changed files with 232 additions and 27 deletions

View File

@ -0,0 +1,72 @@
package tests
import (
"errors"
"testing"
"time"
"github.com/ProtonMail/proton-bridge/v3/internal/bridge"
"github.com/ProtonMail/proton-bridge/v3/internal/telemetry"
"github.com/stretchr/testify/assert"
)
type heartbeatRecorder struct {
heartbeat telemetry.HeartbeatData
bridge *bridge.Bridge
reject bool
assert *assert.Assertions
}
func newHeartbeatRecorder(tb testing.TB) *heartbeatRecorder {
return &heartbeatRecorder{
heartbeat: telemetry.HeartbeatData{},
bridge: nil,
reject: false,
assert: assert.New(tb),
}
}
func (hb *heartbeatRecorder) setBridge(bridge *bridge.Bridge) {
hb.bridge = bridge
}
func (hb *heartbeatRecorder) GetLastHeartbeatSent() time.Time {
if hb.bridge == nil {
return time.Now()
}
return hb.bridge.GetLastHeartbeatSent()
}
func (hb *heartbeatRecorder) IsTelemetryAvailable() bool {
if hb.bridge == nil {
return false
}
return hb.bridge.IsTelemetryAvailable()
}
func (hb *heartbeatRecorder) SendHeartbeat(metrics *telemetry.HeartbeatData) bool {
if hb.bridge == nil {
return false
}
if len(hb.bridge.GetUserIDs()) == 0 {
return false
}
if hb.reject {
return false
}
hb.heartbeat = *metrics
return true
}
func (hb *heartbeatRecorder) SetLastHeartbeatSent(timestamp time.Time) error {
if hb.bridge == nil {
return errors.New("no bridge initialized")
}
return hb.bridge.SetLastHeartbeatSent(timestamp)
}
func (hb *heartbeatRecorder) rejectSend() {
hb.reject = true
}