MCPcopy
hub / github.com/purpleidea/mgmt / TestResources2

Function TestResources2

engine/resources/resources_test.go:719–1794  ·  view source on GitHub ↗

TestResources2 just tests a partial execution of the resource by running CheckApply and Reverse and basics without the mainloop. It's a less accurate representation of a running resource, but is still useful for many circumstances. This also uses a simpler timeline, because it was not possible to ge

(t *testing.T)

Source from the content-addressed store, hash-verified

717// to get the reference passing of the reversed resource working with the fancy
718// version.
719func TestResources2(t *testing.T) {
720 type test struct { // an individual test
721 name string
722 timeline []func() error // TODO: this could be a generator that keeps pushing out steps until it's done!
723 expect func() error // function to check for expected state
724 startup func() error // function to run as startup (unused?)
725 cleanup func() error // function to run as cleanup
726 }
727
728 type initOptions struct {
729 // graph is the graph that should be passed in with Init
730 graph *pgraph.Graph
731 // TODO: add more options if needed
732
733 // logf specifies the log function for Init to pass through...
734 logf func(format string, v ...interface{})
735 }
736
737 type initOption func(*initOptions)
738
739 addGraph := func(graph *pgraph.Graph) initOption {
740 return func(io *initOptions) {
741 io.graph = graph
742 }
743 }
744
745 addLogf := func(logf func(format string, v ...interface{})) initOption {
746 return func(io *initOptions) {
747 io.logf = logf
748 }
749 }
750
751 // resValidate runs Validate on the res.
752 resValidate := func(res engine.Res) func() error {
753 // run Close
754 return func() error {
755 return res.Validate()
756 }
757 }
758 // resInit runs Init on the res.
759 resInit := func(res engine.Res, opts ...initOption) func() error {
760
761 io := &initOptions{} // defaults
762 for _, optionFunc := range opts { // apply the options
763 optionFunc(io)
764 }
765
766 logf := func(format string, v ...interface{}) {
767 if io.logf == nil {
768 return
769 }
770 io.logf(fmt.Sprintf("test: ")+format+"\n", v...)
771 }
772 init := &engine.Init{
773 //Debug: debug,
774 Logf: logf,
775
776 // unused

Callers

nothing calls this directly

Calls 15

ValidateMethod · 0.95
AddVertexMethod · 0.95
WrapfFunction · 0.92
NewGraphFunction · 0.92
StrInListFunction · 0.92
makeResFunction · 0.85
cleanupFunction · 0.85
stepStruct · 0.85
logfMethod · 0.80
LogfMethod · 0.80
InitMethod · 0.65
CheckApplyMethod · 0.65

Tested by

no test coverage detected