github.com/quay/claircore@v1.5.28/aws/distributionscanner_test.go (about) 1 package aws 2 3 import ( 4 "bytes" 5 "testing" 6 7 "github.com/google/go-cmp/cmp" 8 ) 9 10 var AL1v201609OSRelease []byte = []byte(`NAME="Amazon Linux AMI" 11 VERSION="2016.09" 12 ID="amzn" 13 ID_LIKE="rhel fedora" 14 VERSION_ID="2016.09" 15 PRETTY_NAME="Amazon Linux AMI 2016.09" 16 ANSI_COLOR="0;33" 17 CPE_NAME="cpe:/o:amazon:linux:2016.09:ga" 18 HOME_URL="http://aws.amazon.com/amazon-linux-ami/"`) 19 20 var AL1v201703OSRelease []byte = []byte(`NAME="Amazon Linux AMI" 21 VERSION="2017.03" 22 ID="amzn" 23 ID_LIKE="rhel fedora" 24 VERSION_ID="2017.03" 25 PRETTY_NAME="Amazon Linux AMI 2017.03" 26 ANSI_COLOR="0;33" 27 CPE_NAME="cpe:/o:amazon:linux:2017.03:ga" 28 HOME_URL="http://aws.amazon.com/amazon-linux-ami/"`) 29 30 var AL1v201709OSRelease []byte = []byte(`NAME="Amazon Linux AMI" 31 VERSION="2017.09" 32 ID="amzn" 33 ID_LIKE="rhel fedora" 34 VERSION_ID="2017.09" 35 PRETTY_NAME="Amazon Linux AMI 2017.09" 36 ANSI_COLOR="0;33" 37 CPE_NAME="cpe:/o:amazon:linux:2017.09:ga" 38 HOME_URL="http://aws.amazon.com/amazon-linux-ami/"`) 39 40 var AL1v201803OSRelease []byte = []byte(`NAME="Amazon Linux AMI" 41 VERSION="2018.03" 42 ID="amzn" 43 ID_LIKE="rhel fedora" 44 VERSION_ID="2018.03" 45 PRETTY_NAME="Amazon Linux AMI 2018.03" 46 ANSI_COLOR="0;33" 47 CPE_NAME="cpe:/o:amazon:linux:2018.03:ga" 48 HOME_URL="http://aws.amazon.com/amazon-linux-ami/"`) 49 50 var AL2OSRelease []byte = []byte(`NAME="Amazon Linux" 51 VERSION="2" 52 ID="amzn" 53 ID_LIKE="centos rhel fedora" 54 VERSION_ID="2" 55 PRETTY_NAME="Amazon Linux 2" 56 ANSI_COLOR="0;33" 57 CPE_NAME="cpe:2.3:o:amazon:amazon_linux:2" 58 HOME_URL="https://amazonlinux.com/"`) 59 60 var AL2023OSRelease []byte = []byte(`NAME="Amazon Linux" 61 VERSION="2023" 62 ID="amzn" 63 ID_LIKE="fedora" 64 VERSION_ID="2023" 65 PLATFORM_ID="platform:al2023" 66 PRETTY_NAME="Amazon Linux 2023" 67 ANSI_COLOR="0;33" 68 CPE_NAME="cpe:2.3:o:amazon:amazon_linux:2023" 69 HOME_URL="https://aws.amazon.com/linux/" 70 BUG_REPORT_URL="https://github.com/amazonlinux/amazon-linux-2023" 71 SUPPORT_END="2028-03-01"`) 72 73 func TestDistributionScanner(t *testing.T) { 74 table := []struct { 75 name string 76 release Release 77 osRelease []byte 78 prettyDistName string 79 }{ 80 { 81 name: "AL1", 82 release: AmazonLinux1, 83 osRelease: AL1v201609OSRelease, 84 prettyDistName: "Amazon Linux AMI 2018.03", 85 }, 86 { 87 name: "AL1", 88 release: AmazonLinux1, 89 osRelease: AL1v201703OSRelease, 90 prettyDistName: "Amazon Linux AMI 2018.03", 91 }, 92 { 93 name: "AL1", 94 release: AmazonLinux1, 95 osRelease: AL1v201709OSRelease, 96 prettyDistName: "Amazon Linux AMI 2018.03", 97 }, 98 { 99 name: "AL1", 100 release: AmazonLinux1, 101 osRelease: AL1v201803OSRelease, 102 prettyDistName: "Amazon Linux AMI 2018.03", 103 }, 104 { 105 name: "AL2", 106 release: AmazonLinux2, 107 osRelease: AL2OSRelease, 108 prettyDistName: "Amazon Linux 2", 109 }, 110 { 111 name: "AL2023", 112 release: AmazonLinux2023, 113 osRelease: AL2023OSRelease, 114 prettyDistName: "Amazon Linux 2023", 115 }, 116 } 117 for _, tt := range table { 118 t.Run(tt.name, func(t *testing.T) { 119 scanner := DistributionScanner{} 120 dist := scanner.parse(bytes.NewBuffer(tt.osRelease)) 121 cmpDist := releaseToDist(tt.release) 122 if !cmp.Equal(dist, cmpDist) { 123 t.Fatalf("%v", cmp.Diff(dist, cmpDist)) 124 } 125 if !cmp.Equal(cmpDist.PrettyName, tt.prettyDistName) { 126 t.Fatalf("%v", cmp.Diff(tt.prettyDistName, cmpDist.PrettyName)) 127 } 128 }) 129 } 130 }