-
Notifications
You must be signed in to change notification settings - Fork 4
/
remote_tracker_mocks.go
53 lines (44 loc) · 1.27 KB
/
remote_tracker_mocks.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package utils
import (
"context"
"fmt"
"sync"
"k8s.io/apimachinery/pkg/types"
)
var _ RemoteTracker = (*RemoteTrackerMock)(nil)
func NewRemoteTrackerMock() *RemoteTrackerMock {
return &RemoteTrackerMock{
calls: make(map[types.NamespacedName]RemoteTrackerMockCall),
}
}
// This is a manually crafted mock.
// The reason of not using gomock is that we need this mock to be "global" and used across
// different tests, which gomock does not support.
type RemoteTrackerMock struct {
lock sync.Mutex
calls map[types.NamespacedName]RemoteTrackerMockCall
}
type RemoteTrackerMockCall struct {
NodeName string
ProviderID string
}
func (r *RemoteTrackerMock) AddCall(cluster types.NamespacedName, call RemoteTrackerMockCall) {
r.lock.TryLock()
defer r.lock.Unlock()
r.calls[cluster] = call
}
func (r *RemoteTrackerMock) SetProviderID(_ context.Context, cluster types.NamespacedName, nodeName string, providerID string) error {
r.lock.TryLock()
defer r.lock.Unlock()
call, found := r.calls[cluster]
if !found {
return fmt.Errorf("Cluster %s not found", cluster.String())
}
if call.NodeName != nodeName {
return ErrRemoteNodeNotFound
}
if call.ProviderID != providerID {
return fmt.Errorf("Want ProviderID '%s', but got '%s'", call.ProviderID, providerID)
}
return nil
}