From e039ef45b4f7865ab9a0fb38fa7c63814e89caa1 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Sat, 22 Aug 2026 16:24:00 +0200 Subject: [PATCH] deprecate ErrParseRuncVersion This error was added in 6a4f927d6393d862ea5ded21a833368eecb06dfe, but no longer used since e32098aae3bc878417256292705aedbde3aa3dd8 (before v1.0.0). Deprecate it, in case there's consumers checking for this error. Also remove the error-return from parseVersion, which was never used, and rewrite the test to use a test-table to make it a bit more DRY. updates 6a4f927d6393d862ea5ded21a833368eecb06dfe updates e32098aae3bc878417256292705aedbde3aa3dd8 Signed-off-by: Sebastiaan van Stijn --- runc.go | 12 ++++--- runc_test.go | 99 ++++++++++++++++++++++++---------------------------- 2 files changed, 53 insertions(+), 58 deletions(-) diff --git a/runc.go b/runc.go index b63a4e7..c519a9b 100644 --- a/runc.go +++ b/runc.go @@ -730,7 +730,9 @@ func (r *Runc) Update(context context.Context, id string, resources *specs.Linux return r.runOrError(cmd) } -// ErrParseRuncVersion is used when the runc version can't be parsed +// ErrParseRuncVersion is kept for backward compatibility with older versions. +// +// Deprecated: ErrParseRuncVersion is never emitted, and should not be used. var ErrParseRuncVersion = errors.New("unable to parse runc version") // Version represents the runc version information @@ -747,16 +749,16 @@ func (r *Runc) Version(context context.Context) (Version, error) { if err != nil { return Version{}, err } - return parseVersion(data.Bytes()) + return parseVersion(data.Bytes()), nil } -func parseVersion(data []byte) (Version, error) { +func parseVersion(data []byte) Version { var v Version parts := strings.Split(strings.TrimSpace(string(data)), "\n") if len(parts) > 0 { if !strings.HasPrefix(parts[0], "runc version ") { - return v, nil + return v } v.Runc = parts[0][13:] @@ -769,7 +771,7 @@ func parseVersion(data []byte) (Version, error) { } } - return v, nil + return v } // Features shows the features implemented by the runtime. diff --git a/runc_test.go b/runc_test.go index 5329e23..58dfd72 100644 --- a/runc_test.go +++ b/runc_test.go @@ -31,63 +31,56 @@ import ( ) func TestParseVersion(t *testing.T) { - testParseVersion := func(t *testing.T, input string, expected Version) { - actual, err := parseVersion([]byte(input)) - if err != nil { - t.Fatalf("unexpected error: %v", err) - } - if expected != actual { - t.Fatalf("expected: %v, actual: %v", expected, actual) - } - } - - t.Run("Full", func(t *testing.T) { - input := `runc version 1.0.0-rc3 + tests := []struct { + doc, input string + expected Version + }{ + { + doc: "Full", + input: `runc version 1.0.0-rc3 commit: 17f3e2a07439a024e54566774d597df9177ee216 spec: 1.0.0-rc5-dev -` - expected := Version{ - Runc: "1.0.0-rc3", - Commit: "17f3e2a07439a024e54566774d597df9177ee216", - Spec: "1.0.0-rc5-dev", - } - testParseVersion(t, input, expected) - }) - - t.Run("WithoutCommit", func(t *testing.T) { - input := `runc version 1.0.0-rc9 +`, + expected: Version{ + Runc: "1.0.0-rc3", + Commit: "17f3e2a07439a024e54566774d597df9177ee216", + Spec: "1.0.0-rc5-dev", + }, + }, + { + doc: "WithoutCommit", + input: `runc version 1.0.0-rc9 spec: 1.0.1-dev -` - expected := Version{ - Runc: "1.0.0-rc9", - Commit: "", - Spec: "1.0.1-dev", - } - testParseVersion(t, input, expected) - }) - - t.Run("Oneline", func(t *testing.T) { - input := `runc version 1.0.0-rc8+dev -` - expected := Version{ - Runc: "1.0.0-rc8+dev", - Commit: "", - Spec: "", - } - testParseVersion(t, input, expected) - }) - - t.Run("Garbage", func(t *testing.T) { - input := `Garbage +`, + expected: Version{ + Runc: "1.0.0-rc9", + Spec: "1.0.1-dev", + }, + }, + { + doc: "Oneline", + input: `runc version 1.0.0-rc8+dev +`, + expected: Version{ + Runc: "1.0.0-rc8+dev", + }, + }, + { + doc: "Garbage", + input: `Garbage spec: nope -` - expected := Version{ - Runc: "", - Commit: "", - Spec: "", - } - testParseVersion(t, input, expected) - }) +`, + expected: Version{}, + }, + } + for _, tc := range tests { + t.Run(tc.doc, func(t *testing.T) { + actual := parseVersion([]byte(tc.input)) + if tc.expected != actual { + t.Fatalf("expected: %v, actual: %v", tc.expected, actual) + } + }) + } } func TestParallelCmds(t *testing.T) {