tests for new Identify distro func

Signed-off-by: Alfredo Deza <adeza@anchore.com>
This commit is contained in:
Alfredo Deza 2020-07-17 13:07:14 -04:00
parent e2b71184aa
commit 0534a68ec6
4 changed files with 71 additions and 0 deletions

View file

@ -5,8 +5,50 @@ import (
"io/ioutil"
"os"
"testing"
"github.com/anchore/imgbom/imgbom/scope"
)
func TestIdentifyDistro(t *testing.T) {
tests := []struct {
fixture string
name string
RawVersion string
Type Type
}{
{
fixture: "test-fixtures/os/ubuntu-20.04",
name: "ubuntu",
Type: Ubuntu,
},
{
fixture: "test-fixtures/os/empty",
name: "No OS files",
Type: UnknownDistro,
},
{
fixture: "test-fixtures/os/unmatchable",
name: "Unmatchable distro",
Type: UnknownDistro,
},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
s, err := scope.NewScopeFromDir(test.fixture, scope.AllLayersScope)
if err != nil {
t.Fatalf("unable to produce a new scope for testing: %s", test.fixture)
}
distro := Identify(s)
if distro.Type != test.Type {
t.Errorf("expected distro doesn't match: %v != %v", distro.Type, test.Type)
}
})
}
}
func TestParseOsRelease(t *testing.T) {
tests := []struct {

View file

@ -0,0 +1,12 @@
NAME="Ubuntu"
VERSION="20.04 LTS (Focal Fossa)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 20.04 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

View file

@ -0,0 +1,17 @@
NAME="Scientific Linux"
VERSION="16 (Core)"
ID="scientific"
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"