summaryrefslogtreecommitdiff
path: root/cmd/podman/root_test.go
diff options
context:
space:
mode:
authorJordan Christiansen <xordspar0@gmail.com>2020-10-08 12:07:42 -0500
committerJordan Christiansen <xordspar0@gmail.com>2020-10-09 10:36:21 -0500
commitc47a1b1e550a361a009156e14fcc933dfbbdee64 (patch)
treeacf4f8b11e4b70998f8b055ef2bbc41d752a15e6 /cmd/podman/root_test.go
parent73488369586d387db0e4754fa56d5d0077a24940 (diff)
downloadpodman-c47a1b1e550a361a009156e14fcc933dfbbdee64.tar.gz
podman-c47a1b1e550a361a009156e14fcc933dfbbdee64.tar.bz2
podman-c47a1b1e550a361a009156e14fcc933dfbbdee64.zip
Fix the "err: cause" order of OCI runtime errors
Previously, the order of OCI error messages was reversed, so that the type of error was listed as the cause. For example: Error: writing file `cpu.cfs_quota_us`: Invalid argument: OCI runtime error This error message makes it seem like "OCI runtime error" is the argument that was invalid. In fact, "OCI runtime error" is the error and "writing file ..." is the cause. With this change, the above message reads: Error: OCI runtime error: writing file `cpu.cfs_quota_us`: Invalid argument Signed-off-by: Jordan Christiansen <xordspar0@gmail.com>
Diffstat (limited to 'cmd/podman/root_test.go')
-rw-r--r--cmd/podman/root_test.go34
1 files changed, 34 insertions, 0 deletions
diff --git a/cmd/podman/root_test.go b/cmd/podman/root_test.go
new file mode 100644
index 000000000..0473128df
--- /dev/null
+++ b/cmd/podman/root_test.go
@@ -0,0 +1,34 @@
+package main
+
+import (
+ "fmt"
+ "strings"
+ "testing"
+
+ "github.com/containers/podman/v2/libpod/define"
+ "github.com/pkg/errors"
+)
+
+func TestFormatError(t *testing.T) {
+ err := errors.New("unknown error")
+ output := formatError(err)
+ expected := fmt.Sprintf("Error: %v", err)
+
+ if output != expected {
+ t.Errorf("Expected \"%s\" to equal \"%s\"", output, err.Error())
+ }
+}
+
+func TestFormatOCIError(t *testing.T) {
+ expectedPrefix := "Error: "
+ expectedSuffix := "OCI runtime output"
+ err := errors.Wrap(define.ErrOCIRuntime, expectedSuffix)
+ output := formatError(err)
+
+ if !strings.HasPrefix(output, expectedPrefix) {
+ t.Errorf("Expected \"%s\" to start with \"%s\"", output, expectedPrefix)
+ }
+ if !strings.HasSuffix(output, expectedSuffix) {
+ t.Errorf("Expected \"%s\" to end with \"%s\"", output, expectedSuffix)
+ }
+}