Skip to content
This repository has been archived by the owner on May 12, 2021. It is now read-only.

Commit

Permalink
Merge pull request #2828 from cmaf/unittest-virtcontainers-bridges
Browse files Browse the repository at this point in the history
virtcontainers: Add to bridges unit test
  • Loading branch information
amshinde authored Jul 17, 2020
2 parents 37c0ff5 + e71b05b commit 8de190d
Showing 1 changed file with 49 additions and 0 deletions.
49 changes: 49 additions & 0 deletions virtcontainers/types/bridges_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,55 @@ func testAddRemoveDevice(t *testing.T, b *Bridge) {
}
}

func TestAddressFormat(t *testing.T) {
assert := assert.New(t)

// successful cases for AddressFormat functions
var ccwbridge = NewBridge(CCW, "", make(map[uint32]string), 0)
format, err := ccwbridge.AddressFormatCCW("0")
assert.NoError(err)
assert.Equal(format, "fe.0.0", "Format string should be fe.0.0")
format, err = ccwbridge.AddressFormatCCWForVirtServer("0")
assert.NoError(err)
assert.Equal(format, "0.0.0", "Format string should be 0.0.0")

// failure cases for AddressFormat functions
var pcibridge = NewBridge(PCI, "", make(map[uint32]string), 0)
_, err = pcibridge.AddressFormatCCW("0")
assert.Error(err)
_, err = pcibridge.AddressFormatCCWForVirtServer("0")
assert.Error(err)

}

func TestNewBridge(t *testing.T) {
assert := assert.New(t)

var pci Type = "pci"
var pcie Type = "pcie"
var ccw Type = "ccw"
var maxDefaultCapacity uint32

var pcibridge = NewBridge(PCI, "", make(map[uint32]string), 0)
assert.Equal(pcibridge.Type, pci, "Type should be PCI")
assert.Equal(pcibridge.Devices, make(map[uint32]string), "Devices should be equal to make(map[uint32]string)")
assert.Equal(pcibridge.Addr, 0, "Address should be 0")

var pciebridge = NewBridge(PCIE, "", make(map[uint32]string), 0)
assert.Equal(pciebridge.Type, pcie, "Type should be PCIE")
assert.Equal(pciebridge.Devices, make(map[uint32]string), "Devices should be equal to make(map[uint32]string)")
assert.Equal(pciebridge.Addr, 0, "Address should be 0")

var ccwbridge = NewBridge(CCW, "", make(map[uint32]string), 0)
assert.Equal(ccwbridge.Type, ccw, "Type should be CCW")
assert.Equal(ccwbridge.Devices, make(map[uint32]string), "Devices should be equal to make(map[uint32]string)")
assert.Equal(ccwbridge.Addr, 0, "Address should be 0")

var defaultbridge = NewBridge("", "", make(map[uint32]string), 0)
assert.Empty(defaultbridge.Type)
assert.Equal(defaultbridge.MaxCapacity, maxDefaultCapacity, "MaxCapacity should be 0")
}

func TestAddRemoveDevicePCI(t *testing.T) {

// create a pci bridge
Expand Down

0 comments on commit 8de190d

Please sign in to comment.