Skip to content

Commit

Permalink
Fix how we are reading the executors as at the moment we are not load…
Browse files Browse the repository at this point in the history
…ing them from the cache properly

Signed-off-by: Fokion Sotiropoulos <fokion.s@gmail.com>
  • Loading branch information
fokion committed Sep 27, 2023
1 parent 408bcdf commit f8f16f1
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 37 deletions.
1 change: 1 addition & 0 deletions process_teststep.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ func (v *Venom) RunTestStep(ctx context.Context, e ExecutorRunner, tc *TestCase,
if oDir == "" {
oDir = "."
}

filename := path.Join(oDir, fmt.Sprintf("%s.%s.step.%d.%d.dump.json", slug.Make(StringVarFromCtx(ctx, "venom.testsuite.shortName")), slug.Make(tc.Name), stepNumber, rangedIndex))

if err := os.WriteFile(filename, []byte(HideSensitive(ctx, string(output))), 0644); err != nil {
Expand Down
15 changes: 15 additions & 0 deletions read_partial.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,21 @@ func getVarFromPartialYML(ctx context.Context, btesIn []byte) (H, error) {
return partial.Vars, nil
}

func getExecutorName(btes []byte) (string, error) {
content := readPartialYML(btes, "executor")
type partialType struct {
Executor string `yaml:"executor" json:"executor"`
}
partial := &partialType{}
if len(content) > 0 {
if err := yaml.Unmarshal([]byte(content), &partial); err != nil {
Error(context.Background(), "file content: %s", string(btes))
return "", errors.Wrapf(err, "error while unmarshal - see venom.log")
}
}
return partial.Executor, nil
}

// readPartialYML extract a yml part from a given string
func readPartialYML(btes []byte, attribute string) string {
var result []string
Expand Down
54 changes: 17 additions & 37 deletions venom.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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]
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)
Expand All @@ -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))
}

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
v.RegisterExecutorUser(executorName, ux)
}
return nil
}
Expand Down

0 comments on commit f8f16f1

Please sign in to comment.