Skip to content

Commit bc2e070

Browse files
committed
Pass whole test as an arg to the executeStep method instead of passing only steps
Signed-off-by: GLVS Kiriti <glvskiriti2003369@gmail.com>
1 parent d8baeb5 commit bc2e070

File tree

4 files changed

+7
-19
lines changed

4 files changed

+7
-19
lines changed

cmd/declarative.go

+1-4
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,6 @@ func runTestSteps(test declarative.Test) error {
7979
// spawn an alpine container
8080
runner = &declarative.Containerrunner{Image: "golang"}
8181
ctx = context.Background()
82-
ctx = context.WithValue(ctx, declarative.ContextKey("ruleName"), test.Rule)
83-
ctx = context.WithValue(ctx, declarative.ContextKey("beforeScript"), test.Before)
84-
ctx = context.WithValue(ctx, declarative.ContextKey("afterScript"), test.After)
8582
default:
8683
return fmt.Errorf("unsupported runner: %v", test.Runner)
8784
}
@@ -92,7 +89,7 @@ func runTestSteps(test declarative.Test) error {
9289
}
9390

9491
// Execute each step in the test.
95-
err := runner.ExecuteStep(ctx, test.Steps)
92+
err := runner.ExecuteStep(ctx, test)
9693
if err != nil {
9794
return fmt.Errorf("error executing steps for the rule %v : %v", test.Rule, err)
9895
}

pkg/declarative/container.go

+3-10
Original file line numberDiff line numberDiff line change
@@ -90,23 +90,16 @@ func (r *Containerrunner) Setup(ctx context.Context, beforeScript string) error
9090
return nil
9191
}
9292

93-
func (r *Containerrunner) ExecuteStep(ctx context.Context, steps []SyscallStep) error {
93+
func (r *Containerrunner) ExecuteStep(ctx context.Context, test Test) error {
9494
cli, err := client.NewClientWithOpts(client.FromEnv, client.WithAPIVersionNegotiation())
9595
if err != nil {
9696
return fmt.Errorf("error creating Docker Client: %v", err)
9797
}
9898

9999
// Create a yaml structure for given step
100+
test.Runner = "HostRunner" // Change container runner to host runner
100101
testFile := Tests{
101-
Tests: []Test{
102-
{
103-
Rule: ctx.Value(ContextKey("ruleName")).(string),
104-
Runner: "HostRunner",
105-
Before: ctx.Value(ContextKey("beforeScript")).(string),
106-
Steps: steps,
107-
After: ctx.Value(ContextKey("afterScript")).(string),
108-
},
109-
},
102+
Tests: []Test{test},
110103
}
111104

112105
// Marshall struct to yaml data

pkg/declarative/host.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ func (r *Hostrunner) Setup(ctx context.Context, beforeScript string) error {
3131
return nil
3232
}
3333

34-
func (r *Hostrunner) ExecuteStep(ctx context.Context, steps []SyscallStep) error {
34+
func (r *Hostrunner) ExecuteStep(ctx context.Context, test Test) error {
35+
steps := test.Steps
3536
for _, step := range steps {
3637
switch step.Syscall {
3738
case "write":

pkg/declarative/interface.go

+1-4
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,6 @@ import "context"
1919
// Common runner interface for runners like hostrunner, container-runner etc..
2020
type Runner interface {
2121
Setup(ctx context.Context, beforeScript string) error
22-
ExecuteStep(ctx context.Context, steps []SyscallStep) error
22+
ExecuteStep(ctx context.Context, test Test) error
2323
Cleanup(ctx context.Context, afterScript string) error
2424
}
25-
26-
// A type which helps to store and retrive key-value pairs in context
27-
type ContextKey string

0 commit comments

Comments
 (0)