Merge pull request #2135 from seans3/inventory-set

Fixed inventory Equal(), checking nil as passed parameter
This commit is contained in:
Jeff Regan
2020-01-23 10:06:58 -08:00
committed by GitHub
2 changed files with 15 additions and 0 deletions

View File

@@ -71,6 +71,9 @@ func parseInventory(inv string) (*Inventory, error) {
// Equals returns true if the Inventory structs are identical;
// false otherwise.
func (i *Inventory) Equals(other *Inventory) bool {
if other == nil {
return false
}
return i.String() == other.String()
}

View File

@@ -80,6 +80,18 @@ func TestInventoryEqual(t *testing.T) {
inventory2 *Inventory
isEqual bool
}{
// "Other" inventory is nil, then not equal.
{
inventory1: &Inventory{
Name: "test-inv",
GroupKind: schema.GroupKind{
Group: "apps",
Kind: "Deployment",
},
},
inventory2: nil,
isEqual: false,
},
// Two equal inventories without a namespace
{
inventory1: &Inventory{