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

     1  package ubuntu
     2  
     3  import (
     4  	"os"
     5  	"path/filepath"
     6  	"testing"
     7  
     8  	"github.com/google/go-cmp/cmp"
     9  
    10  	"github.com/quay/claircore"
    11  )
    12  
    13  func TestDistributionScanner(t *testing.T) {
    14  	table := []struct {
    15  		Name string
    16  		Want *claircore.Distribution
    17  	}{
    18  		{
    19  			// This is a Debian distribution.
    20  			Name: "11",
    21  			Want: nil,
    22  		},
    23  		{
    24  			Name: "10.04",
    25  			Want: &claircore.Distribution{
    26  				Name:            "Ubuntu",
    27  				DID:             "ubuntu",
    28  				VersionID:       "10.04",
    29  				PrettyName:      "Ubuntu 10.04",
    30  				VersionCodeName: "lucid",
    31  				Version:         "10.04 (Lucid)",
    32  			},
    33  		},
    34  		{
    35  			Name: "12.04",
    36  			Want: &claircore.Distribution{
    37  				Name:            "Ubuntu",
    38  				DID:             "ubuntu",
    39  				VersionID:       "12.04",
    40  				PrettyName:      "Ubuntu 12.04",
    41  				VersionCodeName: "precise",
    42  				Version:         "12.04 (Precise)",
    43  			},
    44  		},
    45  		{
    46  			Name: "12.10",
    47  			Want: &claircore.Distribution{
    48  				Name:            "Ubuntu",
    49  				DID:             "ubuntu",
    50  				VersionID:       "12.10",
    51  				PrettyName:      "Ubuntu 12.10",
    52  				VersionCodeName: "quantal",
    53  				Version:         "12.10 (Quantal)",
    54  			},
    55  		},
    56  		{
    57  			Name: "13.04",
    58  			Want: &claircore.Distribution{
    59  				Name:            "Ubuntu",
    60  				DID:             "ubuntu",
    61  				VersionID:       "13.04",
    62  				PrettyName:      "Ubuntu 13.04",
    63  				VersionCodeName: "raring",
    64  				Version:         "13.04 (Raring)",
    65  			},
    66  		},
    67  		{
    68  			Name: "13.10",
    69  			Want: &claircore.Distribution{
    70  				Name:            "Ubuntu",
    71  				DID:             "ubuntu",
    72  				VersionID:       "13.10",
    73  				PrettyName:      "Ubuntu 13.10",
    74  				VersionCodeName: "saucy",
    75  				Version:         "13.10 (Saucy)",
    76  			},
    77  		},
    78  		{
    79  			Name: "14.04",
    80  			Want: &claircore.Distribution{
    81  				Name:            "Ubuntu",
    82  				DID:             "ubuntu",
    83  				VersionID:       "14.04",
    84  				PrettyName:      "Ubuntu 14.04",
    85  				VersionCodeName: "trusty",
    86  				Version:         "14.04 (Trusty)",
    87  			},
    88  		},
    89  		{
    90  			Name: "14.10",
    91  			Want: &claircore.Distribution{
    92  				Name:            "Ubuntu",
    93  				DID:             "ubuntu",
    94  				VersionID:       "14.10",
    95  				PrettyName:      "Ubuntu 14.10",
    96  				VersionCodeName: "utopic",
    97  				Version:         "14.10 (Utopic)",
    98  			},
    99  		},
   100  		{
   101  			Name: "15.04",
   102  			Want: &claircore.Distribution{
   103  				Name:            "Ubuntu",
   104  				DID:             "ubuntu",
   105  				VersionID:       "15.04",
   106  				PrettyName:      "Ubuntu 15.04",
   107  				VersionCodeName: "vivid",
   108  				Version:         "15.04 (Vivid)",
   109  			},
   110  		},
   111  		{
   112  			Name: "15.10",
   113  			Want: &claircore.Distribution{
   114  				Name:            "Ubuntu",
   115  				DID:             "ubuntu",
   116  				VersionID:       "15.10",
   117  				PrettyName:      "Ubuntu 15.10",
   118  				VersionCodeName: "wily",
   119  				Version:         "15.10 (Wily)",
   120  			},
   121  		},
   122  		{
   123  			Name: "16.04",
   124  			Want: &claircore.Distribution{
   125  				Name:            "Ubuntu",
   126  				DID:             "ubuntu",
   127  				VersionID:       "16.04",
   128  				PrettyName:      "Ubuntu 16.04",
   129  				VersionCodeName: "xenial",
   130  				Version:         "16.04 (Xenial)",
   131  			},
   132  		},
   133  		{
   134  			Name: "16.10",
   135  			Want: &claircore.Distribution{
   136  				Name:            "Ubuntu",
   137  				DID:             "ubuntu",
   138  				VersionID:       "16.10",
   139  				PrettyName:      "Ubuntu 16.10",
   140  				VersionCodeName: "yakkety",
   141  				Version:         "16.10 (Yakkety)",
   142  			},
   143  		},
   144  		{
   145  			Name: "17.04",
   146  			Want: &claircore.Distribution{
   147  				Name:            "Ubuntu",
   148  				DID:             "ubuntu",
   149  				VersionID:       "17.04",
   150  				PrettyName:      "Ubuntu 17.04",
   151  				VersionCodeName: "zesty",
   152  				Version:         "17.04 (Zesty)",
   153  			},
   154  		},
   155  		{
   156  			Name: "17.10",
   157  			Want: &claircore.Distribution{
   158  				Name:            "Ubuntu",
   159  				DID:             "ubuntu",
   160  				VersionID:       "17.10",
   161  				PrettyName:      "Ubuntu 17.10",
   162  				VersionCodeName: "artful",
   163  				Version:         "17.10 (Artful)",
   164  			},
   165  		},
   166  		{
   167  			Name: "18.04",
   168  			Want: &claircore.Distribution{
   169  				Name:            "Ubuntu",
   170  				DID:             "ubuntu",
   171  				VersionID:       "18.04",
   172  				PrettyName:      "Ubuntu 18.04",
   173  				VersionCodeName: "bionic",
   174  				Version:         "18.04 (Bionic)",
   175  			},
   176  		},
   177  		{
   178  			Name: "18.10",
   179  			Want: &claircore.Distribution{
   180  				Name:            "Ubuntu",
   181  				DID:             "ubuntu",
   182  				VersionID:       "18.10",
   183  				PrettyName:      "Ubuntu 18.10",
   184  				VersionCodeName: "cosmic",
   185  				Version:         "18.10 (Cosmic)",
   186  			},
   187  		},
   188  		{
   189  			Name: "19.04",
   190  			Want: &claircore.Distribution{
   191  				Name:            "Ubuntu",
   192  				DID:             "ubuntu",
   193  				VersionID:       "19.04",
   194  				PrettyName:      "Ubuntu 19.04",
   195  				VersionCodeName: "disco",
   196  				Version:         "19.04 (Disco)",
   197  			},
   198  		},
   199  		{
   200  			Name: "19.10",
   201  			Want: &claircore.Distribution{
   202  				Name:            "Ubuntu",
   203  				DID:             "ubuntu",
   204  				VersionID:       "19.10",
   205  				PrettyName:      "Ubuntu 19.10",
   206  				VersionCodeName: "eoan",
   207  				Version:         "19.10 (Eoan)",
   208  			},
   209  		},
   210  		{
   211  			Name: "20.04",
   212  			Want: &claircore.Distribution{
   213  				Name:            "Ubuntu",
   214  				DID:             "ubuntu",
   215  				VersionID:       "20.04",
   216  				PrettyName:      "Ubuntu 20.04",
   217  				VersionCodeName: "focal",
   218  				Version:         "20.04 (Focal)",
   219  			},
   220  		},
   221  		{
   222  			Name: "20.10",
   223  			Want: &claircore.Distribution{
   224  				Name:            "Ubuntu",
   225  				DID:             "ubuntu",
   226  				VersionID:       "20.10",
   227  				PrettyName:      "Ubuntu 20.10",
   228  				VersionCodeName: "groovy",
   229  				Version:         "20.10 (Groovy)",
   230  			},
   231  		},
   232  		{
   233  			Name: "21.04",
   234  			Want: &claircore.Distribution{
   235  				Name:            "Ubuntu",
   236  				DID:             "ubuntu",
   237  				VersionID:       "21.04",
   238  				PrettyName:      "Ubuntu 21.04",
   239  				VersionCodeName: "hirsute",
   240  				Version:         "21.04 (Hirsute)",
   241  			},
   242  		},
   243  		{
   244  			Name: "21.10",
   245  			Want: &claircore.Distribution{
   246  				Name:            "Ubuntu",
   247  				DID:             "ubuntu",
   248  				VersionID:       "21.10",
   249  				PrettyName:      "Ubuntu 21.10",
   250  				VersionCodeName: "impish",
   251  				Version:         "21.10 (Impish)",
   252  			},
   253  		},
   254  		{
   255  			Name: "22.04",
   256  			Want: &claircore.Distribution{
   257  				Name:            "Ubuntu",
   258  				DID:             "ubuntu",
   259  				VersionID:       "22.04",
   260  				PrettyName:      "Ubuntu 22.04",
   261  				VersionCodeName: "jammy",
   262  				Version:         "22.04 (Jammy)",
   263  			},
   264  		},
   265  		{
   266  			Name: "22.10",
   267  			Want: &claircore.Distribution{
   268  				Name:            "Ubuntu",
   269  				DID:             "ubuntu",
   270  				VersionID:       "22.10",
   271  				PrettyName:      "Ubuntu 22.10",
   272  				VersionCodeName: "kinetic",
   273  				Version:         "22.10 (Kinetic)",
   274  			},
   275  		},
   276  		{
   277  			Name: "23.04",
   278  			Want: &claircore.Distribution{
   279  				Name:            "Ubuntu",
   280  				DID:             "ubuntu",
   281  				VersionID:       "23.04",
   282  				PrettyName:      "Ubuntu 23.04",
   283  				VersionCodeName: "lunar",
   284  				Version:         "23.04 (Lunar)",
   285  			},
   286  		},
   287  		{
   288  			Name: "23.10",
   289  			Want: &claircore.Distribution{
   290  				Name:            "Ubuntu",
   291  				DID:             "ubuntu",
   292  				VersionID:       "23.10",
   293  				PrettyName:      "Ubuntu 23.10",
   294  				VersionCodeName: "mantic",
   295  				Version:         "23.10 (Mantic)",
   296  			},
   297  		},
   298  	}
   299  	todo := make(map[string]struct{})
   300  	ents, err := os.ReadDir("testdata/dist")
   301  	if err != nil {
   302  		t.Error(err)
   303  	}
   304  	for _, e := range ents {
   305  		if !e.IsDir() {
   306  			continue
   307  		}
   308  		todo[e.Name()] = struct{}{}
   309  	}
   310  	for _, tc := range table {
   311  		t.Run(tc.Name, func(t *testing.T) {
   312  			sys := os.DirFS(filepath.Join("testdata", "dist", tc.Name))
   313  			got, err := findDist(sys)
   314  			if err != nil {
   315  				t.Fatal(err)
   316  			}
   317  			if want := tc.Want; !cmp.Equal(got, want) {
   318  				t.Error(cmp.Diff(got, want))
   319  			}
   320  		})
   321  		delete(todo, tc.Name)
   322  	}
   323  	if len(todo) != 0 {
   324  		t.Errorf("missed directories: %v", todo)
   325  	}
   326  }