Skip to content

Commit

Permalink
Add unit test for PCI address parsing
Browse files Browse the repository at this point in the history
Signed-off-by: Vasiliy Ulyanov <[email protected]>
  • Loading branch information
vasiliy-ul committed Jan 8, 2021
1 parent a8e4890 commit f909e5d
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions pkg/util/hardware/hw_utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,4 +82,34 @@ var _ = Describe("Hardware utils test", func() {
Expect(vCPUs).To(Equal(int64(4)), "Expect vCPUs")
})
})

Context("parse PCI address", func() {
It("shoud return an array of PCI DBSF fields (domain, bus, slot, function) or an error for malformed address", func() {
testData := []struct {
addr string
expectation []string
}{
{"05EA:Fc:1d.6", []string{"05EA", "Fc", "1d", "6"}},
{"", nil},
{"invalid address", nil},
{" 05EA:Fc:1d.6", nil}, // leading symbol
{"05EA:Fc:1d.6 ", nil}, // trailing symbol
{"00Z0:00:1d.6", nil}, // invalid digit in domain
{"0000:z0:1d.6", nil}, // invalid digit in bus
{"0000:00:Zd.6", nil}, // invalid digit in slot
{"05EA:Fc:1d:6", nil}, // colon ':' instead of dot '.' after slot
{"0000:00:1d.9", nil}, // invalid function
}

for _, t := range testData {
res, err := ParsePciAddress(t.addr)
Expect(res).To(Equal(t.expectation))
if t.expectation == nil {
Expect(err).To(HaveOccurred())
} else {
Expect(err).ToNot(HaveOccurred())
}
}
})
})
})

0 comments on commit f909e5d

Please sign in to comment.