github.com/quay/claircore@v1.5.28/oracle/distributionscanner_test.go (about) 1 package oracle 2 3 import ( 4 "bytes" 5 "testing" 6 7 "github.com/google/go-cmp/cmp" 8 ) 9 10 var ( 11 nineOSRelease = []byte(`NAME="Oracle Linux Server" 12 VERSION="9.2" 13 ID="ol" 14 ID_LIKE="fedora" 15 VARIANT="Server" 16 VARIANT_ID="server" 17 VERSION_ID="9.2" 18 PLATFORM_ID="platform:el9" 19 PRETTY_NAME="Oracle Linux Server 9.2" 20 ANSI_COLOR="0;31" 21 CPE_NAME="cpe:/o:oracle:linux:9:2:server" 22 HOME_URL="https://linux.oracle.com/" 23 BUG_REPORT_URL="https://github.com/oracle/oracle-linux" 24 25 ORACLE_BUGZILLA_PRODUCT="Oracle Linux 9" 26 ORACLE_BUGZILLA_PRODUCT_VERSION=9.2 27 ORACLE_SUPPORT_PRODUCT="Oracle Linux" 28 ORACLE_SUPPORT_PRODUCT_VERSION=9.2`) 29 30 eightOSRelease = []byte(`NAME="Oracle Linux Server" 31 VERSION="8.0" 32 ID="ol" 33 ID_LIKE="fedora" 34 VARIANT="Server" 35 VARIANT_ID="server" 36 VERSION_ID="8.0" 37 PLATFORM_ID="platform:el8" 38 PRETTY_NAME="Oracle Linux Server 8.0" 39 ANSI_COLOR="0;31" 40 CPE_NAME="cpe:/o:oracle:linux:8:0:server" 41 HOME_URL="https://linux.oracle.com/" 42 BUG_REPORT_URL="https://bugzilla.oracle.com/" 43 44 ORACLE_BUGZILLA_PRODUCT="Oracle Linux 8" 45 ORACLE_BUGZILLA_PRODUCT_VERSION=8.0 46 ORACLE_SUPPORT_PRODUCT="Oracle Linux" 47 ORACLE_SUPPORT_PRODUCT_VERSION=8.0`) 48 49 sevenOSRelease = []byte(`NAME="Oracle Linux Server" 50 VERSION="7.7" 51 ID="ol" 52 ID_LIKE="fedora" 53 VARIANT="Server" 54 VARIANT_ID="server" 55 VERSION_ID="7.7" 56 PRETTY_NAME="Oracle Linux Server 7.7" 57 ANSI_COLOR="0;31" 58 CPE_NAME="cpe:/o:oracle:linux:7:7:server" 59 HOME_URL="https://linux.oracle.com/" 60 BUG_REPORT_URL="https://bugzilla.oracle.com/" 61 62 ORACLE_BUGZILLA_PRODUCT="Oracle Linux 7" 63 ORACLE_BUGZILLA_PRODUCT_VERSION=7.7 64 ORACLE_SUPPORT_PRODUCT="Oracle Linux" 65 ORACLE_SUPPORT_PRODUCT_VERSION=7.7`) 66 67 sixOSRelease = []byte(`NAME="Oracle Linux Server" 68 VERSION="6.10" 69 ID="ol" 70 VERSION_ID="6.10" 71 PRETTY_NAME="Oracle Linux Server 6.10" 72 ANSI_COLOR="0;31" 73 CPE_NAME="cpe:/o:oracle:linux:6:10:server" 74 HOME_URL="https://linux.oracle.com/" 75 BUG_REPORT_URL="https://bugzilla.oracle.com/" 76 77 ORACLE_BUGZILLA_PRODUCT="Oracle Linux 6" 78 ORACLE_BUGZILLA_PRODUCT_VERSION=6.10 79 ORACLE_SUPPORT_PRODUCT="Oracle Linux" 80 ORACLE_SUPPORT_PRODUCT_VERSION=6.10`) 81 82 // Oracle Five versions do not have os-release file and only have /etc/issue file 83 fiveIssue = []byte(` 84 Oracle Linux Server release 5.11 85 Kernel \r on an \m 86 `) 87 ) 88 89 func TestDistributionScanner(t *testing.T) { 90 table := []struct { 91 name string 92 release Release 93 file []byte 94 }{ 95 { 96 name: "9.2", 97 release: Nine, 98 file: nineOSRelease, 99 }, 100 { 101 name: "8.0", 102 release: Eight, 103 file: eightOSRelease, 104 }, 105 { 106 name: "7.7", 107 release: Seven, 108 file: sevenOSRelease, 109 }, 110 { 111 name: "6.10", 112 release: Six, 113 file: sixOSRelease, 114 }, 115 { 116 name: "5.11", 117 release: Five, 118 file: fiveIssue, 119 }, 120 } 121 for _, tt := range table { 122 t.Run(tt.name, func(t *testing.T) { 123 scanner := DistributionScanner{} 124 dist := scanner.parse(bytes.NewBuffer(tt.file)) 125 if !cmp.Equal(dist, releaseToDist(tt.release)) { 126 t.Fatalf("%v", cmp.Diff(dist, releaseToDist(tt.release))) 127 } 128 }) 129 } 130 }