forked from hashicorp/otto
/
testing_components.go
50 lines (40 loc) · 1.25 KB
/
testing_components.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
package otto
import (
"github.com/hashicorp/otto/app"
"github.com/hashicorp/otto/foundation"
"github.com/hashicorp/otto/infrastructure"
)
// TestInfra adds a mock infrastructure with the given name to the
// core config and returns it.
func TestInfra(t TestT, n string, c *CoreConfig) *infrastructure.Mock {
if c.Infrastructures == nil {
c.Infrastructures = make(map[string]infrastructure.Factory)
}
result := new(infrastructure.Mock)
c.Infrastructures[n] = func() (infrastructure.Infrastructure, error) {
return result, nil
}
return result
}
// TestApp adds a mock app with the given tuple to the core config.
func TestApp(t TestT, tuple app.Tuple, c *CoreConfig) *app.Mock {
if c.Apps == nil {
c.Apps = make(map[app.Tuple]app.Factory)
}
result := new(app.Mock)
c.Apps[tuple] = func() (app.App, error) {
return result, nil
}
return result
}
// TestFoundation adds a mock foundation with the given tuple to the core config.
func TestFoundation(t TestT, tuple foundation.Tuple, c *CoreConfig) *foundation.Mock {
if c.Foundations == nil {
c.Foundations = make(map[foundation.Tuple]foundation.Factory)
}
result := new(foundation.Mock)
c.Foundations[tuple] = func() (foundation.Foundation, error) {
return result, nil
}
return result
}