-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcore_example_test.go
More file actions
156 lines (138 loc) · 4.43 KB
/
core_example_test.go
File metadata and controls
156 lines (138 loc) · 4.43 KB
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
package core_test
import . "dappco.re/go"
// ExampleCore_accessors reads the grouped accessor methods through `Core` for Core
// orchestration. Core keeps orchestration helpers reachable from one predictable facade.
func ExampleCore_accessors() {
c := New(WithOption("name", "ops"))
Println(c.Options().String("name"))
Println(c.App().Name)
Println(c.Data() != nil)
Println(c.Drive() != nil)
Println(c.Fs() != nil)
Println(c.Config() != nil)
Println(c.Error() != nil)
Println(c.Log() != nil)
Println(c.Cli() != nil)
Println(c.IPC() != nil)
Println(c.I18n() != nil)
// Output:
// ops
// ops
// true
// true
// true
// true
// true
// true
// true
// true
// true
}
// ExampleCore_Env reads environment access through `Core.Env` for Core orchestration. Core
// keeps orchestration helpers reachable from one predictable facade.
func ExampleCore_Env() {
c := New()
Println(c.Env("OS") != "")
// Output: true
}
// ExampleCore_Context reads the active context through `Core.Context` for Core
// orchestration. Core keeps orchestration helpers reachable from one predictable facade.
func ExampleCore_Context() {
c := New()
Println(c.Context() != nil)
// Output: true
}
// ExampleCore_Core returns the Core instance through `Core.Core` for Core orchestration.
// Core keeps orchestration helpers reachable from one predictable facade.
func ExampleCore_Core() {
c := New()
Println(c.Core() == c)
// Output: true
}
// ExampleCore_RunResult runs `Core.RunResult` through the Result-returning startup path
// for Core orchestration. Core keeps orchestration helpers reachable from one
// predictable facade.
func ExampleCore_RunResult() {
c := New()
Println(c.RunResult().OK)
// Output: true
}
// ExampleCore_Run runs `Core.Run` with representative caller inputs for Core
// orchestration. Core keeps orchestration helpers reachable from one predictable facade.
func ExampleCore_Run() {
_ = New().Run
}
// ExampleCore_ACTION calls the uppercase action helper through `Core.ACTION` for Core
// orchestration. Core keeps orchestration helpers reachable from one predictable facade.
func ExampleCore_ACTION() {
c := New()
seen := ""
c.RegisterAction(func(_ *Core, msg Message) Result {
seen = msg.(string)
return Result{OK: true}
})
c.ACTION("started")
Println(seen)
// Output: started
}
// ExampleCore_QUERY calls the uppercase query helper through `Core.QUERY` for Core
// orchestration. Core keeps orchestration helpers reachable from one predictable facade.
func ExampleCore_QUERY() {
c := New()
c.RegisterQuery(func(_ *Core, q Query) Result {
return Result{Value: Concat("query:", q.(string)), OK: true}
})
r := c.QUERY("status")
Println(r.Value)
// Output: query:status
}
// ExampleCore_QUERYALL calls every matching uppercase query through `Core.QUERYALL` for
// Core orchestration. Core keeps orchestration helpers reachable from one predictable
// facade.
func ExampleCore_QUERYALL() {
c := New()
c.RegisterQuery(func(_ *Core, q Query) Result {
return Result{Value: Concat("a:", q.(string)), OK: true}
})
c.RegisterQuery(func(_ *Core, q Query) Result {
return Result{Value: Concat("b:", q.(string)), OK: true}
})
r := c.QUERYALL("status")
Println(r.Value)
// Output: [a:status b:status]
}
// ExampleCore_LogError logs an error through `Core.LogError` for Core orchestration. Core
// keeps orchestration helpers reachable from one predictable facade.
func ExampleCore_LogError() {
c := New()
r := c.LogError(nil, "example", "nothing to log")
Println(r.OK)
// Output: true
}
// ExampleCore_LogWarn logs a warning through `Core.LogWarn` for Core orchestration. Core
// keeps orchestration helpers reachable from one predictable facade.
func ExampleCore_LogWarn() {
c := New()
r := c.LogWarn(nil, "example", "nothing to warn")
Println(r.OK)
// Output: true
}
// ExampleCore_Must unwraps a successful Result through `Core.Must` for Core orchestration.
// Core keeps orchestration helpers reachable from one predictable facade.
func ExampleCore_Must() {
c := New()
c.Must(nil, "example", "no panic")
Println("ok")
// Output: ok
}
// ExampleCore_RegistryOf retrieves a named registry through `Core.RegistryOf` for Core
// orchestration. Core keeps orchestration helpers reachable from one predictable facade.
func ExampleCore_RegistryOf() {
c := New()
c.Action("deploy", func(_ Context, _ Options) Result { return Result{OK: true} })
Println(c.RegistryOf("actions").Names())
Println(c.RegistryOf("missing").Len())
// Output:
// [deploy]
// 0
}