Replace go-spew + go-difflib with go-cmp - #1090
Open
mtrmac wants to merge 1 commit into
Open
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
github.com/davecgh/go-spewandgithub.com/pmezard/go-difflibboth have last commits 8 years ago;go-difflibis explicitly unmaintained. Instead, usegithub.com/google/go-cmp, which seems at least minimally maintained.This is locally motivated by
stretrchr/testifyno longer depending on the 2 packages (... by copying them into thetestifypackage...).Note that all three of
go-spew/go-difflib/go-cmpare, except for this one call, used only in tests (the 2 previously instretrchr/testify,go-spewinonsi/gomega).The
go-spewimplementation 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):
(Yes we are logging the diff at a single line)
maps to:
New output:
maps to:
is a bit more chatty, *shrug*.