aboutsummaryrefslogtreecommitdiff
path: root/pkg/hooks
diff options
context:
space:
mode:
Diffstat (limited to 'pkg/hooks')
-rw-r--r--pkg/hooks/1.0.0/when_test.go30
-rw-r--r--pkg/hooks/docs/oci-hooks.5.md2
-rw-r--r--pkg/hooks/exec/exec_test.go6
-rw-r--r--pkg/hooks/exec/runtimeconfigfilter_test.go5
4 files changed, 28 insertions, 15 deletions
diff --git a/pkg/hooks/1.0.0/when_test.go b/pkg/hooks/1.0.0/when_test.go
index a749063ff..94b0c3830 100644
--- a/pkg/hooks/1.0.0/when_test.go
+++ b/pkg/hooks/1.0.0/when_test.go
@@ -10,7 +10,8 @@ import (
func TestNoMatch(t *testing.T) {
config := &rspec.Spec{}
- for _, or := range []bool{true, false} {
+ for _, o := range []bool{true, false} {
+ or := o
t.Run(fmt.Sprintf("or %t", or), func(t *testing.T) {
when := When{Or: or}
match, err := when.Match(config, map[string]string{}, false)
@@ -27,9 +28,12 @@ func TestAlways(t *testing.T) {
processStruct := &rspec.Process{
Args: []string{"/bin/sh", "a", "b"},
}
- for _, always := range []bool{true, false} {
- for _, or := range []bool{true, false} {
- for _, process := range []*rspec.Process{processStruct, nil} {
+ for _, a := range []bool{true, false} {
+ always := a
+ for _, o := range []bool{true, false} {
+ or := o
+ for _, p := range []*rspec.Process{processStruct, nil} {
+ process := p
t.Run(fmt.Sprintf("always %t, or %t, has process %t", always, or, process != nil), func(t *testing.T) {
config.Process = process
when := When{Always: &always, Or: or}
@@ -48,7 +52,8 @@ func TestHasBindMountsAnd(t *testing.T) {
hasBindMounts := true
when := When{HasBindMounts: &hasBindMounts}
config := &rspec.Spec{}
- for _, containerHasBindMounts := range []bool{false, true} {
+ for _, b := range []bool{false, true} {
+ containerHasBindMounts := b
t.Run(fmt.Sprintf("%t", containerHasBindMounts), func(t *testing.T) {
match, err := when.Match(config, map[string]string{}, containerHasBindMounts)
if err != nil {
@@ -63,7 +68,8 @@ func TestHasBindMountsOr(t *testing.T) {
hasBindMounts := true
when := When{HasBindMounts: &hasBindMounts, Or: true}
config := &rspec.Spec{}
- for _, containerHasBindMounts := range []bool{false, true} {
+ for _, b := range []bool{false, true} {
+ containerHasBindMounts := b
t.Run(fmt.Sprintf("%t", containerHasBindMounts), func(t *testing.T) {
match, err := when.Match(config, map[string]string{}, containerHasBindMounts)
if err != nil {
@@ -82,7 +88,7 @@ func TestAnnotations(t *testing.T) {
},
}
config := &rspec.Spec{}
- for _, test := range []struct {
+ for _, tt := range []struct {
name string
annotations map[string]string
or bool
@@ -131,6 +137,7 @@ func TestAnnotations(t *testing.T) {
match: false,
},
} {
+ test := tt
t.Run(test.name, func(t *testing.T) {
when.Or = test.or
match, err := when.Match(config, test.annotations, false)
@@ -149,7 +156,7 @@ func TestCommands(t *testing.T) {
},
}
config := &rspec.Spec{}
- for _, test := range []struct {
+ for _, tt := range []struct {
name string
process *rspec.Process
match bool
@@ -173,6 +180,7 @@ func TestCommands(t *testing.T) {
match: false,
},
} {
+ test := tt
t.Run(test.name, func(t *testing.T) {
config.Process = test.process
match, err := when.Match(config, map[string]string{}, false)
@@ -209,7 +217,7 @@ func TestHasBindMountsAndCommands(t *testing.T) {
},
}
config := &rspec.Spec{Process: &rspec.Process{}}
- for _, test := range []struct {
+ for _, tt := range []struct {
name string
command string
hasBindMounts bool
@@ -273,6 +281,7 @@ func TestHasBindMountsAndCommands(t *testing.T) {
match: false,
},
} {
+ test := tt
t.Run(test.name, func(t *testing.T) {
config.Process.Args = []string{test.command}
when.Or = test.or
@@ -287,7 +296,7 @@ func TestHasBindMountsAndCommands(t *testing.T) {
func TestInvalidRegexp(t *testing.T) {
config := &rspec.Spec{Process: &rspec.Process{Args: []string{"/bin/sh"}}}
- for _, test := range []struct {
+ for _, tt := range []struct {
name string
when When
expected string
@@ -308,6 +317,7 @@ func TestInvalidRegexp(t *testing.T) {
expected: "^command: error parsing regexp: .*",
},
} {
+ test := tt
t.Run(test.name, func(t *testing.T) {
_, err := test.when.Match(config, map[string]string{"a": "b"}, false)
if err == nil {
diff --git a/pkg/hooks/docs/oci-hooks.5.md b/pkg/hooks/docs/oci-hooks.5.md
index b50a6bddc..7d13ffa82 100644
--- a/pkg/hooks/docs/oci-hooks.5.md
+++ b/pkg/hooks/docs/oci-hooks.5.md
@@ -25,7 +25,7 @@ Tools consuming this format may also opt to monitor the hook directories for cha
Hooks are injected in the order obtained by sorting the JSON file names, after converting them to lower case, based on their Unicode code points.
For example, a matching hook defined in `01-my-hook.json` would be injected before matching hooks defined in `02-another-hook.json` and `01-UPPERCASE.json`.
-It is strongly recommended to make the sort oder unambiguous depending on an ASCII-only prefix (like the `01`/`02` above).
+It is strongly recommended to make the sort order unambiguous depending on an ASCII-only prefix (like the `01`/`02` above).
Each JSON file should contain an object with one of the following schemas.
diff --git a/pkg/hooks/exec/exec_test.go b/pkg/hooks/exec/exec_test.go
index 7aac315cb..1e105373d 100644
--- a/pkg/hooks/exec/exec_test.go
+++ b/pkg/hooks/exec/exec_test.go
@@ -94,7 +94,7 @@ func TestRunEnvironment(t *testing.T) {
Path: path,
Args: []string{"sh", "-c", "env"},
}
- for _, test := range []struct {
+ for _, tt := range []struct {
name string
env []string
expected map[string]string
@@ -120,6 +120,7 @@ func TestRunEnvironment(t *testing.T) {
},
},
} {
+ test := tt
t.Run(test.name, func(t *testing.T) {
var stderr, stdout bytes.Buffer
hook.Env = test.env
@@ -147,7 +148,7 @@ func TestRunCancel(t *testing.T) {
Args: []string{"sh", "-c", "echo waiting; sleep 2; echo done"},
}
one := 1
- for _, test := range []struct {
+ for _, tt := range []struct {
name string
contextTimeout time.Duration
hookTimeout *int
@@ -174,6 +175,7 @@ func TestRunCancel(t *testing.T) {
expectedRunError: context.DeadlineExceeded,
},
} {
+ test := tt
t.Run(test.name, func(t *testing.T) {
ctx := context.Background()
var stderr, stdout bytes.Buffer
diff --git a/pkg/hooks/exec/runtimeconfigfilter_test.go b/pkg/hooks/exec/runtimeconfigfilter_test.go
index 52d590d14..48dd2f998 100644
--- a/pkg/hooks/exec/runtimeconfigfilter_test.go
+++ b/pkg/hooks/exec/runtimeconfigfilter_test.go
@@ -25,9 +25,9 @@ func pointerFileMode(value os.FileMode) *os.FileMode {
}
func TestRuntimeConfigFilter(t *testing.T) {
- unexpectedEndOfJSONInput := json.Unmarshal([]byte("{\n"), nil)
+ unexpectedEndOfJSONInput := json.Unmarshal([]byte("{\n"), nil) //nolint
- for _, test := range []struct {
+ for _, tt := range []struct {
name string
contextTimeout time.Duration
hooks []spec.Hook
@@ -244,6 +244,7 @@ func TestRuntimeConfigFilter(t *testing.T) {
expectedRunError: unexpectedEndOfJSONInput,
},
} {
+ test := tt
t.Run(test.name, func(t *testing.T) {
ctx := context.Background()
if test.contextTimeout > 0 {