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)
| 717 | // to get the reference passing of the reversed resource working with the fancy |
| 718 | // version. |
| 719 | func 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 |
nothing calls this directly
no test coverage detected