github.com/openshift/installer@v1.4.17/pkg/types/baremetal/rootdevice_test.go (about)

     1  package baremetal
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/metal3-io/baremetal-operator/apis/metal3.io/v1alpha1"
     7  	"github.com/stretchr/testify/assert"
     8  )
     9  
    10  func TestMakeHintMap(t *testing.T) {
    11  	addressableTrue := true
    12  	addressableFalse := false
    13  
    14  	for _, tc := range []struct {
    15  		Scenario string
    16  		Hints    RootDeviceHints
    17  		Expected map[string]string
    18  	}{
    19  		{
    20  			Scenario: "device-name",
    21  			Hints: RootDeviceHints{
    22  				DeviceName: "userd_devicename",
    23  			},
    24  			Expected: map[string]string{
    25  				"name": "s== userd_devicename",
    26  			},
    27  		},
    28  		{
    29  			Scenario: "hctl",
    30  			Hints: RootDeviceHints{
    31  				HCTL: "1:2:3:4",
    32  			},
    33  			Expected: map[string]string{
    34  				"hctl": "s== 1:2:3:4",
    35  			},
    36  		},
    37  		{
    38  			Scenario: "model",
    39  			Hints: RootDeviceHints{
    40  				Model: "userd_model",
    41  			},
    42  			Expected: map[string]string{
    43  				"model": "<in> userd_model",
    44  			},
    45  		},
    46  		{
    47  			Scenario: "vendor",
    48  			Hints: RootDeviceHints{
    49  				Vendor: "userd_vendor",
    50  			},
    51  			Expected: map[string]string{
    52  				"vendor": "<in> userd_vendor",
    53  			},
    54  		},
    55  		{
    56  			Scenario: "serial-number",
    57  			Hints: RootDeviceHints{
    58  				SerialNumber: "userd_serial",
    59  			},
    60  			Expected: map[string]string{
    61  				"serial": "s== userd_serial",
    62  			},
    63  		},
    64  		{
    65  			Scenario: "min-size",
    66  			Hints: RootDeviceHints{
    67  				MinSizeGigabytes: 40,
    68  			},
    69  			Expected: map[string]string{
    70  				"size": ">= 40",
    71  			},
    72  		},
    73  		{
    74  			Scenario: "wwn",
    75  			Hints: RootDeviceHints{
    76  				WWN: "userd_wwn",
    77  			},
    78  			Expected: map[string]string{
    79  				"wwn": "s== userd_wwn",
    80  			},
    81  		},
    82  		{
    83  			Scenario: "wwn-with-extension",
    84  			Hints: RootDeviceHints{
    85  				WWNWithExtension: "userd_with_extension",
    86  			},
    87  			Expected: map[string]string{
    88  				"wwn_with_extension": "s== userd_with_extension",
    89  			},
    90  		},
    91  		{
    92  			Scenario: "wwn-extension",
    93  			Hints: RootDeviceHints{
    94  				WWNVendorExtension: "userd_vendor_extension",
    95  			},
    96  			Expected: map[string]string{
    97  				"wwn_vendor_extension": "s== userd_vendor_extension",
    98  			},
    99  		},
   100  		{
   101  			Scenario: "rotational-true",
   102  			Hints: RootDeviceHints{
   103  				Rotational: &addressableTrue,
   104  			},
   105  			Expected: map[string]string{
   106  				"rotational": "true",
   107  			},
   108  		},
   109  		{
   110  			Scenario: "rotational-false",
   111  			Hints: RootDeviceHints{
   112  				Rotational: &addressableFalse,
   113  			},
   114  			Expected: map[string]string{
   115  				"rotational": "false",
   116  			},
   117  		},
   118  		{
   119  			Scenario: "everything-bagel",
   120  			Hints: RootDeviceHints{
   121  				DeviceName:         "userd_devicename",
   122  				HCTL:               "1:2:3:4",
   123  				Model:              "userd_model",
   124  				Vendor:             "userd_vendor",
   125  				SerialNumber:       "userd_serial",
   126  				MinSizeGigabytes:   40,
   127  				WWN:                "userd_wwn",
   128  				WWNWithExtension:   "userd_with_extension",
   129  				WWNVendorExtension: "userd_vendor_extension",
   130  				Rotational:         &addressableTrue,
   131  			},
   132  			Expected: map[string]string{
   133  				"name":                 "s== userd_devicename",
   134  				"hctl":                 "s== 1:2:3:4",
   135  				"model":                "<in> userd_model",
   136  				"vendor":               "<in> userd_vendor",
   137  				"serial":               "s== userd_serial",
   138  				"size":                 ">= 40",
   139  				"wwn":                  "s== userd_wwn",
   140  				"wwn_with_extension":   "s== userd_with_extension",
   141  				"wwn_vendor_extension": "s== userd_vendor_extension",
   142  				"rotational":           "true",
   143  			},
   144  		},
   145  		{
   146  			Scenario: "empty",
   147  			Hints:    RootDeviceHints{},
   148  			Expected: map[string]string{},
   149  		},
   150  	} {
   151  		t.Run(tc.Scenario, func(t *testing.T) {
   152  			actual := tc.Hints.MakeHintMap()
   153  			assert.Equal(t, tc.Expected, actual, "hint map does not match")
   154  		})
   155  	}
   156  }
   157  
   158  func TestMakeCRDHints(t *testing.T) {
   159  	addressableTrue := true
   160  	addressableFalse := false
   161  
   162  	for _, tc := range []struct {
   163  		Scenario string
   164  		Hints    *RootDeviceHints
   165  		Expected *v1alpha1.RootDeviceHints
   166  	}{
   167  		{
   168  			Scenario: "nil",
   169  			Hints:    nil,
   170  			Expected: nil,
   171  		},
   172  		{
   173  			Scenario: "device-name",
   174  			Hints: &RootDeviceHints{
   175  				DeviceName: "userd_devicename",
   176  			},
   177  			Expected: &v1alpha1.RootDeviceHints{
   178  				DeviceName: "userd_devicename",
   179  			},
   180  		},
   181  		{
   182  			Scenario: "hctl",
   183  			Hints: &RootDeviceHints{
   184  				HCTL: "1:2:3:4",
   185  			},
   186  			Expected: &v1alpha1.RootDeviceHints{
   187  				HCTL: "1:2:3:4",
   188  			},
   189  		},
   190  		{
   191  			Scenario: "model",
   192  			Hints: &RootDeviceHints{
   193  				Model: "userd_model",
   194  			},
   195  			Expected: &v1alpha1.RootDeviceHints{
   196  				Model: "userd_model",
   197  			},
   198  		},
   199  		{
   200  			Scenario: "vendor",
   201  			Hints: &RootDeviceHints{
   202  				Vendor: "userd_vendor",
   203  			},
   204  			Expected: &v1alpha1.RootDeviceHints{
   205  				Vendor: "userd_vendor",
   206  			},
   207  		},
   208  		{
   209  			Scenario: "serial-number",
   210  			Hints: &RootDeviceHints{
   211  				SerialNumber: "userd_serial",
   212  			},
   213  			Expected: &v1alpha1.RootDeviceHints{
   214  				SerialNumber: "userd_serial",
   215  			},
   216  		},
   217  		{
   218  			Scenario: "min-size",
   219  			Hints: &RootDeviceHints{
   220  				MinSizeGigabytes: 40,
   221  			},
   222  			Expected: &v1alpha1.RootDeviceHints{
   223  				MinSizeGigabytes: 40,
   224  			},
   225  		},
   226  		{
   227  			Scenario: "wwn",
   228  			Hints: &RootDeviceHints{
   229  				WWN: "userd_wwn",
   230  			},
   231  			Expected: &v1alpha1.RootDeviceHints{
   232  				WWN: "userd_wwn",
   233  			},
   234  		},
   235  		{
   236  			Scenario: "wwn-with-extension",
   237  			Hints: &RootDeviceHints{
   238  				WWNWithExtension: "userd_with_extension",
   239  			},
   240  			Expected: &v1alpha1.RootDeviceHints{
   241  				WWNWithExtension: "userd_with_extension",
   242  			},
   243  		},
   244  		{
   245  			Scenario: "wwn-extension",
   246  			Hints: &RootDeviceHints{
   247  				WWNVendorExtension: "userd_vendor_extension",
   248  			},
   249  			Expected: &v1alpha1.RootDeviceHints{
   250  				WWNVendorExtension: "userd_vendor_extension",
   251  			},
   252  		},
   253  		{
   254  			Scenario: "rotational-true",
   255  			Hints: &RootDeviceHints{
   256  				Rotational: &addressableTrue,
   257  			},
   258  			Expected: &v1alpha1.RootDeviceHints{
   259  				Rotational: &addressableTrue,
   260  			},
   261  		},
   262  		{
   263  			Scenario: "rotational-false",
   264  			Hints: &RootDeviceHints{
   265  				Rotational: &addressableFalse,
   266  			},
   267  			Expected: &v1alpha1.RootDeviceHints{
   268  				Rotational: &addressableFalse,
   269  			},
   270  		},
   271  		{
   272  			Scenario: "everything-bagel",
   273  			Hints: &RootDeviceHints{
   274  				DeviceName:         "userd_devicename",
   275  				HCTL:               "1:2:3:4",
   276  				Model:              "userd_model",
   277  				Vendor:             "userd_vendor",
   278  				SerialNumber:       "userd_serial",
   279  				MinSizeGigabytes:   40,
   280  				WWN:                "userd_wwn",
   281  				WWNWithExtension:   "userd_with_extension",
   282  				WWNVendorExtension: "userd_vendor_extension",
   283  				Rotational:         &addressableTrue,
   284  			},
   285  			Expected: &v1alpha1.RootDeviceHints{
   286  				DeviceName:         "userd_devicename",
   287  				HCTL:               "1:2:3:4",
   288  				Model:              "userd_model",
   289  				Vendor:             "userd_vendor",
   290  				SerialNumber:       "userd_serial",
   291  				MinSizeGigabytes:   40,
   292  				WWN:                "userd_wwn",
   293  				WWNWithExtension:   "userd_with_extension",
   294  				WWNVendorExtension: "userd_vendor_extension",
   295  				Rotational:         &addressableTrue,
   296  			},
   297  		},
   298  		{
   299  			Scenario: "empty",
   300  			Hints:    &RootDeviceHints{},
   301  			Expected: &v1alpha1.RootDeviceHints{},
   302  		},
   303  	} {
   304  		t.Run(tc.Scenario, func(t *testing.T) {
   305  			actual := tc.Hints.MakeCRDHints()
   306  			assert.Equal(t, tc.Expected, actual, "hint map does not match")
   307  		})
   308  	}
   309  }