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 0ea685c
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 13 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
29 changes: 16 additions & 13 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,6 +236,11 @@ func (v *Venom) registerUserExecutors(ctx context.Context, name string, vars map
}
v.executorFileCache[f] = btes
}
executorName, _ := getExecutorName(btes)
if len(executorName) == 0 {
fileName := filepath.Base(f)
executorName = strings.TrimSuffix(fileName, filepath.Ext(fileName))
}

varsFromInput, err := getUserExecutorInputYML(ctx, btes)
if err != nil {
Expand All @@ -257,23 +267,16 @@ func (v *Venom) registerUserExecutors(ctx context.Context, name string, vars map
}
}

content, err := interpolate.Do(string(btes), varsComputed)
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)
if err := yaml.Unmarshal(btes, &ux); err != nil {
return errors.Wrapf(err, "unable to parse file %q", f)
}

Debug(ctx, "User executor %q revolved with content %v", f, content)

for k, vr := range varsComputed {
ux.Input.Add(k, vr)
}

v.RegisterExecutorUser(ux.Executor, ux)
ux.Executor = executorName
v.RegisterExecutorUser(executorName, ux)
}
return nil
}
Expand Down

0 comments on commit 0ea685c

Please sign in to comment.