forked from Silverfish/proton-bridge
feat(GODT-2552): Fix unit test.
This commit is contained in:
committed by
Romain Le Jeune
parent
d88bee68c6
commit
4adc6d60b9
1
Makefile
1
Makefile
@ -257,6 +257,7 @@ mocks:
|
|||||||
mockgen --package mocks github.com/ProtonMail/gluon/reporter Reporter > internal/bridge/mocks/gluon_mocks.go
|
mockgen --package mocks github.com/ProtonMail/gluon/reporter Reporter > internal/bridge/mocks/gluon_mocks.go
|
||||||
mockgen --package mocks github.com/ProtonMail/proton-bridge/v3/internal/updater Downloader,Installer > internal/updater/mocks/mocks.go
|
mockgen --package mocks github.com/ProtonMail/proton-bridge/v3/internal/updater Downloader,Installer > internal/updater/mocks/mocks.go
|
||||||
mockgen --package mocks github.com/ProtonMail/proton-bridge/v3/internal/telemetry HeartbeatManager > internal/telemetry/mocks/mocks.go
|
mockgen --package mocks github.com/ProtonMail/proton-bridge/v3/internal/telemetry HeartbeatManager > internal/telemetry/mocks/mocks.go
|
||||||
|
cp internal/telemetry/mocks/mocks.go internal/bridge/mocks/telemetry_mocks.go
|
||||||
|
|
||||||
lint: gofiles lint-golang lint-license lint-dependencies lint-changelog
|
lint: gofiles lint-golang lint-license lint-dependencies lint-changelog
|
||||||
|
|
||||||
|
|||||||
@ -823,6 +823,9 @@ func withBridgeNoMocks(
|
|||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.Empty(t, bridge.GetErrors())
|
require.Empty(t, bridge.GetErrors())
|
||||||
|
|
||||||
|
// Start the Heartbeat process.
|
||||||
|
bridge.StartHeartbeat(mocks.Heartbeat)
|
||||||
|
|
||||||
// Wait for bridge to finish loading users.
|
// Wait for bridge to finish loading users.
|
||||||
waitForEvent(t, eventCh, events.AllUsersLoaded{})
|
waitForEvent(t, eventCh, events.AllUsersLoaded{})
|
||||||
// Wait for bridge to start the IMAP server.
|
// Wait for bridge to start the IMAP server.
|
||||||
|
|||||||
@ -32,6 +32,9 @@ import (
|
|||||||
|
|
||||||
func (bridge *Bridge) IsTelemetryAvailable() bool {
|
func (bridge *Bridge) IsTelemetryAvailable() bool {
|
||||||
var flag = true
|
var flag = true
|
||||||
|
if bridge.GetTelemetryDisabled() {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
safe.RLock(func() {
|
safe.RLock(func() {
|
||||||
for _, user := range bridge.users {
|
for _, user := range bridge.users {
|
||||||
|
|||||||
@ -24,6 +24,7 @@ type Mocks struct {
|
|||||||
|
|
||||||
CrashHandler *mocks.MockPanicHandler
|
CrashHandler *mocks.MockPanicHandler
|
||||||
Reporter *mocks.MockReporter
|
Reporter *mocks.MockReporter
|
||||||
|
Heartbeat *mocks.MockHeartbeatManager
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewMocks(tb testing.TB, version, minAuto *semver.Version) *Mocks {
|
func NewMocks(tb testing.TB, version, minAuto *semver.Version) *Mocks {
|
||||||
@ -39,14 +40,18 @@ func NewMocks(tb testing.TB, version, minAuto *semver.Version) *Mocks {
|
|||||||
|
|
||||||
CrashHandler: mocks.NewMockPanicHandler(ctl),
|
CrashHandler: mocks.NewMockPanicHandler(ctl),
|
||||||
Reporter: mocks.NewMockReporter(ctl),
|
Reporter: mocks.NewMockReporter(ctl),
|
||||||
|
Heartbeat: mocks.NewMockHeartbeatManager(ctl),
|
||||||
}
|
}
|
||||||
|
|
||||||
// When getting the TLS issue channel, we want to return the test channel.
|
// When getting the TLS issue channel, we want to return the test channel.
|
||||||
mocks.TLSReporter.EXPECT().GetTLSIssueCh().Return(mocks.TLSIssueCh).AnyTimes()
|
mocks.TLSReporter.EXPECT().GetTLSIssueCh().Return(mocks.TLSIssueCh).AnyTimes()
|
||||||
|
|
||||||
// This is called at he end of any go-routine:
|
// This is called at the end of any go-routine:
|
||||||
mocks.CrashHandler.EXPECT().HandlePanic(gomock.Any()).AnyTimes()
|
mocks.CrashHandler.EXPECT().HandlePanic(gomock.Any()).AnyTimes()
|
||||||
|
|
||||||
|
// this is called at start of heartbeat process.
|
||||||
|
mocks.Heartbeat.EXPECT().IsTelemetryAvailable().AnyTimes()
|
||||||
|
|
||||||
return mocks
|
return mocks
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
92
internal/bridge/mocks/telemetry_mocks.go
Normal file
92
internal/bridge/mocks/telemetry_mocks.go
Normal file
@ -0,0 +1,92 @@
|
|||||||
|
// Code generated by MockGen. DO NOT EDIT.
|
||||||
|
// Source: github.com/ProtonMail/proton-bridge/v3/internal/telemetry (interfaces: HeartbeatManager)
|
||||||
|
|
||||||
|
// Package mocks is a generated GoMock package.
|
||||||
|
package mocks
|
||||||
|
|
||||||
|
import (
|
||||||
|
reflect "reflect"
|
||||||
|
time "time"
|
||||||
|
|
||||||
|
telemetry "github.com/ProtonMail/proton-bridge/v3/internal/telemetry"
|
||||||
|
gomock "github.com/golang/mock/gomock"
|
||||||
|
)
|
||||||
|
|
||||||
|
// MockHeartbeatManager is a mock of HeartbeatManager interface.
|
||||||
|
type MockHeartbeatManager struct {
|
||||||
|
ctrl *gomock.Controller
|
||||||
|
recorder *MockHeartbeatManagerMockRecorder
|
||||||
|
}
|
||||||
|
|
||||||
|
// MockHeartbeatManagerMockRecorder is the mock recorder for MockHeartbeatManager.
|
||||||
|
type MockHeartbeatManagerMockRecorder struct {
|
||||||
|
mock *MockHeartbeatManager
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewMockHeartbeatManager creates a new mock instance.
|
||||||
|
func NewMockHeartbeatManager(ctrl *gomock.Controller) *MockHeartbeatManager {
|
||||||
|
mock := &MockHeartbeatManager{ctrl: ctrl}
|
||||||
|
mock.recorder = &MockHeartbeatManagerMockRecorder{mock}
|
||||||
|
return mock
|
||||||
|
}
|
||||||
|
|
||||||
|
// EXPECT returns an object that allows the caller to indicate expected use.
|
||||||
|
func (m *MockHeartbeatManager) EXPECT() *MockHeartbeatManagerMockRecorder {
|
||||||
|
return m.recorder
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetLastHeartbeatSent mocks base method.
|
||||||
|
func (m *MockHeartbeatManager) GetLastHeartbeatSent() time.Time {
|
||||||
|
m.ctrl.T.Helper()
|
||||||
|
ret := m.ctrl.Call(m, "GetLastHeartbeatSent")
|
||||||
|
ret0, _ := ret[0].(time.Time)
|
||||||
|
return ret0
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetLastHeartbeatSent indicates an expected call of GetLastHeartbeatSent.
|
||||||
|
func (mr *MockHeartbeatManagerMockRecorder) GetLastHeartbeatSent() *gomock.Call {
|
||||||
|
mr.mock.ctrl.T.Helper()
|
||||||
|
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetLastHeartbeatSent", reflect.TypeOf((*MockHeartbeatManager)(nil).GetLastHeartbeatSent))
|
||||||
|
}
|
||||||
|
|
||||||
|
// IsTelemetryAvailable mocks base method.
|
||||||
|
func (m *MockHeartbeatManager) IsTelemetryAvailable() bool {
|
||||||
|
m.ctrl.T.Helper()
|
||||||
|
ret := m.ctrl.Call(m, "IsTelemetryAvailable")
|
||||||
|
ret0, _ := ret[0].(bool)
|
||||||
|
return ret0
|
||||||
|
}
|
||||||
|
|
||||||
|
// IsTelemetryAvailable indicates an expected call of IsTelemetryAvailable.
|
||||||
|
func (mr *MockHeartbeatManagerMockRecorder) IsTelemetryAvailable() *gomock.Call {
|
||||||
|
mr.mock.ctrl.T.Helper()
|
||||||
|
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "IsTelemetryAvailable", reflect.TypeOf((*MockHeartbeatManager)(nil).IsTelemetryAvailable))
|
||||||
|
}
|
||||||
|
|
||||||
|
// SendHeartbeat mocks base method.
|
||||||
|
func (m *MockHeartbeatManager) SendHeartbeat(arg0 *telemetry.HeartbeatData) bool {
|
||||||
|
m.ctrl.T.Helper()
|
||||||
|
ret := m.ctrl.Call(m, "SendHeartbeat", arg0)
|
||||||
|
ret0, _ := ret[0].(bool)
|
||||||
|
return ret0
|
||||||
|
}
|
||||||
|
|
||||||
|
// SendHeartbeat indicates an expected call of SendHeartbeat.
|
||||||
|
func (mr *MockHeartbeatManagerMockRecorder) SendHeartbeat(arg0 interface{}) *gomock.Call {
|
||||||
|
mr.mock.ctrl.T.Helper()
|
||||||
|
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SendHeartbeat", reflect.TypeOf((*MockHeartbeatManager)(nil).SendHeartbeat), arg0)
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetLastHeartbeatSent mocks base method.
|
||||||
|
func (m *MockHeartbeatManager) SetLastHeartbeatSent(arg0 time.Time) error {
|
||||||
|
m.ctrl.T.Helper()
|
||||||
|
ret := m.ctrl.Call(m, "SetLastHeartbeatSent", arg0)
|
||||||
|
ret0, _ := ret[0].(error)
|
||||||
|
return ret0
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetLastHeartbeatSent indicates an expected call of SetLastHeartbeatSent.
|
||||||
|
func (mr *MockHeartbeatManagerMockRecorder) SetLastHeartbeatSent(arg0 interface{}) *gomock.Call {
|
||||||
|
mr.mock.ctrl.T.Helper()
|
||||||
|
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SetLastHeartbeatSent", reflect.TypeOf((*MockHeartbeatManager)(nil).SetLastHeartbeatSent), arg0)
|
||||||
|
}
|
||||||
@ -1,3 +1,20 @@
|
|||||||
|
// Copyright (c) 2023 Proton AG
|
||||||
|
//
|
||||||
|
// This file is part of Proton Mail Bridge.
|
||||||
|
//
|
||||||
|
// Proton Mail Bridge is free software: you can redistribute it and/or modify
|
||||||
|
// it under the terms of the GNU General Public License as published by
|
||||||
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
|
// (at your option) any later version.
|
||||||
|
//
|
||||||
|
// Proton Mail Bridge is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU General Public License
|
||||||
|
// along with Proton Mail Bridge. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
package tests
|
package tests
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
|||||||
@ -13,7 +13,6 @@ Feature: Bridge send usage metrics
|
|||||||
Then bridge telemetry feature is enabled
|
Then bridge telemetry feature is enabled
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Scenario: Telemetry availability - Multi user
|
Scenario: Telemetry availability - Multi user
|
||||||
When the user logs in with username "[user:user1]" and password "password"
|
When the user logs in with username "[user:user1]" and password "password"
|
||||||
And user "[user:user1]" finishes syncing
|
And user "[user:user1]" finishes syncing
|
||||||
|
|||||||
@ -1,3 +1,20 @@
|
|||||||
|
// Copyright (c) 2023 Proton AG
|
||||||
|
//
|
||||||
|
// This file is part of Proton Mail Bridge.
|
||||||
|
//
|
||||||
|
// Proton Mail Bridge is free software: you can redistribute it and/or modify
|
||||||
|
// it under the terms of the GNU General Public License as published by
|
||||||
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
|
// (at your option) any later version.
|
||||||
|
//
|
||||||
|
// Proton Mail Bridge is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU General Public License
|
||||||
|
// along with Proton Mail Bridge. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
package tests
|
package tests
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
|||||||
Reference in New Issue
Block a user