Skip to content

Replace go-spew + go-difflib with go-cmp - #1090

Open
mtrmac wants to merge 1 commit into
podman-container-tools:mainfrom
mtrmac:diff-deps
Open

Replace go-spew + go-difflib with go-cmp#1090
mtrmac wants to merge 1 commit into
podman-container-tools:mainfrom
mtrmac:diff-deps

Conversation

@mtrmac

@mtrmac mtrmac commented Aug 17, 2026

Copy link
Copy Markdown
Contributor

github.com/davecgh/go-spew and github.com/pmezard/go-difflib both have last commits 8 years ago; go-difflib is explicitly unmaintained. Instead, use github.com/google/go-cmp, which seems at least minimally maintained.

This is locally motivated by stretrchr/testify no longer depending on the 2 packages (... by copying them into the testify package...).

Note that all three of go-spew / go-difflib / go-cmp are, except for this one call, used only in tests (the 2 previously in stretrchr/testify, go-spew in onsi/gomega).

The go-spew implementation is a bit heavier than we might like, but the code is only used for debug logs, and worrying less about our supply chains seems valuable.

Previous output (from tests in this package):

time="2026-08-17T20:29:50+02:00" level=error msg="precreate hook 0 made configuration changes:\n--- Old\n+++ New\n@@ -19,3 +19,3 @@\n   Namespaces: ([]specs.LinuxNamespace) <nil>,\n-  Devices: ([]specs.LinuxDevice) (len=1) {\n+  Devices: ([]specs.LinuxDevice) (len=2) {\n    (specs.LinuxDevice) {\n@@ -25,2 +25,11 @@\n     Minor: (int64) 229,\n+    FileMode: (*fs.FileMode)(-rw-------),\n+    UID: (*uint32)(0),\n+    GID: (*uint32)(0)\n+   },\n+   (specs.LinuxDevice) {\n+    Path: (string) (len=8) \"/dev/sda\",\n+    Type: (string) (len=1) \"b\",\n+    Major: (int64) 8,\n+    Minor: (int64) 0,\n     FileMode: (*fs.FileMode)(-rw-------),\n"
time="2026-08-17T20:29:50+02:00" level=error msg="precreate hook 1 made configuration changes:\n--- Old\n+++ New\n@@ -30,3 +30,3 @@\n    (specs.LinuxDevice) {\n-    Path: (string) (len=8) \"/dev/sda\",\n+    Path: (string) (len=8) \"/dev/sdb\",\n     Type: (string) (len=1) \"b\",\n"

(Yes we are logging the diff at a single line)

maps to:

precreate hook 0 made configuration changes:
--- Old
+++ New
@@ -19,3 +19,3 @@
   Namespaces: ([]specs.LinuxNamespace) <nil>,
-  Devices: ([]specs.LinuxDevice) (len=1) {
+  Devices: ([]specs.LinuxDevice) (len=2) {
    (specs.LinuxDevice) {
@@ -25,2 +25,11 @@
     Minor: (int64) 229,
+    FileMode: (*fs.FileMode)(-rw-------),
+    UID: (*uint32)(0),
+    GID: (*uint32)(0)
+   },
+   (specs.LinuxDevice) {
+    Path: (string) (len=8) "/dev/sda",
+    Type: (string) (len=1) "b",
+    Major: (int64) 8,
+    Minor: (int64) 0,
     FileMode: (*fs.FileMode)(-rw-------),

precreate hook 1 made configuration changes:
--- Old
+++ New
@@ -30,3 +30,3 @@
    (specs.LinuxDevice) {
-    Path: (string) (len=8) "/dev/sda",
+    Path: (string) (len=8) "/dev/sdb",
     Type: (string) (len=1) "b",

New output:

time="2026-08-17T20:37:11+02:00" level=error msg="precreate hook 0 made configuration changes:\n\u00a0\u00a0&specs.Spec{\n\u00a0\u00a0\t... // 6 identical fields\n\u00a0\u00a0\tHooks:       nil,\n\u00a0\u00a0\tAnnotations: nil,\n\u00a0\u00a0\tLinux: &specs.Linux{\n\u00a0\u00a0\t\t... // 4 identical fields\n\u00a0\u00a0\t\tCgroupsPath: \"\",\n\u00a0\u00a0\t\tNamespaces:  nil,\n\u00a0\u00a0\t\tDevices: []specs.LinuxDevice{\n\u00a0\u00a0\t\t\t{Path: \"/dev/fuse\", Type: \"c\", Major: 10, Minor: 229, ...},\n+\u00a0\t\t\t{Path: \"/dev/sda\", Type: \"b\", Major: 8, FileMode: s\"-rw-------\", UID: &0, GID: &0},\n\u00a0\u00a0\t\t},\n\u00a0\u00a0\t\tNetDevices: nil,\n\u00a0\u00a0\t\tSeccomp:    nil,\n\u00a0\u00a0\t\t... // 8 identical fields\n\u00a0\u00a0\t},\n\u00a0\u00a0\tSolaris: nil,\n\u00a0\u00a0\tWindows: nil,\n\u00a0\u00a0\t... // 3 identical fields\n\u00a0\u00a0}\n"
time="2026-08-17T20:37:11+02:00" level=error msg="precreate hook 1 made configuration changes:\n\u00a0\u00a0&specs.Spec{\n\u00a0\u00a0\t... // 6 identical fields\n\u00a0\u00a0\tHooks:       nil,\n\u00a0\u00a0\tAnnotations: nil,\n\u00a0\u00a0\tLinux: &specs.Linux{\n\u00a0\u00a0\t\t... // 4 identical fields\n\u00a0\u00a0\t\tCgroupsPath: \"\",\n\u00a0\u00a0\t\tNamespaces:  nil,\n\u00a0\u00a0\t\tDevices: []specs.LinuxDevice{\n\u00a0\u00a0\t\t\t{Path: \"/dev/fuse\", Type: \"c\", Major: 10, Minor: 229, ...},\n\u00a0\u00a0\t\t\t{\n-\u00a0\t\t\t\tPath:  \"/dev/sda\",\n+\u00a0\t\t\t\tPath:  \"/dev/sdb\",\n\u00a0\u00a0\t\t\t\tType:  \"b\",\n\u00a0\u00a0\t\t\t\tMajor: 8,\n\u00a0\u00a0\t\t\t\t... // 4 identical fields\n\u00a0\u00a0\t\t\t},\n\u00a0\u00a0\t\t},\n\u00a0\u00a0\t\tNetDevices: nil,\n\u00a0\u00a0\t\tSeccomp:    nil,\n\u00a0\u00a0\t\t... // 8 identical fields\n\u00a0\u00a0\t},\n\u00a0\u00a0\tSolaris: nil,\n\u00a0\u00a0\tWindows: nil,\n\u00a0\u00a0\t... // 3 identical fields\n\u00a0\u00a0}\n"

maps to:

precreate hook 0 made configuration changes:
  &specs.Spec{
      ... // 6 identical fields
      Hooks:       nil,
      Annotations: nil,
      Linux: &specs.Linux{
              ... // 4 identical fields
              CgroupsPath: "",
              Namespaces:  nil,
              Devices: []specs.LinuxDevice{
                      {Path: "/dev/fuse", Type: "c", Major: 10, Minor: 229, ...},
+                      {Path: "/dev/sda", Type: "b", Major: 8, FileMode: s"-rw-------", UID: &0, GID: &0},
              },
              NetDevices: nil,
              Seccomp:    nil,
              ... // 8 identical fields
      },
      Solaris: nil,
      Windows: nil,
      ... // 3 identical fields
  }

precreate hook 1 made configuration changes:
  &specs.Spec{
      ... // 6 identical fields
      Hooks:       nil,
      Annotations: nil,
      Linux: &specs.Linux{
              ... // 4 identical fields
              CgroupsPath: "",
              Namespaces:  nil,
              Devices: []specs.LinuxDevice{
                      {Path: "/dev/fuse", Type: "c", Major: 10, Minor: 229, ...},
                      {
-                              Path:  "/dev/sda",
+                              Path:  "/dev/sdb",
                              Type:  "b",
                              Major: 8,
                              ... // 4 identical fields
                      },
              },
              NetDevices: nil,
              Seccomp:    nil,
              ... // 8 identical fields
      },
      Solaris: nil,
      Windows: nil,
      ... // 3 identical fields
  }

is a bit more chatty, *shrug*.

github.com/davecgh/go-spew and github.com/pmezard/go-difflib
both have last commits 8 years ago; go-difflib is explicitly
unmaintained. Instead, use github.com/google/go-cmp, which
seems at least minimally maintained.

This is locally motivated by stretrchr/testify no longer
depending on the 2 packages (... by copying them into the
testify package...).

Note that all three of go-spew / go-difflib / go-cmp are,
except for this one call, used only in tests (the 2 previously
in stretrchr/testify, go-spew in onsi/gomega).

The go-spew implementation is a bit heavier than we might
like, but the code is only used for debug logs, and worrying less
about our supply chains seems valuable.

Previous output (from tests in this package):
> time="2026-08-17T20:29:50+02:00" level=error msg="precreate hook 0 made configuration changes:\n--- Old\n+++ New\n@@ -19,3 +19,3 @@\n   Namespaces: ([]specs.LinuxNamespace) <nil>,\n-  Devices: ([]specs.LinuxDevice) (len=1) {\n+  Devices: ([]specs.LinuxDevice) (len=2) {\n    (specs.LinuxDevice) {\n@@ -25,2 +25,11 @@\n     Minor: (int64) 229,\n+    FileMode: (*fs.FileMode)(-rw-------),\n+    UID: (*uint32)(0),\n+    GID: (*uint32)(0)\n+   },\n+   (specs.LinuxDevice) {\n+    Path: (string) (len=8) \"/dev/sda\",\n+    Type: (string) (len=1) \"b\",\n+    Major: (int64) 8,\n+    Minor: (int64) 0,\n     FileMode: (*fs.FileMode)(-rw-------),\n"
> time="2026-08-17T20:29:50+02:00" level=error msg="precreate hook 1 made configuration changes:\n--- Old\n+++ New\n@@ -30,3 +30,3 @@\n    (specs.LinuxDevice) {\n-    Path: (string) (len=8) \"/dev/sda\",\n+    Path: (string) (len=8) \"/dev/sdb\",\n     Type: (string) (len=1) \"b\",\n"

(Yes we are logging the diff at a single line)

maps to:
> precreate hook 0 made configuration changes:
> --- Old
> +++ New
> @@ -19,3 +19,3 @@
>    Namespaces: ([]specs.LinuxNamespace) <nil>,
> -  Devices: ([]specs.LinuxDevice) (len=1) {
> +  Devices: ([]specs.LinuxDevice) (len=2) {
>     (specs.LinuxDevice) {
> @@ -25,2 +25,11 @@
>      Minor: (int64) 229,
> +    FileMode: (*fs.FileMode)(-rw-------),
> +    UID: (*uint32)(0),
> +    GID: (*uint32)(0)
> +   },
> +   (specs.LinuxDevice) {
> +    Path: (string) (len=8) "/dev/sda",
> +    Type: (string) (len=1) "b",
> +    Major: (int64) 8,
> +    Minor: (int64) 0,
>      FileMode: (*fs.FileMode)(-rw-------),
>
> precreate hook 1 made configuration changes:
> --- Old
> +++ New
> @@ -30,3 +30,3 @@
>     (specs.LinuxDevice) {
> -    Path: (string) (len=8) "/dev/sda",
> +    Path: (string) (len=8) "/dev/sdb",
>      Type: (string) (len=1) "b",

New output:
> time="2026-08-17T20:37:11+02:00" level=error msg="precreate hook 0 made configuration changes:\n\u00a0\u00a0&specs.Spec{\n\u00a0\u00a0\t... // 6 identical fields\n\u00a0\u00a0\tHooks:       nil,\n\u00a0\u00a0\tAnnotations: nil,\n\u00a0\u00a0\tLinux: &specs.Linux{\n\u00a0\u00a0\t\t... // 4 identical fields\n\u00a0\u00a0\t\tCgroupsPath: \"\",\n\u00a0\u00a0\t\tNamespaces:  nil,\n\u00a0\u00a0\t\tDevices: []specs.LinuxDevice{\n\u00a0\u00a0\t\t\t{Path: \"/dev/fuse\", Type: \"c\", Major: 10, Minor: 229, ...},\n+\u00a0\t\t\t{Path: \"/dev/sda\", Type: \"b\", Major: 8, FileMode: s\"-rw-------\", UID: &0, GID: &0},\n\u00a0\u00a0\t\t},\n\u00a0\u00a0\t\tNetDevices: nil,\n\u00a0\u00a0\t\tSeccomp:    nil,\n\u00a0\u00a0\t\t... // 8 identical fields\n\u00a0\u00a0\t},\n\u00a0\u00a0\tSolaris: nil,\n\u00a0\u00a0\tWindows: nil,\n\u00a0\u00a0\t... // 3 identical fields\n\u00a0\u00a0}\n"
> time="2026-08-17T20:37:11+02:00" level=error msg="precreate hook 1 made configuration changes:\n\u00a0\u00a0&specs.Spec{\n\u00a0\u00a0\t... // 6 identical fields\n\u00a0\u00a0\tHooks:       nil,\n\u00a0\u00a0\tAnnotations: nil,\n\u00a0\u00a0\tLinux: &specs.Linux{\n\u00a0\u00a0\t\t... // 4 identical fields\n\u00a0\u00a0\t\tCgroupsPath: \"\",\n\u00a0\u00a0\t\tNamespaces:  nil,\n\u00a0\u00a0\t\tDevices: []specs.LinuxDevice{\n\u00a0\u00a0\t\t\t{Path: \"/dev/fuse\", Type: \"c\", Major: 10, Minor: 229, ...},\n\u00a0\u00a0\t\t\t{\n-\u00a0\t\t\t\tPath:  \"/dev/sda\",\n+\u00a0\t\t\t\tPath:  \"/dev/sdb\",\n\u00a0\u00a0\t\t\t\tType:  \"b\",\n\u00a0\u00a0\t\t\t\tMajor: 8,\n\u00a0\u00a0\t\t\t\t... // 4 identical fields\n\u00a0\u00a0\t\t\t},\n\u00a0\u00a0\t\t},\n\u00a0\u00a0\t\tNetDevices: nil,\n\u00a0\u00a0\t\tSeccomp:    nil,\n\u00a0\u00a0\t\t... // 8 identical fields\n\u00a0\u00a0\t},\n\u00a0\u00a0\tSolaris: nil,\n\u00a0\u00a0\tWindows: nil,\n\u00a0\u00a0\t... // 3 identical fields\n\u00a0\u00a0}\n"

maps to:
> precreate hook 0 made configuration changes:
>   &specs.Spec{
>       ... // 6 identical fields
>       Hooks:       nil,
>       Annotations: nil,
>       Linux: &specs.Linux{
>               ... // 4 identical fields
>               CgroupsPath: "",
>               Namespaces:  nil,
>               Devices: []specs.LinuxDevice{
>                       {Path: "/dev/fuse", Type: "c", Major: 10, Minor: 229, ...},
> +                      {Path: "/dev/sda", Type: "b", Major: 8, FileMode: s"-rw-------", UID: &0, GID: &0},
>               },
>               NetDevices: nil,
>               Seccomp:    nil,
>               ... // 8 identical fields
>       },
>       Solaris: nil,
>       Windows: nil,
>       ... // 3 identical fields
>   }
>
> precreate hook 1 made configuration changes:
>   &specs.Spec{
>       ... // 6 identical fields
>       Hooks:       nil,
>       Annotations: nil,
>       Linux: &specs.Linux{
>               ... // 4 identical fields
>               CgroupsPath: "",
>               Namespaces:  nil,
>               Devices: []specs.LinuxDevice{
>                       {Path: "/dev/fuse", Type: "c", Major: 10, Minor: 229, ...},
>                       {
> -                              Path:  "/dev/sda",
> +                              Path:  "/dev/sdb",
>                               Type:  "b",
>                               Major: 8,
>                               ... // 4 identical fields
>                       },
>               },
>               NetDevices: nil,
>               Seccomp:    nil,
>               ... // 8 identical fields
>       },
>       Solaris: nil,
>       Windows: nil,
>       ... // 3 identical fields
>   }

is a bit more chatty, *shrug*.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
@github-actions github-actions Bot added the common Related to "common" package label Aug 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

common Related to "common" package

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant