-
Notifications
You must be signed in to change notification settings - Fork 140
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WIP --- Update how we are loading executors #723
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -203,19 +203,22 @@ func (ux UserExecutor) ZeroValueResult() interface{} { | |
func (v *Venom) RunUserExecutor(ctx context.Context, runner ExecutorRunner, tcIn *TestCase, tsIn *TestStepResult, step TestStep) (interface{}, error) { | ||
vrs := tcIn.TestSuiteVars.Clone() | ||
uxIn := runner.GetExecutor().(UserExecutor) | ||
|
||
inputOnlyVrs := H{} | ||
for k, va := range uxIn.Input { | ||
if strings.HasPrefix(k, "input.") { | ||
// do not reinject input.vars from parent user executor if exists | ||
continue | ||
} else if !strings.HasPrefix(k, "venom") { | ||
if vl, ok := step[k]; ok && vl != "" { // value from step | ||
vrs.AddWithPrefix("input", k, vl) | ||
inputOnlyVrs.AddWithPrefix("input", k, vl) | ||
} else { // default value from executor | ||
vrs.AddWithPrefix("input", k, va) | ||
inputOnlyVrs.AddWithPrefix("input", k, va) | ||
} | ||
} else { | ||
vrs.Add(k, va) | ||
inputOnlyVrs.Add(k, va) | ||
} | ||
} | ||
// reload the user executor with the interpolated vars | ||
|
@@ -229,12 +232,13 @@ func (v *Venom) RunUserExecutor(ctx context.Context, runner ExecutorRunner, tcIn | |
TestCaseInput: TestCaseInput{ | ||
Name: ux.Executor, | ||
RawTestSteps: ux.RawTestSteps, | ||
Vars: vrs, | ||
Vars: inputOnlyVrs, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I don't understand the goal of the variable inputOnlyVrs: Doing |
||
}, | ||
TestSuiteVars: tcIn.TestSuiteVars, | ||
IsExecutor: true, | ||
TestStepResults: make([]TestStepResult, 0), | ||
} | ||
tc.Vars.AddAll(vrs) | ||
|
||
tc.originalName = tc.Name | ||
tc.Name = slug.Make(tc.Name) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,7 +15,6 @@ import ( | |
|
||
"github.com/confluentinc/bincover" | ||
"github.com/fatih/color" | ||
"github.com/ovh/cds/sdk/interpolate" | ||
"github.com/pkg/errors" | ||
"github.com/rockbears/yaml" | ||
"github.com/spf13/cast" | ||
|
@@ -216,13 +215,19 @@ func (v *Venom) getUserExecutorFilesPath(vars map[string]string) (filePaths []st | |
} | ||
|
||
func (v *Venom) registerUserExecutors(ctx context.Context, name string, vars map[string]string) error { | ||
_, ok := v.executorsUser[name] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can't do a cache here. The GetExecutorRunner is used in RunUserExecutor, so that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will mark it as WIP as I need to check if I have migrated all the necessary changes for it to work properly. You do need to check if you have read the executor or not as this is the point of the cache , we want to read that file only once and not multiple times ) . |
||
if ok { | ||
return nil | ||
} | ||
if v.executorFileCache != nil && len(v.executorFileCache) != 0 { | ||
return errors.Errorf("Could not find executor with name %v ", name) | ||
} | ||
executorsPath, err := v.getUserExecutorFilesPath(vars) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
for _, f := range executorsPath { | ||
Info(ctx, "Reading %v", f) | ||
btes, ok := v.executorFileCache[f] | ||
if !ok { | ||
btes, err = os.ReadFile(f) | ||
|
@@ -231,49 +236,24 @@ func (v *Venom) registerUserExecutors(ctx context.Context, name string, vars map | |
} | ||
v.executorFileCache[f] = btes | ||
} | ||
|
||
varsFromInput, err := getUserExecutorInputYML(ctx, btes) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
// varsFromInput contains the default vars from the executor | ||
var varsFromInputMap map[string]string | ||
if len(varsFromInput) > 0 { | ||
varsFromInputMap, err = DumpStringPreserveCase(varsFromInput) | ||
if err != nil { | ||
return errors.Wrapf(err, "unable to parse variables") | ||
} | ||
executorName, _ := getExecutorName(btes) | ||
if len(executorName) == 0 { | ||
fileName := filepath.Base(f) | ||
executorName = strings.TrimSuffix(fileName, filepath.Ext(fileName)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The name of user executor is the attribute in the file. It should not be defined by the filename. In the read, we can see that the user executor is defined in the file lib/customA.yml, but the executor name is executor. |
||
} | ||
|
||
varsComputed := map[string]string{} | ||
for k, v := range vars { | ||
varsComputed[k] = v | ||
} | ||
for k, v := range varsFromInputMap { | ||
// we only take vars from varsFromInputMap if it's not already exist in vars from teststep vars | ||
if _, ok := vars[k]; !ok { | ||
varsComputed[k] = v | ||
} | ||
} | ||
|
||
content, err := interpolate.Do(string(btes), varsComputed) | ||
varsFromInput, err := getUserExecutorInputYML(ctx, btes) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
ux := UserExecutor{Filename: f} | ||
if err := yaml.Unmarshal([]byte(content), &ux); err != nil { | ||
return errors.Wrapf(err, "unable to parse file %q with content %v", f, content) | ||
} | ||
|
||
Debug(ctx, "User executor %q revolved with content %v", f, content) | ||
|
||
for k, vr := range varsComputed { | ||
ux.Input.Add(k, vr) | ||
if err := yaml.Unmarshal(btes, &ux); err != nil { | ||
return errors.Wrapf(err, "unable to parse file %q", f) | ||
} | ||
|
||
v.RegisterExecutorUser(ux.Executor, ux) | ||
ux.Input.AddAll(varsFromInput) | ||
ux.Executor = executorName | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think there is no need to force assign here, ux.Executor already contains the value, as the name is already in the btes. |
||
v.RegisterExecutorUser(executorName, ux) | ||
} | ||
return nil | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not needed, see comment below.