diff --git a/cmd/declarative.go b/cmd/declarative.go index f14a4356..2b248e01 100644 --- a/cmd/declarative.go +++ b/cmd/declarative.go @@ -79,9 +79,6 @@ func runTestSteps(test declarative.Test) error { // spawn an alpine container runner = &declarative.Containerrunner{Image: "golang"} ctx = context.Background() - ctx = context.WithValue(ctx, declarative.ContextKey("ruleName"), test.Rule) - ctx = context.WithValue(ctx, declarative.ContextKey("beforeScript"), test.Before) - ctx = context.WithValue(ctx, declarative.ContextKey("afterScript"), test.After) default: return fmt.Errorf("unsupported runner: %v", test.Runner) } @@ -92,7 +89,7 @@ func runTestSteps(test declarative.Test) error { } // Execute each step in the test. - err := runner.ExecuteStep(ctx, test.Steps) + err := runner.ExecuteStep(ctx, test) if err != nil { return fmt.Errorf("error executing steps for the rule %v : %v", test.Rule, err) } diff --git a/pkg/declarative/container.go b/pkg/declarative/container.go index d5aa91a7..f75d8897 100644 --- a/pkg/declarative/container.go +++ b/pkg/declarative/container.go @@ -90,23 +90,16 @@ func (r *Containerrunner) Setup(ctx context.Context, beforeScript string) error return nil } -func (r *Containerrunner) ExecuteStep(ctx context.Context, steps []SyscallStep) error { +func (r *Containerrunner) ExecuteStep(ctx context.Context, test Test) error { cli, err := client.NewClientWithOpts(client.FromEnv, client.WithAPIVersionNegotiation()) if err != nil { return fmt.Errorf("error creating Docker Client: %v", err) } // Create a yaml structure for given step + test.Runner = "HostRunner" // Change container runner to host runner testFile := Tests{ - Tests: []Test{ - { - Rule: ctx.Value(ContextKey("ruleName")).(string), - Runner: "HostRunner", - Before: ctx.Value(ContextKey("beforeScript")).(string), - Steps: steps, - After: ctx.Value(ContextKey("afterScript")).(string), - }, - }, + Tests: []Test{test}, } // Marshall struct to yaml data diff --git a/pkg/declarative/host.go b/pkg/declarative/host.go index 6ad1e71f..32147212 100644 --- a/pkg/declarative/host.go +++ b/pkg/declarative/host.go @@ -31,7 +31,8 @@ func (r *Hostrunner) Setup(ctx context.Context, beforeScript string) error { return nil } -func (r *Hostrunner) ExecuteStep(ctx context.Context, steps []SyscallStep) error { +func (r *Hostrunner) ExecuteStep(ctx context.Context, test Test) error { + steps := test.Steps for _, step := range steps { switch step.Syscall { case "write": diff --git a/pkg/declarative/interface.go b/pkg/declarative/interface.go index 242f7eda..4f588599 100644 --- a/pkg/declarative/interface.go +++ b/pkg/declarative/interface.go @@ -19,9 +19,6 @@ import "context" // Common runner interface for runners like hostrunner, container-runner etc.. type Runner interface { Setup(ctx context.Context, beforeScript string) error - ExecuteStep(ctx context.Context, steps []SyscallStep) error + ExecuteStep(ctx context.Context, test Test) error Cleanup(ctx context.Context, afterScript string) error } - -// A type which helps to store and retrive key-value pairs in context -type ContextKey string