mirror of https://github.com/kubernetes/kops.git
Add tests for distributions
This commit is contained in:
parent
22ec1512dc
commit
e29b84da01
|
|
@ -1,4 +1,4 @@
|
|||
load("@io_bazel_rules_go//go:def.bzl", "go_library")
|
||||
load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test")
|
||||
|
||||
go_library(
|
||||
name = "go_default_library",
|
||||
|
|
@ -10,3 +10,12 @@ go_library(
|
|||
visibility = ["//visibility:public"],
|
||||
deps = ["//vendor/k8s.io/klog/v2:go_default_library"],
|
||||
)
|
||||
|
||||
go_test(
|
||||
name = "go_default_test",
|
||||
srcs = ["identify_test.go"],
|
||||
data = [
|
||||
"//util/pkg/distributions/tests:exported_testdata", # keep
|
||||
],
|
||||
embed = [":go_default_library"],
|
||||
)
|
||||
|
|
|
|||
|
|
@ -0,0 +1,114 @@
|
|||
/*
|
||||
Copyright 2020 The Kubernetes Authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package distributions
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"path"
|
||||
"reflect"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestFindDistribution(t *testing.T) {
|
||||
tests := []struct {
|
||||
rootfs string
|
||||
err error
|
||||
expected Distribution
|
||||
}{
|
||||
{
|
||||
rootfs: "amazonlinux2",
|
||||
err: nil,
|
||||
expected: DistributionAmazonLinux2,
|
||||
},
|
||||
{
|
||||
rootfs: "centos7",
|
||||
err: nil,
|
||||
expected: DistributionCentos7,
|
||||
},
|
||||
{
|
||||
rootfs: "centos8",
|
||||
err: nil,
|
||||
expected: DistributionCentos8,
|
||||
},
|
||||
{
|
||||
rootfs: "coreos",
|
||||
err: fmt.Errorf("distribution CoreOS is no longer supported"),
|
||||
expected: "",
|
||||
},
|
||||
{
|
||||
rootfs: "containeros",
|
||||
err: nil,
|
||||
expected: DistributionContainerOS,
|
||||
},
|
||||
{
|
||||
rootfs: "debian8",
|
||||
err: fmt.Errorf("distribution Degian 8 (Jessie) is no longer supported"),
|
||||
expected: "",
|
||||
},
|
||||
{
|
||||
rootfs: "debian9",
|
||||
err: nil,
|
||||
expected: DistributionDebian9,
|
||||
},
|
||||
{
|
||||
rootfs: "debian10",
|
||||
err: nil,
|
||||
expected: DistributionDebian10,
|
||||
},
|
||||
{
|
||||
rootfs: "flatcar",
|
||||
err: nil,
|
||||
expected: DistributionFlatcar,
|
||||
},
|
||||
{
|
||||
rootfs: "rhel7",
|
||||
err: nil,
|
||||
expected: DistributionRhel7,
|
||||
},
|
||||
{
|
||||
rootfs: "rhel8",
|
||||
err: nil,
|
||||
expected: DistributionRhel8,
|
||||
},
|
||||
{
|
||||
rootfs: "ubuntu1604",
|
||||
err: nil,
|
||||
expected: DistributionUbuntu1604,
|
||||
},
|
||||
{
|
||||
rootfs: "ubuntu1804",
|
||||
err: nil,
|
||||
expected: DistributionUbuntu1804,
|
||||
},
|
||||
{
|
||||
rootfs: "ubuntu2004",
|
||||
err: nil,
|
||||
expected: DistributionUbuntu2004,
|
||||
},
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
actual, err := FindDistribution(path.Join("tests", test.rootfs))
|
||||
if !reflect.DeepEqual(err, test.err) {
|
||||
t.Errorf("unexpected error, actual=\"%v\", expected=\"%v\"", err, test.err)
|
||||
continue
|
||||
}
|
||||
if actual != test.expected {
|
||||
t.Errorf("unexpected distribution, actual=%q, expected=%q", actual, test.expected)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
filegroup(
|
||||
name = "exported_testdata",
|
||||
srcs = glob(["**"]),
|
||||
visibility = ["//visibility:public"],
|
||||
)
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
NAME="Amazon Linux"
|
||||
VERSION="2"
|
||||
ID="amzn"
|
||||
ID_LIKE="centos rhel fedora"
|
||||
VERSION_ID="2"
|
||||
PRETTY_NAME="Amazon Linux 2"
|
||||
ANSI_COLOR="0;33"
|
||||
CPE_NAME="cpe:2.3:o:amazon:amazon_linux:2"
|
||||
HOME_URL="https://amazonlinux.com/"
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
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"
|
||||
|
||||
|
|
@ -0,0 +1 @@
|
|||
CentOS Linux release 7.8.2003 (Core)
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
NAME="CentOS Linux"
|
||||
VERSION="8 (Core)"
|
||||
ID="centos"
|
||||
ID_LIKE="rhel fedora"
|
||||
VERSION_ID="8"
|
||||
PLATFORM_ID="platform:el8"
|
||||
PRETTY_NAME="CentOS Linux 8 (Core)"
|
||||
ANSI_COLOR="0;31"
|
||||
CPE_NAME="cpe:/o:centos:centos:8"
|
||||
HOME_URL="https://www.centos.org/"
|
||||
BUG_REPORT_URL="https://bugs.centos.org/"
|
||||
|
||||
CENTOS_MANTISBT_PROJECT="CentOS-8"
|
||||
CENTOS_MANTISBT_PROJECT_VERSION="8"
|
||||
REDHAT_SUPPORT_PRODUCT="centos"
|
||||
REDHAT_SUPPORT_PRODUCT_VERSION="8"
|
||||
|
||||
|
|
@ -0,0 +1 @@
|
|||
CentOS Linux release 8.2.2004 (Core)
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
CHROMEOS_AUSERVER=https://tools.google.com/service/update2
|
||||
CHROMEOS_BOARD_APPID={76E245CF-C0D0-444D-BA50-36739C18EB00}
|
||||
CHROMEOS_CANARY_APPID={90F229CE-83E2-4FAF-8479-E368A34938B1}
|
||||
CHROMEOS_DEVSERVER=
|
||||
CHROMEOS_RELEASE_APPID={76E245CF-C0D0-444D-BA50-36739C18EB00}
|
||||
CHROMEOS_RELEASE_BOARD=lakitu
|
||||
CHROMEOS_RELEASE_BRANCH_NUMBER=1185
|
||||
CHROMEOS_RELEASE_BUILD_NUMBER=12871
|
||||
CHROMEOS_RELEASE_BUILD_TYPE=Official Build
|
||||
CHROMEOS_RELEASE_CHROME_MILESTONE=81
|
||||
CHROMEOS_RELEASE_DESCRIPTION=12871.1185.0 (Official Build) stable-channel lakitu
|
||||
CHROMEOS_RELEASE_KEYSET=v10
|
||||
CHROMEOS_RELEASE_NAME=Chrome OS
|
||||
CHROMEOS_RELEASE_PATCH_NUMBER=0
|
||||
CHROMEOS_RELEASE_TRACK=stable-channel
|
||||
CHROMEOS_RELEASE_VERSION=12871.1185.0
|
||||
DEVICETYPE=OTHER
|
||||
GOOGLE_RELEASE=12871.1185.0
|
||||
HWID_OVERRIDE=LAKITU DEFAULT
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
BUILD_ID=12871.1185.0
|
||||
NAME="Container-Optimized OS"
|
||||
KERNEL_COMMIT_ID=1d5bc45f886bc0308010614cdcdf658f5fb44a25
|
||||
GOOGLE_CRASH_ID=Lakitu
|
||||
VERSION_ID=81
|
||||
BUG_REPORT_URL="https://cloud.google.com/container-optimized-os/docs/resources/support-policy#contact_us"
|
||||
PRETTY_NAME="Container-Optimized OS from Google"
|
||||
VERSION=81
|
||||
GOOGLE_METRICS_PRODUCT_ID=26
|
||||
HOME_URL="https://cloud.google.com/container-optimized-os/docs"
|
||||
ID=cos
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
DISTRIB_ID="Container Linux by CoreOS"
|
||||
DISTRIB_RELEASE=2247.7.0
|
||||
DISTRIB_CODENAME="Rhyolite"
|
||||
DISTRIB_DESCRIPTION="Container Linux by CoreOS 2247.7.0 (Rhyolite)"
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
NAME="Container Linux by CoreOS"
|
||||
ID=coreos
|
||||
VERSION=2247.7.0
|
||||
VERSION_ID=2247.7.0
|
||||
BUILD_ID=2019-11-19-2251
|
||||
PRETTY_NAME="Container Linux by CoreOS 2247.7.0 (Rhyolite)"
|
||||
ANSI_COLOR="38;5;75"
|
||||
HOME_URL="https://coreos.com/"
|
||||
BUG_REPORT_URL="https://issues.coreos.com"
|
||||
COREOS_BOARD="amd64-usr"
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
NAME="Container Linux by CoreOS"
|
||||
ID=coreos
|
||||
VERSION=2247.7.0
|
||||
VERSION_ID=2247.7.0
|
||||
BUILD_ID=2019-11-19-2251
|
||||
PRETTY_NAME="Container Linux by CoreOS 2247.7.0 (Rhyolite)"
|
||||
ANSI_COLOR="38;5;75"
|
||||
HOME_URL="https://coreos.com/"
|
||||
BUG_REPORT_URL="https://issues.coreos.com"
|
||||
COREOS_BOARD="amd64-usr"
|
||||
|
|
@ -0,0 +1 @@
|
|||
10.3
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
PRETTY_NAME="Debian GNU/Linux 10 (buster)"
|
||||
NAME="Debian GNU/Linux"
|
||||
VERSION_ID="10"
|
||||
VERSION="10 (buster)"
|
||||
VERSION_CODENAME=buster
|
||||
ID=debian
|
||||
HOME_URL="https://www.debian.org/"
|
||||
SUPPORT_URL="https://www.debian.org/support"
|
||||
BUG_REPORT_URL="https://bugs.debian.org/"
|
||||
|
|
@ -0,0 +1 @@
|
|||
8.11
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
PRETTY_NAME="Debian GNU/Linux 8 (jessie)"
|
||||
NAME="Debian GNU/Linux"
|
||||
VERSION_ID="8"
|
||||
VERSION="8 (jessie)"
|
||||
ID=debian
|
||||
HOME_URL="http://www.debian.org/"
|
||||
SUPPORT_URL="http://www.debian.org/support"
|
||||
BUG_REPORT_URL="https://bugs.debian.org/"
|
||||
|
|
@ -0,0 +1 @@
|
|||
9.9
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
PRETTY_NAME="Debian GNU/Linux 9 (stretch)"
|
||||
NAME="Debian GNU/Linux"
|
||||
VERSION_ID="9"
|
||||
VERSION="9 (stretch)"
|
||||
ID=debian
|
||||
HOME_URL="https://www.debian.org/"
|
||||
SUPPORT_URL="https://www.debian.org/support"
|
||||
BUG_REPORT_URL="https://bugs.debian.org/"
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
DISTRIB_ID="Flatcar Container Linux by Kinvolk"
|
||||
DISTRIB_RELEASE=2592.0.0
|
||||
DISTRIB_CODENAME="Oklo"
|
||||
DISTRIB_DESCRIPTION="Flatcar Container Linux by Kinvolk 2592.0.0 (Oklo)"
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
NAME="Flatcar Container Linux by Kinvolk"
|
||||
ID=flatcar
|
||||
ID_LIKE=coreos
|
||||
VERSION=2592.0.0
|
||||
VERSION_ID=2592.0.0
|
||||
BUILD_ID=2020-08-05-2321
|
||||
PRETTY_NAME="Flatcar Container Linux by Kinvolk 2592.0.0 (Oklo)"
|
||||
ANSI_COLOR="38;5;75"
|
||||
HOME_URL="https://flatcar-linux.org/"
|
||||
BUG_REPORT_URL="https://issues.flatcar-linux.org"
|
||||
FLATCAR_BOARD="amd64-usr"
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
NAME="Flatcar Container Linux by Kinvolk"
|
||||
ID=flatcar
|
||||
ID_LIKE=coreos
|
||||
VERSION=2592.0.0
|
||||
VERSION_ID=2592.0.0
|
||||
BUILD_ID=2020-08-05-2321
|
||||
PRETTY_NAME="Flatcar Container Linux by Kinvolk 2592.0.0 (Oklo)"
|
||||
ANSI_COLOR="38;5;75"
|
||||
HOME_URL="https://flatcar-linux.org/"
|
||||
BUG_REPORT_URL="https://issues.flatcar-linux.org"
|
||||
FLATCAR_BOARD="amd64-usr"
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
NAME="Red Hat Enterprise Linux Server"
|
||||
VERSION="7.8 (Maipo)"
|
||||
ID="rhel"
|
||||
ID_LIKE="fedora"
|
||||
VARIANT="Server"
|
||||
VARIANT_ID="server"
|
||||
VERSION_ID="7.8"
|
||||
PRETTY_NAME="Red Hat Enterprise Linux Server 7.8 (Maipo)"
|
||||
ANSI_COLOR="0;31"
|
||||
CPE_NAME="cpe:/o:redhat:enterprise_linux:7.8:GA:server"
|
||||
HOME_URL="https://www.redhat.com/"
|
||||
BUG_REPORT_URL="https://bugzilla.redhat.com/"
|
||||
|
||||
REDHAT_BUGZILLA_PRODUCT="Red Hat Enterprise Linux 7"
|
||||
REDHAT_BUGZILLA_PRODUCT_VERSION=7.8
|
||||
REDHAT_SUPPORT_PRODUCT="Red Hat Enterprise Linux"
|
||||
REDHAT_SUPPORT_PRODUCT_VERSION="7.8"
|
||||
|
|
@ -0,0 +1 @@
|
|||
Red Hat Enterprise Linux Server release 7.8 (Maipo)
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
NAME="Red Hat Enterprise Linux"
|
||||
VERSION="8.2 (Ootpa)"
|
||||
ID="rhel"
|
||||
ID_LIKE="fedora"
|
||||
VERSION_ID="8.2"
|
||||
PLATFORM_ID="platform:el8"
|
||||
PRETTY_NAME="Red Hat Enterprise Linux 8.2 (Ootpa)"
|
||||
ANSI_COLOR="0;31"
|
||||
CPE_NAME="cpe:/o:redhat:enterprise_linux:8.2:GA"
|
||||
HOME_URL="https://www.redhat.com/"
|
||||
BUG_REPORT_URL="https://bugzilla.redhat.com/"
|
||||
|
||||
REDHAT_BUGZILLA_PRODUCT="Red Hat Enterprise Linux 8"
|
||||
REDHAT_BUGZILLA_PRODUCT_VERSION=8.2
|
||||
REDHAT_SUPPORT_PRODUCT="Red Hat Enterprise Linux"
|
||||
REDHAT_SUPPORT_PRODUCT_VERSION="8.2"
|
||||
|
|
@ -0,0 +1 @@
|
|||
Red Hat Enterprise Linux release 8.2 (Ootpa)
|
||||
|
|
@ -0,0 +1 @@
|
|||
stretch/sid
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
DISTRIB_ID=Ubuntu
|
||||
DISTRIB_RELEASE=16.04
|
||||
DISTRIB_CODENAME=xenial
|
||||
DISTRIB_DESCRIPTION="Ubuntu 16.04.6 LTS"
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
NAME="Ubuntu"
|
||||
VERSION="16.04.6 LTS (Xenial Xerus)"
|
||||
ID=ubuntu
|
||||
ID_LIKE=debian
|
||||
PRETTY_NAME="Ubuntu 16.04.6 LTS"
|
||||
VERSION_ID="16.04"
|
||||
HOME_URL="http://www.ubuntu.com/"
|
||||
SUPPORT_URL="http://help.ubuntu.com/"
|
||||
BUG_REPORT_URL="http://bugs.launchpad.net/ubuntu/"
|
||||
VERSION_CODENAME=xenial
|
||||
UBUNTU_CODENAME=xenial
|
||||
|
|
@ -0,0 +1 @@
|
|||
buster/sid
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
DISTRIB_ID=Ubuntu
|
||||
DISTRIB_RELEASE=18.04
|
||||
DISTRIB_CODENAME=bionic
|
||||
DISTRIB_DESCRIPTION="Ubuntu 18.04.4 LTS"
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
NAME="Ubuntu"
|
||||
VERSION="18.04.4 LTS (Bionic Beaver)"
|
||||
ID=ubuntu
|
||||
ID_LIKE=debian
|
||||
PRETTY_NAME="Ubuntu 18.04.4 LTS"
|
||||
VERSION_ID="18.04"
|
||||
HOME_URL="https://www.ubuntu.com/"
|
||||
SUPPORT_URL="https://help.ubuntu.com/"
|
||||
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
|
||||
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
|
||||
VERSION_CODENAME=bionic
|
||||
UBUNTU_CODENAME=bionic
|
||||
|
|
@ -0,0 +1 @@
|
|||
bullseye/sid
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
DISTRIB_ID=Ubuntu
|
||||
DISTRIB_RELEASE=20.04
|
||||
DISTRIB_CODENAME=focal
|
||||
DISTRIB_DESCRIPTION="Ubuntu 20.04.1 LTS"
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
NAME="Ubuntu"
|
||||
VERSION="20.04.1 LTS (Focal Fossa)"
|
||||
ID=ubuntu
|
||||
ID_LIKE=debian
|
||||
PRETTY_NAME="Ubuntu 20.04.1 LTS"
|
||||
VERSION_ID="20.04"
|
||||
HOME_URL="https://www.ubuntu.com/"
|
||||
SUPPORT_URL="https://help.ubuntu.com/"
|
||||
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
|
||||
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
|
||||
VERSION_CODENAME=focal
|
||||
UBUNTU_CODENAME=focal
|
||||
Loading…
Reference in New Issue