mirror of
https://github.com/k8snetworkplumbingwg/multus-cni.git
synced 2025-08-31 16:38:43 +00:00
Improved coverage of checkpoint.go to 96.4%
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package checkpoint
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
. "github.com/onsi/ginkgo"
|
||||
@@ -104,6 +105,21 @@ var _ = Describe("Kubelet checkpoint data read operations", func() {
|
||||
resourceMap = rmap
|
||||
})
|
||||
|
||||
// It("should return a ResourceMap instance", func() {
|
||||
// podUID := k8sTypes.UID("970a395d-bb3b-11e8-89df-408d5c537d23")
|
||||
// fakePod := &v1.Pod{
|
||||
// ObjectMeta: metav1.ObjectMeta{
|
||||
// Name: "fakePod",
|
||||
// Namespace: "podNamespace",
|
||||
// UID: podUID,
|
||||
// },
|
||||
// }
|
||||
// rmap, err := cp.GetPodResourceMap(fakePod)
|
||||
// Expect(err).NotTo(HaveOccurred())
|
||||
// Expect(rmap).NotTo(BeEmpty())
|
||||
// resourceMap = rmap
|
||||
// })
|
||||
|
||||
It("resourceMap should have value for \"intel.com/sriov_net_A\"", func() {
|
||||
rInfo, ok := resourceMap[resourceAnnot]
|
||||
Expect(ok).To(BeTrue())
|
||||
@@ -122,6 +138,87 @@ var _ = Describe("Kubelet checkpoint data read operations", func() {
|
||||
Expect(resourceInfo.DeviceIDs[1]).To(BeEquivalentTo("0000:03:02.0"))
|
||||
})
|
||||
})
|
||||
|
||||
Context("Using faulty or incompatible information", func() {
|
||||
var (
|
||||
cp types.ResourceClient
|
||||
err error
|
||||
// resourceMap map[string]*types.ResourceInfo
|
||||
// resourceInfo *types.ResourceInfo
|
||||
// resourceAnnot = "intel.com/sriov_net_A"
|
||||
)
|
||||
|
||||
It("should not get a Checkpoint instance from file given bad filepath", func() {
|
||||
_, err = getCheckpoint("invalid/file/path")
|
||||
Expect(err).To(HaveOccurred())
|
||||
})
|
||||
|
||||
It("should not get a Checkpoint instance from file given bad json", func() {
|
||||
sampleData := `{
|
||||
"Data": {
|
||||
"PodDeviceEntries": [
|
||||
{
|
||||
"PodUID": "970a395d-bb3b-11e8-89df-408d5c537d23",
|
||||
"ContainerName": "appcntr1",
|
||||
"ResourceName": "intel.com/sriov_net_A",
|
||||
"DeviceIDs": [
|
||||
"0000:03:02.3",
|
||||
"0000:03:02.0"
|
||||
],
|
||||
"AllocResp": "CikKC3NyaW92X25ldF9BEhogMDAwMDowMzowMi4zIDAwMDA6MDM6MDIuMA=="
|
||||
}
|
||||
],
|
||||
"RegisteredDevices": {
|
||||
"intel.com/sriov_net_A": [
|
||||
"0000:03:02.1",
|
||||
"0000:03:02.2",
|
||||
"0000:03:02.3",
|
||||
"0000:03:02.0"
|
||||
],
|
||||
"intel.com/sriov_net_B": [
|
||||
"0000:03:06.3",
|
||||
"0000:03:06.0",
|
||||
"0000:03:06.1",
|
||||
"0000:03:06.2"
|
||||
]
|
||||
}
|
||||
},
|
||||
"Checksum": 229855270
|
||||
}`
|
||||
|
||||
//missing a close bracket
|
||||
badSampleData := `BAD BAD DATA`
|
||||
|
||||
fakeCheckpoint := &fakeCheckpoint{fileName: fakeTempFile}
|
||||
fakeCheckpoint.WriteToFile([]byte(badSampleData))
|
||||
_, err = getCheckpoint(fakeTempFile)
|
||||
Expect(err).To(HaveOccurred())
|
||||
fakeCheckpoint.WriteToFile([]byte(sampleData)) // do i need to rewrite the good data?
|
||||
})
|
||||
|
||||
It("should not return a ResourceMap instance", func() {
|
||||
cp, err = getCheckpoint(fakeTempFile)
|
||||
podUID := k8sTypes.UID("")
|
||||
fakePod := &v1.Pod{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: "fakePod",
|
||||
Namespace: "podNamespace",
|
||||
UID: podUID,
|
||||
},
|
||||
}
|
||||
fmt.Println("fakePod-podID: ", fakePod.UID)
|
||||
rmap, err := cp.GetPodResourceMap(fakePod)
|
||||
Expect(err).To(HaveOccurred())
|
||||
Expect(rmap).To(BeEmpty())
|
||||
// resourceMap = rmap
|
||||
})
|
||||
})
|
||||
|
||||
It("Check public GetCheckpoint for basic functionality", func() {
|
||||
cp, err := GetCheckpoint()
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(cp).To(Equal(&checkpoint{fileName: checkPointfile}))
|
||||
})
|
||||
})
|
||||
|
||||
var _ = AfterSuite(func() {
|
||||
|
Reference in New Issue
Block a user