From 9b9f18a7ed92e2a1f331c86fe1bb371f33c28a5e Mon Sep 17 00:00:00 2001 From: tongxin21 Date: Mon, 28 Oct 2019 19:09:15 +0800 Subject: [PATCH 1/2] add a case is ID="centos" --- pkg/util/helpers.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pkg/util/helpers.go b/pkg/util/helpers.go index 35045def5..84cba0a92 100644 --- a/pkg/util/helpers.go +++ b/pkg/util/helpers.go @@ -89,6 +89,8 @@ func GetOSVersion() (string, error) { return getDebianVersion(osReleaseMap), nil case "ubuntu": return getDebianVersion(osReleaseMap), nil + case "centos": + return getDebianVersion(osReleaseMap), nil default: return "", fmt.Errorf("Unsupported ID in /etc/os-release: %q", osReleaseMap["ID"]) } From d5cb44646e57440d8d6ef47f2912ae0dcd209a68 Mon Sep 17 00:00:00 2001 From: tongxin21 Date: Tue, 29 Oct 2019 09:50:59 +0800 Subject: [PATCH 2/2] add an unit test for parsing the "/etc/os-release" of CentOS add a newline character at the end --- pkg/util/helpers_test.go | 6 ++++++ pkg/util/testdata/os-release-centos | 15 +++++++++++++++ 2 files changed, 21 insertions(+) create mode 100644 pkg/util/testdata/os-release-centos diff --git a/pkg/util/helpers_test.go b/pkg/util/helpers_test.go index 32b3ff5e6..7e7d84d1f 100644 --- a/pkg/util/helpers_test.go +++ b/pkg/util/helpers_test.go @@ -161,6 +161,12 @@ func TestGetOSVersion(t *testing.T) { expectedOSVersion: "ubuntu 16.04.6 LTS (Xenial Xerus)", expectErr: false, }, + { + name: "centos", + fakeOSReleasePath: "testdata/os-release-centos", + expectedOSVersion: "centos 7 (Core)", + expectErr: false, + }, { name: "Unknown", fakeOSReleasePath: "testdata/os-release-unknown", diff --git a/pkg/util/testdata/os-release-centos b/pkg/util/testdata/os-release-centos new file mode 100644 index 000000000..c276e3ae5 --- /dev/null +++ b/pkg/util/testdata/os-release-centos @@ -0,0 +1,15 @@ +NAME="CentOS Linux" +VERSION="7 (Core)" +ID="centos" +ID_LIKE="rhel fedora" +VERSION_ID="7" +PRETTY_NAME="CentOS Linux 7 (Core)" +ANSI_COLOR="0;31" +CPE_NAME="cpe:/o:centos:centos:7" +HOME_URL="https://www.centos.org/" +BUG_REPORT_URL="https://bugs.centos.org/" + +CENTOS_MANTISBT_PROJECT="CentOS-7" +CENTOS_MANTISBT_PROJECT_VERSION="7" +REDHAT_SUPPORT_PRODUCT="centos" +REDHAT_SUPPORT_PRODUCT_VERSION="7"