-
Notifications
You must be signed in to change notification settings - Fork 0
/
elasticip_fake.go
64 lines (49 loc) · 1.2 KB
/
elasticip_fake.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
54
55
56
57
58
59
60
61
62
63
64
package main
import (
"context"
"fmt"
"sync"
"github.com/sirupsen/logrus"
)
func NewFakeProvider() (elasticIPProvider, error) {
return &fakeElasticIPProvider{}, nil
}
type fakeElasticIPProvider struct {
mu sync.Mutex
refreshCounter map[string]int
}
func (p *fakeElasticIPProvider) Test(ctx context.Context) error {
return nil
}
func (p *fakeElasticIPProvider) NewElasticIPRefresher(logger *logrus.Entry,
network netAddress) (elasticIPRefresher, error) {
p.mu.Lock()
defer p.mu.Unlock()
if p.refreshCounter == nil {
p.refreshCounter = map[string]int{}
}
ref := &fakeElasticIPRefresher{
network: network,
logger: logger,
mu: &p.mu,
refreshCounter: p.refreshCounter,
}
return ref, nil
}
type fakeElasticIPRefresher struct {
network netAddress
logger *logrus.Entry
mu *sync.Mutex
refreshCounter map[string]int
}
func (r *fakeElasticIPRefresher) Logger() *logrus.Entry {
return r.logger
}
func (r *fakeElasticIPRefresher) Refresh(ctx context.Context) error {
r.mu.Lock()
defer r.mu.Unlock()
c := r.refreshCounter[r.network.String()]
r.refreshCounter[r.network.String()] = c + 1
fmt.Printf("REFRESH %s\n", r.network)
return nil
}