forked from openshift/origin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fake.go
46 lines (40 loc) · 1.49 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
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{}),
}
}
// 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,
}
}