github.com/quay/claircore@v1.5.28/suse/distributionscanner_test.go (about)

     1  package suse
     2  
     3  import (
     4  	"bytes"
     5  	"testing"
     6  
     7  	"github.com/google/go-cmp/cmp"
     8  )
     9  
    10  var enterpriseServer15OSRelease []byte = []byte(`NAME="SLES"
    11  VERSION="15-SP1"
    12  VERSION_ID="15.1"
    13  PRETTY_NAME="SUSE Linux Enterprise Server 15 SP1"
    14  ID="sles"
    15  ID_LIKE="suse"
    16  ANSI_COLOR="0;32"
    17  CPE_NAME="cpe:/o:suse:sles:15:sp1"`)
    18  
    19  var enterpriseServer12OSRelase []byte = []byte(`NAME="SLES"
    20  VERSION="12-SP5"
    21  VERSION_ID="12.5"
    22  PRETTY_NAME="SUSE Linux Enterprise Server 12 SP5"
    23  ID="sles"
    24  ANSI_COLOR="0;32"
    25  CPE_NAME="cpe:/o:suse:sles:12:sp5"`)
    26  
    27  var enterpriseServer11OSRelease []byte = []byte(`NAME="SLES"
    28  VERSION="11-SP5"
    29  VERSION_ID="11.2"
    30  PRETTY_NAME="SUSE Linux Enterprise Server 11 SP5"
    31  ID="sles"
    32  ANSI_COLOR="0;32"
    33  CPE_NAME="cpe:/o:suse:sles:12:sp5"`)
    34  
    35  var leap151OSRelease []byte = []byte(`NAME="openSUSE Leap"
    36  VERSION="15.1"
    37  ID="opensuse-leap"
    38  ID_LIKE="suse opensuse"
    39  VERSION_ID="15.1"
    40  PRETTY_NAME="openSUSE Leap 15.1"
    41  ANSI_COLOR="0;32"
    42  CPE_NAME="cpe:/o:opensuse:leap:15.1"
    43  BUG_REPORT_URL="https://bugs.opensuse.org"
    44  HOME_URL="https://www.opensuse.org/"`)
    45  
    46  var leap15OSRelease []byte = []byte(`NAME="openSUSE Leap"
    47  VERSION="15.0"
    48  ID="opensuse-leap"
    49  ID_LIKE="suse opensuse"
    50  VERSION_ID="15.0"
    51  PRETTY_NAME="openSUSE Leap 15.0"
    52  ANSI_COLOR="0;32"
    53  CPE_NAME="cpe:/o:opensuse:leap:15.0"
    54  BUG_REPORT_URL="https://bugs.opensuse.org"
    55  HOME_URL="https://www.opensuse.org/"`)
    56  
    57  var leap423OSRelease []byte = []byte(`NAME="openSUSE Leap"
    58  VERSION="42.3"
    59  ID=opensuse
    60  ID_LIKE="suse"
    61  VERSION_ID="42.3"
    62  PRETTY_NAME="openSUSE Leap 42.3"
    63  ANSI_COLOR="0;32"
    64  CPE_NAME="cpe:/o:opensuse:leap:42.3"
    65  BUG_REPORT_URL="https://bugs.opensuse.org"
    66  HOME_URL="https://www.opensuse.org/"`)
    67  
    68  func TestDistributionScanner(t *testing.T) {
    69  	table := []struct {
    70  		name      string
    71  		release   Release
    72  		osRelease []byte
    73  	}{
    74  		{
    75  			name:      "enterprise server 15",
    76  			release:   EnterpriseServer15,
    77  			osRelease: enterpriseServer15OSRelease,
    78  		},
    79  		{
    80  			name:      "enterprise server 12",
    81  			release:   EnterpriseServer12,
    82  			osRelease: enterpriseServer12OSRelase,
    83  		},
    84  		{
    85  			name:      "enterprise server 11",
    86  			release:   EnterpriseServer11,
    87  			osRelease: enterpriseServer11OSRelease,
    88  		},
    89  		{
    90  			name:      "leap 15.0",
    91  			release:   Leap150,
    92  			osRelease: leap15OSRelease,
    93  		},
    94  		{
    95  			name:      "leap 15.1",
    96  			release:   Leap151,
    97  			osRelease: leap151OSRelease,
    98  		},
    99  		{
   100  			name:      "leap 42.3",
   101  			release:   Leap423,
   102  			osRelease: leap423OSRelease,
   103  		},
   104  	}
   105  	for _, tt := range table {
   106  		t.Run(tt.name, func(t *testing.T) {
   107  			scanner := DistributionScanner{}
   108  			dist := scanner.parse(bytes.NewBuffer(tt.osRelease))
   109  			if !cmp.Equal(dist, releaseToDist(tt.release)) {
   110  				t.Fatalf("%v", cmp.Diff(dist, releaseToDist(tt.release)))
   111  			}
   112  		})
   113  	}
   114  }