-
Notifications
You must be signed in to change notification settings - Fork 0
/
fake.go
57 lines (48 loc) · 1.78 KB
/
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
package templaterouter
// NewFakeTemplateRouter provides an empty template router with a simple certificate manager
// backed by a fake cert writer for testing
func NewFakeTemplateRouter() *templateRouter {
fakeCertManager, _ := newSimpleCertificateManager(newFakeCertificateManagerConfig(), &fakeCertWriter{})
return &templateRouter{
state: map[string]ServiceAliasConfig{},
serviceUnits: make(map[string]ServiceUnit),
certManager: fakeCertManager,
rateLimitedCommitFunction: nil,
rateLimitedCommitStopChannel: make(chan struct{}),
}
}
// FakeReloadHandler implements the minimal changes needed to make the locking behavior work
// This MUST match the behavior with the stateChanged of commitAndReload
func (r *templateRouter) FakeReloadHandler() {
r.lock.Lock()
defer r.lock.Unlock()
r.stateChanged = false
return
}
// fakeCertWriter is a certificate writer that records actions but is a no-op
type fakeCertWriter struct {
addedCerts []string
deletedCerts []string
}
// clear clears the fake cert writer for test case resets
func (fcw *fakeCertWriter) clear() {
fcw.addedCerts = make([]string, 0)
fcw.deletedCerts = make([]string, 0)
}
func (fcw *fakeCertWriter) WriteCertificate(directory string, id string, cert []byte) error {
fcw.addedCerts = append(fcw.addedCerts, directory+id)
return nil
}
func (fcw *fakeCertWriter) DeleteCertificate(directory, id string) error {
fcw.deletedCerts = append(fcw.deletedCerts, directory+id)
return nil
}
func newFakeCertificateManagerConfig() *certificateManagerConfig {
return &certificateManagerConfig{
certKeyFunc: generateCertKey,
caCertKeyFunc: generateCACertKey,
destCertKeyFunc: generateDestCertKey,
certDir: certDir,
caCertDir: caCertDir,
}
}