From 62ad6fb7b610480db970a5dec302ad25cea5fee6 Mon Sep 17 00:00:00 2001 From: Casey Callendrello Date: Wed, 27 Apr 2022 21:41:40 +0200 Subject: [PATCH] libcni: handle empty version when parsing version Without this Delete failed for empty-version configs. Update the tests to catch this case. Signed-off-by: Casey Callendrello --- libcni/backwards_compatibility_test.go | 3 +++ pkg/version/plugin.go | 4 ++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/libcni/backwards_compatibility_test.go b/libcni/backwards_compatibility_test.go index 0bba36faa..dabd87213 100644 --- a/libcni/backwards_compatibility_test.go +++ b/libcni/backwards_compatibility_test.go @@ -66,6 +66,9 @@ var _ = Describe("Backwards compatibility", func() { Expect(result).To(Equal(legacy_examples.ExpectedResult)) + err = cniConfig.DelNetwork(context.TODO(), netConf, runtimeConf) + Expect(err).NotTo(HaveOccurred()) + Expect(os.RemoveAll(pluginPath)).To(Succeed()) }) diff --git a/pkg/version/plugin.go b/pkg/version/plugin.go index d4bc9d169..17b22b6b0 100644 --- a/pkg/version/plugin.go +++ b/pkg/version/plugin.go @@ -86,8 +86,8 @@ func (*PluginDecoder) Decode(jsonBytes []byte) (PluginInfo, error) { // minor, and micro numbers or returns an error func ParseVersion(version string) (int, int, int, error) { var major, minor, micro int - if version == "" { - return -1, -1, -1, fmt.Errorf("invalid version %q: the version is empty", version) + if version == "" { // special case: no version declared == v0.1.0 + return 0, 1, 0, nil } parts := strings.Split(version, ".")