Skip to content

Commit

Permalink
style(decl): replace interface{} with any
Browse files Browse the repository at this point in the history
Signed-off-by: Leonardo Di Giovanna <leonardodigiovanna1@gmail.com>
Co-authored-by: Aldo Lacuku <aldo@lacuku.eu>
  • Loading branch information
ekoops and alacuku committed Dec 5, 2024
1 parent e000191 commit 09aae3d
Show file tree
Hide file tree
Showing 25 changed files with 35 additions and 35 deletions.
16 changes: 8 additions & 8 deletions pkg/test/loader/loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ func (r *TestResource) UnmarshalYAML(node *yaml.Node) error {
// marshal the content.
// TODO: this method should be implemented with a pointer receiver but unfortunately, the yaml.v3 library is only able
// to call it if it is implemented with a value receiver. Uniform the receivers once the library is replaced.
func (r TestResource) MarshalYAML() (interface{}, error) {
func (r TestResource) MarshalYAML() (any, error) {
switch resourceType := r.Type; resourceType {
case TestResourceTypeClientServer:
return struct {
Expand All @@ -271,7 +271,7 @@ func (r TestResource) MarshalYAML() (interface{}, error) {
// provide an addition MarshalYAML method for TestResourceFDSpec, as it will not be called by the library if the Spec
// field specify "inline" (as it should be in our case). Take care of replace this with a more elegant solution once
// yaml.v3 is replaced.
func (r *TestResource) marshalFD() (interface{}, error) {
func (r *TestResource) marshalFD() (any, error) {
spec := r.Spec.(*TestResourceFDSpec)
subSpec := spec.Spec
switch subtype := spec.Subtype; subtype {
Expand Down Expand Up @@ -592,11 +592,11 @@ func (s *TestStep) UnmarshalYAML(node *yaml.Node) error {
// marshal the content.
// TODO: this method should be implemented with a pointer receiver but unfortunately, the yaml.v3 library is only able
// to call it if it is implemented with a value receiver. Uniform the receivers once the library is replaced.
func (s TestStep) MarshalYAML() (interface{}, error) {
func (s TestStep) MarshalYAML() (any, error) {
switch stepType := s.Type; stepType {
case TestStepTypeSyscall:
spec := s.Spec.(*TestStepSyscallSpec)
args := make(map[string]interface{}, len(spec.Args)+len(s.FieldBindings))
args := make(map[string]any, len(spec.Args)+len(s.FieldBindings))
for arg, argValue := range spec.Args {
args[arg] = argValue
}
Expand Down Expand Up @@ -640,8 +640,8 @@ func (t *TestStepType) UnmarshalYAML(node *yaml.Node) error {

// TestStepSyscallSpec describes a system call test step.
type TestStepSyscallSpec struct {
Syscall SyscallName `yaml:"syscall" validate:"-"`
Args map[string]interface{} `yaml:"args" validate:"required"`
Syscall SyscallName `yaml:"syscall" validate:"-"`
Args map[string]any `yaml:"args" validate:"required"`
}

// TestStepFieldBinding contains the information to perform the binding of a field belonging to a source step.
Expand All @@ -653,7 +653,7 @@ type TestStepFieldBinding struct {

var fieldBindingRegex = regexp.MustCompile(`^\${(.+?)\.(.+)}$`)

func getFieldBindings(containingArgName string, args map[string]interface{}) []*TestStepFieldBinding {
func getFieldBindings(containingArgName string, args map[string]any) []*TestStepFieldBinding {
// The prefix of each contained argument is composed by the containing argument name.
var argsPrefix string
if containingArgName != "" {
Expand All @@ -678,7 +678,7 @@ func getFieldBindings(containingArgName string, args map[string]interface{}) []*

// If an argument value is a field binding, remove it from arguments.
delete(args, arg)
case map[string]interface{}:
case map[string]any:
bindings = append(bindings, getFieldBindings(arg, argValue)...)
}
}
Expand Down
8 changes: 4 additions & 4 deletions pkg/test/step/syscall/base/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ var _ syscall.Syscall = (*baseSyscall)(nil)
var errOpenModeMustBePositive = fmt.Errorf("open mode must be a positive integer")

// New creates a new generic system call test step.
func New(stepName string, rawArgs map[string]interface{}, fieldBindings []*step.FieldBinding, argsContainer,
func New(stepName string, rawArgs map[string]any, fieldBindings []*step.FieldBinding, argsContainer,
bindOnlyArgsContainer, retValueContainer reflect.Value, defaultedArgs []string,
runFunc, cleanupFunc func(ctx context.Context) error) (syscall.Syscall, error) {
if err := checkContainersInvariants(argsContainer, bindOnlyArgsContainer, retValueContainer); err != nil {
Expand Down Expand Up @@ -123,7 +123,7 @@ func checkContainersInvariants(argsContainer, bindOnlyArgsContainer, retValueCon

// setArgFieldValues sets the argument fields in argFieldContainer to the corresponding values in rawArgs. It returns
// the list of set arguments field paths.
func setArgFieldValues(argFieldContainer reflect.Value, rawArgs map[string]interface{}) ([]string, error) {
func setArgFieldValues(argFieldContainer reflect.Value, rawArgs map[string]any) ([]string, error) {
fmt.Printf("setArgFieldValues rawArgs: %+v\n", rawArgs)
var boundArgs []string
for rawArg, rawArgValue := range rawArgs {
Expand All @@ -146,7 +146,7 @@ func setArgFieldValues(argFieldContainer reflect.Value, rawArgs map[string]inter
// depending on the field type.
//
//nolint:gocyclo // Disable cyclomatic complexity check.
func setArgFieldValue(argField *field.Field, value interface{}) ([]string, error) {
func setArgFieldValue(argField *field.Field, value any) ([]string, error) {
boundArgs := []string{argField.Path}
argFieldValue := argField.Value
switch argFieldType := argField.Type; argFieldType {
Expand Down Expand Up @@ -280,7 +280,7 @@ func setArgFieldValue(argField *field.Field, value interface{}) ([]string, error
return boundArgs, nil
}

func setSubArgFieldValues(argField *field.Field, value interface{}) ([]string, error) {
func setSubArgFieldValues(argField *field.Field, value any) ([]string, error) {
rawArgs, err := parseMap(value)
if err != nil {
return nil, fmt.Errorf("cannot parse argument field: %w", err)
Expand Down
2 changes: 1 addition & 1 deletion pkg/test/step/syscall/connect/connect.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ type connectSyscall struct {
}

// New creates a new connect system call test step.
func New(name string, rawArgs map[string]interface{}, fieldBindings []*step.FieldBinding) (syscall.Syscall, error) {
func New(name string, rawArgs map[string]any, fieldBindings []*step.FieldBinding) (syscall.Syscall, error) {
c := &connectSyscall{}
argsContainer := reflect.ValueOf(&c.args).Elem()
bindOnlyArgsContainer := reflect.ValueOf(&c.bindOnlyArgs).Elem()
Expand Down
2 changes: 1 addition & 1 deletion pkg/test/step/syscall/dup/dup.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ type dupSyscall struct {
}

// New creates a new dup system call test step.
func New(name string, rawArgs map[string]interface{}, fieldBindings []*step.FieldBinding) (syscall.Syscall, error) {
func New(name string, rawArgs map[string]any, fieldBindings []*step.FieldBinding) (syscall.Syscall, error) {
d := &dupSyscall{}
argsContainer := reflect.ValueOf(&d.args).Elem()
bindOnlyArgsContainer := reflect.ValueOf(&d.bindOnlyArgs).Elem()
Expand Down
2 changes: 1 addition & 1 deletion pkg/test/step/syscall/dup2/dup2.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ type dup2Syscall struct {
}

// New creates a new dup2 system call test step.
func New(name string, rawArgs map[string]interface{}, fieldBindings []*step.FieldBinding) (syscall.Syscall, error) {
func New(name string, rawArgs map[string]any, fieldBindings []*step.FieldBinding) (syscall.Syscall, error) {
d := &dup2Syscall{savedFD: -1}
argsContainer := reflect.ValueOf(&d.args).Elem()
bindOnlyArgsContainer := reflect.ValueOf(&d.bindOnlyArgs).Elem()
Expand Down
2 changes: 1 addition & 1 deletion pkg/test/step/syscall/dup2/dup2_arm64.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@ import (
"github.com/falcosecurity/event-generator/pkg/test/step/syscall"
)

func New(_ string, _ map[string]interface{}, _ []*step.FieldBinding) (syscall.Syscall, error) {
func New(_ string, _ map[string]any, _ []*step.FieldBinding) (syscall.Syscall, error) {
return nil, fmt.Errorf("not supported by the architecture")
}
2 changes: 1 addition & 1 deletion pkg/test/step/syscall/dup3/dup3.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ type dup3Syscall struct {
}

// New creates a new dup3 system call test step.
func New(name string, rawArgs map[string]interface{}, fieldBindings []*step.FieldBinding) (syscall.Syscall, error) {
func New(name string, rawArgs map[string]any, fieldBindings []*step.FieldBinding) (syscall.Syscall, error) {
d := &dup3Syscall{savedFD: -1}
// d.args.Flags defaulted to 0
argsContainer := reflect.ValueOf(&d.args).Elem()
Expand Down
2 changes: 1 addition & 1 deletion pkg/test/step/syscall/finitmodule/finitmodule.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ type finitModuleSyscall struct {
}

// New creates a new finit_module system call test step.
func New(name string, rawArgs map[string]interface{}, fieldBindings []*step.FieldBinding) (syscall.Syscall, error) {
func New(name string, rawArgs map[string]any, fieldBindings []*step.FieldBinding) (syscall.Syscall, error) {
f := &finitModuleSyscall{}
// f.args.ParamValues defaulted to ""
// f.args.Flags defaulted to 0
Expand Down
2 changes: 1 addition & 1 deletion pkg/test/step/syscall/initmodule/initmodule.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ type initModuleSyscall struct {
}

// New creates a new init_module system call test step.
func New(name string, rawArgs map[string]interface{}, fieldBindings []*step.FieldBinding) (syscall.Syscall, error) {
func New(name string, rawArgs map[string]any, fieldBindings []*step.FieldBinding) (syscall.Syscall, error) {
i := &initModuleSyscall{}
// i.args.ParamValues defaulted to ""
argsContainer := reflect.ValueOf(&i.args).Elem()
Expand Down
2 changes: 1 addition & 1 deletion pkg/test/step/syscall/kill/kill.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ type killSyscall struct {
}

// New creates a new kill system call test step.
func New(name string, rawArgs map[string]interface{}, fieldBindings []*step.FieldBinding) (syscall.Syscall, error) {
func New(name string, rawArgs map[string]any, fieldBindings []*step.FieldBinding) (syscall.Syscall, error) {
k := &killSyscall{}
argsContainer := reflect.ValueOf(&k.args).Elem()
bindOnlyArgsContainer := reflect.ValueOf(&k.bindOnlyArgs).Elem()
Expand Down
2 changes: 1 addition & 1 deletion pkg/test/step/syscall/link/link.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ type linkSyscall struct {
}

// New creates a new link system call test step.
func New(name string, rawArgs map[string]interface{}, fieldBindings []*step.FieldBinding) (syscall.Syscall, error) {
func New(name string, rawArgs map[string]any, fieldBindings []*step.FieldBinding) (syscall.Syscall, error) {
l := &linkSyscall{}
argsContainer := reflect.ValueOf(&l.args).Elem()
bindOnlyArgsContainer := reflect.ValueOf(&l.bindOnlyArgs).Elem()
Expand Down
2 changes: 1 addition & 1 deletion pkg/test/step/syscall/link/link_arm64.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@ import (
"github.com/falcosecurity/event-generator/pkg/test/step/syscall"
)

func New(_ string, _ map[string]interface{}, _ []*step.FieldBinding) (syscall.Syscall, error) {
func New(_ string, _ map[string]any, _ []*step.FieldBinding) (syscall.Syscall, error) {
return nil, fmt.Errorf("not supported by the architecture")
}
2 changes: 1 addition & 1 deletion pkg/test/step/syscall/linkat/linkat.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ type linkAtSyscall struct {
}

// New creates a new linkat system call test step.
func New(name string, rawArgs map[string]interface{}, fieldBindings []*step.FieldBinding) (syscall.Syscall, error) {
func New(name string, rawArgs map[string]any, fieldBindings []*step.FieldBinding) (syscall.Syscall, error) {
l := &linkAtSyscall{}
l.bindOnlyArgs.OldDirFD = unix.AT_FDCWD
l.bindOnlyArgs.NewDirFD = unix.AT_FDCWD
Expand Down
2 changes: 1 addition & 1 deletion pkg/test/step/syscall/open/open.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ type openSyscall struct {
}

// New creates a new open system call test step.
func New(name string, rawArgs map[string]interface{}, fieldBindings []*step.FieldBinding) (syscall.Syscall, error) {
func New(name string, rawArgs map[string]any, fieldBindings []*step.FieldBinding) (syscall.Syscall, error) {
o := &openSyscall{}
// o.args.Mode defaulted to 0
argsContainer := reflect.ValueOf(&o.args).Elem()
Expand Down
2 changes: 1 addition & 1 deletion pkg/test/step/syscall/open/open_arm64.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@ import (
"github.com/falcosecurity/event-generator/pkg/test/step/syscall"
)

func New(_ string, _ map[string]interface{}, _ []*step.FieldBinding) (syscall.Syscall, error) {
func New(_ string, _ map[string]any, _ []*step.FieldBinding) (syscall.Syscall, error) {
return nil, fmt.Errorf("not supported by the architecture")
}
2 changes: 1 addition & 1 deletion pkg/test/step/syscall/openat/openat.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ type openAtSyscall struct {
}

// New creates a new openat system call test step.
func New(name string, rawArgs map[string]interface{}, fieldBindings []*step.FieldBinding) (syscall.Syscall, error) {
func New(name string, rawArgs map[string]any, fieldBindings []*step.FieldBinding) (syscall.Syscall, error) {
o := &openAtSyscall{}
o.bindOnlyArgs.DirFD = unix.AT_FDCWD
// o.args.Mode defaulted to 0
Expand Down
2 changes: 1 addition & 1 deletion pkg/test/step/syscall/openat2/openat2.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ type openAt2Syscall struct {
}

// New creates a new openat2 system call test step.
func New(name string, rawArgs map[string]interface{}, fieldBindings []*step.FieldBinding) (syscall.Syscall, error) {
func New(name string, rawArgs map[string]any, fieldBindings []*step.FieldBinding) (syscall.Syscall, error) {
o := &openAt2Syscall{}
o.bindOnlyArgs.DirFD = unix.AT_FDCWD
// o.args.How field defaulted to empty struct.
Expand Down
2 changes: 1 addition & 1 deletion pkg/test/step/syscall/read/read.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ type readSyscall struct {
}

// New creates a new read system call test step.
func New(name string, rawArgs map[string]interface{}, fieldBindings []*step.FieldBinding) (syscall.Syscall, error) {
func New(name string, rawArgs map[string]any, fieldBindings []*step.FieldBinding) (syscall.Syscall, error) {
r := &readSyscall{}
argsContainer := reflect.ValueOf(&r.args).Elem()
bindOnlyArgsContainer := reflect.ValueOf(&r.bindOnlyArgs).Elem()
Expand Down
2 changes: 1 addition & 1 deletion pkg/test/step/syscall/sendto/sendto.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ type sendToSyscall struct {
}

// New creates a new sendto system call test step.
func New(name string, rawArgs map[string]interface{}, fieldBindings []*step.FieldBinding) (syscall.Syscall, error) {
func New(name string, rawArgs map[string]any, fieldBindings []*step.FieldBinding) (syscall.Syscall, error) {
s := &sendToSyscall{}
// s.args.Len defaults to the buffer length at run time, if unbound.
argsContainer := reflect.ValueOf(&s.args).Elem()
Expand Down
2 changes: 1 addition & 1 deletion pkg/test/step/syscall/socket/socket.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ type socketSyscall struct {
}

// New creates a new socket system call test step.
func New(name string, rawArgs map[string]interface{}, fieldBindings []*step.FieldBinding) (syscall.Syscall, error) {
func New(name string, rawArgs map[string]any, fieldBindings []*step.FieldBinding) (syscall.Syscall, error) {
s := &socketSyscall{}
argsContainer := reflect.ValueOf(&s.args).Elem()
bindOnlyArgsContainer := reflect.ValueOf(&s.bindOnlyArgs).Elem()
Expand Down
2 changes: 1 addition & 1 deletion pkg/test/step/syscall/symlink/symlink.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ type symlinkSyscall struct {
}

// New creates a new symlink system call test step.
func New(name string, rawArgs map[string]interface{}, fieldBindings []*step.FieldBinding) (syscall.Syscall, error) {
func New(name string, rawArgs map[string]any, fieldBindings []*step.FieldBinding) (syscall.Syscall, error) {
s := &symlinkSyscall{}
argsContainer := reflect.ValueOf(&s.args).Elem()
bindOnlyArgsContainer := reflect.ValueOf(&s.bindOnlyArgs).Elem()
Expand Down
2 changes: 1 addition & 1 deletion pkg/test/step/syscall/symlink/symlink_arm64.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@ import (
"github.com/falcosecurity/event-generator/pkg/test/step/syscall"
)

func New(_ string, _ map[string]interface{}, _ []*step.FieldBinding) (syscall.Syscall, error) {
func New(_ string, _ map[string]any, _ []*step.FieldBinding) (syscall.Syscall, error) {
return nil, fmt.Errorf("not supported by the architecture")
}
2 changes: 1 addition & 1 deletion pkg/test/step/syscall/symlinkat/symlinkat.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ type symlinkAtSyscall struct {
}

// New creates a new symlinkat system call test step.
func New(name string, rawArgs map[string]interface{}, fieldBindings []*step.FieldBinding) (syscall.Syscall, error) {
func New(name string, rawArgs map[string]any, fieldBindings []*step.FieldBinding) (syscall.Syscall, error) {
s := &symlinkAtSyscall{}
s.bindOnlyArgs.NewDirFD = unix.AT_FDCWD
argsContainer := reflect.ValueOf(&s.args).Elem()
Expand Down
2 changes: 1 addition & 1 deletion pkg/test/step/syscall/syscall.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,6 @@ const (

// Description contains information to build a new Syscall test step.
type Description struct {
RawArgs map[string]interface{}
RawArgs map[string]any
FieldBindings []*step.FieldBinding
}
2 changes: 1 addition & 1 deletion pkg/test/step/syscall/write/write.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ type writeSyscall struct {
}

// New creates a new write system call test step.
func New(name string, rawArgs map[string]interface{}, fieldBindings []*step.FieldBinding) (syscall.Syscall, error) {
func New(name string, rawArgs map[string]any, fieldBindings []*step.FieldBinding) (syscall.Syscall, error) {
w := &writeSyscall{}
// w.args.Len defaults to the buffer length at run time, if unbound.
argsContainer := reflect.ValueOf(&w.args).Elem()
Expand Down

0 comments on commit 09aae3d

Please sign in to comment.