github.com/containerd/nerdctl@v1.7.7/pkg/infoutil/infoutil_unix_test.go (about) 1 //go:build freebsd || linux 2 3 /* 4 Copyright The containerd Authors. 5 6 Licensed under the Apache License, Version 2.0 (the "License"); 7 you may not use this file except in compliance with the License. 8 You may obtain a copy of the License at 9 10 http://www.apache.org/licenses/LICENSE-2.0 11 12 Unless required by applicable law or agreed to in writing, software 13 distributed under the License is distributed on an "AS IS" BASIS, 14 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 See the License for the specific language governing permissions and 16 limitations under the License. 17 */ 18 19 package infoutil 20 21 import ( 22 "strings" 23 "testing" 24 25 "gotest.tools/v3/assert" 26 ) 27 28 func TestDistroNameAlpine(t *testing.T) { 29 const etcOSRelease = `NAME="Alpine Linux" 30 ID=alpine 31 VERSION_ID=3.13.2 32 PRETTY_NAME="Alpine Linux v3.13" 33 HOME_URL="https://alpinelinux.org/" 34 BUG_REPORT_URL="https://bugs.alpinelinux.org/" 35 ` 36 r := strings.NewReader(etcOSRelease) 37 assert.Equal(t, "Alpine Linux v3.13", distroName(r)) 38 } 39 40 func TestDistroNameAlpineAltered(t *testing.T) { 41 const etcOSRelease = `NAME="Alpine Linux" 42 ID=alpine 43 VERSION_ID=3.13.2 44 PRETTY_NAME=Alpine Linux v3.13 # some comment 45 HOME_URL="https://alpinelinux.org/" 46 BUG_REPORT_URL="https://bugs.alpinelinux.org/" 47 ` 48 r := strings.NewReader(etcOSRelease) 49 assert.Equal(t, "Alpine Linux v3.13", distroName(r)) 50 } 51 52 func TestDistroNameUbuntu(t *testing.T) { 53 const etcOSRelease = `NAME="Ubuntu" 54 VERSION="20.10 (Groovy Gorilla)" 55 ID=ubuntu 56 ID_LIKE=debian 57 PRETTY_NAME="Ubuntu 20.10" 58 VERSION_ID="20.10" 59 HOME_URL="https://www.ubuntu.com/" 60 SUPPORT_URL="https://help.ubuntu.com/" 61 BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/" 62 PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy" 63 VERSION_CODENAME=groovy 64 UBUNTU_CODENAME=groovy` 65 r := strings.NewReader(etcOSRelease) 66 assert.Equal(t, "Ubuntu 20.10", distroName(r)) 67 } 68 69 func TestDistroNameCentOS(t *testing.T) { 70 const etcOSRelease = `NAME="CentOS Linux" 71 VERSION="7 (Core)" 72 ID="centos" 73 ID_LIKE="rhel fedora" 74 VERSION_ID="7" 75 PRETTY_NAME="CentOS Linux 7 (Core)" 76 ANSI_COLOR="0;31" 77 CPE_NAME="cpe:/o:centos:centos:7" 78 HOME_URL="https://www.centos.org/" 79 BUG_REPORT_URL="https://bugs.centos.org/" 80 81 CENTOS_MANTISBT_PROJECT="CentOS-7" 82 CENTOS_MANTISBT_PROJECT_VERSION="7" 83 REDHAT_SUPPORT_PRODUCT="centos" 84 REDHAT_SUPPORT_PRODUCT_VERSION="7" 85 ` 86 r := strings.NewReader(etcOSRelease) 87 assert.Equal(t, "CentOS Linux 7 (Core)", distroName(r)) 88 } 89 90 func TestDistroNameEmpty(t *testing.T) { 91 r := strings.NewReader("") 92 assert.Equal(t, UnameO, distroName(r)) 93 } 94 95 func TestDistroNameNoPrettyName(t *testing.T) { 96 const etcOSRelease = `NAME="Foo" 97 VERSION = "42.0" 98 ` 99 r := strings.NewReader(etcOSRelease) 100 assert.Equal(t, "Foo 42.0", distroName(r)) 101 }