summaryrefslogtreecommitdiff
path: root/pkg/hooks/exec
diff options
context:
space:
mode:
Diffstat (limited to 'pkg/hooks/exec')
-rw-r--r--pkg/hooks/exec/exec.go3
-rw-r--r--pkg/hooks/exec/runtimeconfigfilter.go4
-rw-r--r--pkg/hooks/exec/runtimeconfigfilter_test.go30
3 files changed, 22 insertions, 15 deletions
diff --git a/pkg/hooks/exec/exec.go b/pkg/hooks/exec/exec.go
index 2b7bc5f31..bc639245f 100644
--- a/pkg/hooks/exec/exec.go
+++ b/pkg/hooks/exec/exec.go
@@ -10,7 +10,6 @@ import (
"time"
rspec "github.com/opencontainers/runtime-spec/specs-go"
- "github.com/pkg/errors"
"github.com/sirupsen/logrus"
)
@@ -46,7 +45,7 @@ func Run(ctx context.Context, hook *rspec.Hook, state []byte, stdout io.Writer,
go func() {
err := cmd.Wait()
if err != nil {
- err = errors.Wrapf(err, "executing %v", cmd.Args)
+ err = fmt.Errorf("executing %v: %w", cmd.Args, err)
}
exit <- err
}()
diff --git a/pkg/hooks/exec/runtimeconfigfilter.go b/pkg/hooks/exec/runtimeconfigfilter.go
index 3ab3073b2..72d4b8979 100644
--- a/pkg/hooks/exec/runtimeconfigfilter.go
+++ b/pkg/hooks/exec/runtimeconfigfilter.go
@@ -4,12 +4,12 @@ import (
"bytes"
"context"
"encoding/json"
+ "fmt"
"reflect"
"time"
"github.com/davecgh/go-spew/spew"
spec "github.com/opencontainers/runtime-spec/specs-go"
- "github.com/pkg/errors"
"github.com/pmezard/go-difflib/difflib"
"github.com/sirupsen/logrus"
)
@@ -43,7 +43,7 @@ func RuntimeConfigFilter(ctx context.Context, hooks []spec.Hook, config *spec.Sp
err = json.Unmarshal(data, &newConfig)
if err != nil {
logrus.Debugf("invalid JSON from config-filter hook %d:\n%s", i, string(data))
- return nil, errors.Wrapf(err, "unmarshal output from config-filter hook %d", i)
+ return nil, fmt.Errorf("unmarshal output from config-filter hook %d: %w", i, err)
}
if !reflect.DeepEqual(config, &newConfig) {
diff --git a/pkg/hooks/exec/runtimeconfigfilter_test.go b/pkg/hooks/exec/runtimeconfigfilter_test.go
index f4b6cf86a..a4e9b1fdb 100644
--- a/pkg/hooks/exec/runtimeconfigfilter_test.go
+++ b/pkg/hooks/exec/runtimeconfigfilter_test.go
@@ -3,28 +3,29 @@ package exec
import (
"context"
"encoding/json"
+ "errors"
"os"
"testing"
"time"
spec "github.com/opencontainers/runtime-spec/specs-go"
- "github.com/pkg/errors"
"github.com/stretchr/testify/assert"
)
func TestRuntimeConfigFilter(t *testing.T) {
- unexpectedEndOfJSONInput := json.Unmarshal([]byte("{\n"), nil) //nolint
+ unexpectedEndOfJSONInput := json.Unmarshal([]byte("{\n"), nil) //nolint:govet // this should force the error
fileMode := os.FileMode(0600)
rootUint32 := uint32(0)
binUser := int(1)
for _, tt := range []struct {
- name string
- contextTimeout time.Duration
- hooks []spec.Hook
- input *spec.Spec
- expected *spec.Spec
- expectedHookError string
- expectedRunError error
+ name string
+ contextTimeout time.Duration
+ hooks []spec.Hook
+ input *spec.Spec
+ expected *spec.Spec
+ expectedHookError string
+ expectedRunError error
+ expectedRunErrorString string
}{
{
name: "no-op",
@@ -231,7 +232,8 @@ func TestRuntimeConfigFilter(t *testing.T) {
Path: "rootfs",
},
},
- expectedRunError: unexpectedEndOfJSONInput,
+ expectedRunError: unexpectedEndOfJSONInput,
+ expectedRunErrorString: unexpectedEndOfJSONInput.Error(),
},
} {
test := tt
@@ -243,7 +245,13 @@ func TestRuntimeConfigFilter(t *testing.T) {
defer cancel()
}
hookErr, err := RuntimeConfigFilter(ctx, test.hooks, test.input, DefaultPostKillTimeout)
- assert.Equal(t, test.expectedRunError, errors.Cause(err))
+ if test.expectedRunError != nil {
+ if test.expectedRunErrorString != "" {
+ assert.Contains(t, err.Error(), test.expectedRunErrorString)
+ } else {
+ assert.True(t, errors.Is(err, test.expectedRunError))
+ }
+ }
if test.expectedHookError == "" {
if hookErr != nil {
t.Fatal(hookErr)