( ctx context.Context, // should return true if that's a leaf we need to execute // for instance if we want to run a check, return true if IsCheck is true isLeaf func(*ModTreeNode) bool, // run the right function on the leaf. For instance run as a check, or run as a generator // clientMetadata is used to know if we want to try to scale out // this callback is used to keep this function generic and allow to return different values runLeaf func(context.Context, *ModTreeNode, *engine.ClientMetadata) error, include, exclude []string, )
| 67 | } |
| 68 | |
| 69 | func (node *ModTreeNode) Run( |
| 70 | ctx context.Context, |
| 71 | // should return true if that's a leaf we need to execute |
| 72 | // for instance if we want to run a check, return true if IsCheck is true |
| 73 | isLeaf func(*ModTreeNode) bool, |
| 74 | // run the right function on the leaf. For instance run as a check, or run as a generator |
| 75 | // clientMetadata is used to know if we want to try to scale out |
| 76 | // this callback is used to keep this function generic and allow to return different values |
| 77 | runLeaf func(context.Context, *ModTreeNode, *engine.ClientMetadata) error, |
| 78 | include, exclude []string, |
| 79 | ) (rerr error) { |
| 80 | clientMD, _ := engine.ClientMetadataFromContext(ctx) |
| 81 | |
| 82 | if isLeaf(node) { |
| 83 | return runLeaf(ctx, node, clientMD) |
| 84 | } |
| 85 | |
| 86 | children, err := node.Children(ctx) |
| 87 | if err != nil { |
| 88 | return err |
| 89 | } |
| 90 | jobs := parallel.New().WithTracing(false) |
| 91 | for _, child := range children { |
| 92 | // FIXME: filtering uses `node` instead of `child` - should match against the child being iterated |
| 93 | if len(include) > 0 { |
| 94 | if match, err := node.Match(ctx, include); err != nil { |
| 95 | return err |
| 96 | } else if !match { |
| 97 | continue |
| 98 | } |
| 99 | } |
| 100 | if len(exclude) > 0 { |
| 101 | if match, err := node.Match(ctx, exclude); err != nil { |
| 102 | return err |
| 103 | } else if match { |
| 104 | continue |
| 105 | } |
| 106 | } |
| 107 | jobs = jobs.WithJob(child.Name, func(ctx context.Context) error { |
| 108 | return child.Run(ctx, isLeaf, runLeaf, nil, nil) |
| 109 | }) |
| 110 | } |
| 111 | return jobs.Run(ctx) // don't suppress the error. That can be handled by the top-level caller if necessary |
| 112 | } |
| 113 | |
| 114 | func (node *ModTreeNode) RunCheck(ctx context.Context, include, exclude []string) error { |
| 115 | return node.runAsCheck(ctx, |
no test coverage detected