New example files: entitlement, task, lock, log, drive, config, command, info. Every major source file now has a dedicated *_example_test.go with compilable, tested examples. 561 tests, 84.8% coverage. Co-Authored-By: Virgil <virgil@lethean.io>
41 lines
896 B
Go
41 lines
896 B
Go
package core_test
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
. "dappco.re/go/core"
|
|
)
|
|
|
|
func ExampleCore_Command_register() {
|
|
c := New()
|
|
c.Command("deploy/to/homelab", Command{
|
|
Description: "Deploy to homelab",
|
|
Action: func(opts Options) Result {
|
|
return Result{Value: "deployed", OK: true}
|
|
},
|
|
})
|
|
|
|
fmt.Println(c.Command("deploy/to/homelab").OK)
|
|
// Output: true
|
|
}
|
|
|
|
func ExampleCore_Command_managed() {
|
|
c := New()
|
|
c.Command("serve", Command{
|
|
Action: func(_ Options) Result { return Result{OK: true} },
|
|
Managed: "process.daemon",
|
|
})
|
|
|
|
cmd := c.Command("serve").Value.(*Command)
|
|
fmt.Println(cmd.IsManaged())
|
|
// Output: true
|
|
}
|
|
|
|
func ExampleCore_Commands() {
|
|
c := New()
|
|
c.Command("deploy", Command{Action: func(_ Options) Result { return Result{OK: true} }})
|
|
c.Command("test", Command{Action: func(_ Options) Result { return Result{OK: true} }})
|
|
|
|
fmt.Println(c.Commands())
|
|
// Output: [deploy test]
|
|
}
|