Skip to content

Commit

Permalink
update how we read executors
Browse files Browse the repository at this point in the history
  • Loading branch information
fokion committed Aug 4, 2023
1 parent 542f0c5 commit e8dc6e2
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 16 deletions.
4 changes: 2 additions & 2 deletions process_testcase_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func TestProcessVariableAssignments(t *testing.T) {

tcVars := H{"here.some.value": "this is the \nvalue"}

result, is, err := processVariableAssignments(context.TODO(), "", tcVars, b)
result, is, err := processVariableAssignments(context.TODO(), "", &tcVars, b)
assert.True(t, is)
assert.NoError(t, err)
assert.NotNil(t, result)
Expand All @@ -38,7 +38,7 @@ func TestProcessVariableAssignments(t *testing.T) {
script: echo 'foo'
`)
assert.NoError(t, yaml.Unmarshal(b, &wrongStepIn))
result, is, err = processVariableAssignments(context.TODO(), "", tcVars, b)
result, is, err = processVariableAssignments(context.TODO(), "", &tcVars, b)
assert.False(t, is)
assert.NoError(t, err)
assert.Nil(t, result)
Expand Down
2 changes: 1 addition & 1 deletion process_teststep.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func (v *Venom) RunTestStep(ctx context.Context, e ExecutorRunner, tc *TestCase,
flag, exists := os.LookupEnv("VENOM_LOGS_WITH_TIMESTAMP")
if exists && flag == "ON" {
format = "%s.%s.%s.step.%d.%d.dump.json"
name = fmt.Sprintf(format, slug.Make(StringVarFromCtx(ctx, "venom.testsuite.shortName")), slug.Make(tc.Name), time.Now().UTC().Format("15.04.05"), stepNumber, rangedIndex)
name = fmt.Sprintf(format, slug.Make(StringVarFromCtx(ctx, "venom.testsuite.shortName")), time.Now().UTC().Format("15.04.05.000"), slug.Make(tc.Name), stepNumber, rangedIndex)
}
filename := path.Join(oDir, name)

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
42 changes: 42 additions & 0 deletions tests/skip/skip.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name : "Testing skip"
testcases:
- name : "skip something"
steps:
- info:
- Set a variable to 1
- script : "echo '1'"
vars :
out:
from : result.systemout
- name: "Skip this as out is 1 and we are checking if its equal with 2"
script: |
exit 1
skip:
- out ShouldEqual 2
- script: "echo 'false'"
vars:
outAsBool:
from: result.systemout
- name: "skip as outAsBool is False"
script: |
exit 1
skip:
- outAsBool ShouldBeTrue
- name : "producer"
steps:
- info:
- Set a variable to 1
- script : "echo '1'"
vars :
out:
from : result.systemout
- name: "consumer"
skip:
- producer.out ShouldEqual 1
step:
- info:
- "Fail should be skipped as we are checking that the producer.out is equal with 1"
script: |
exit 1
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 e8dc6e2

Please sign in to comment.