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

Commit

Permalink
agent: refine unit test for func GetGuestDetails
Browse files Browse the repository at this point in the history
since we add extra functionality in func GetGuestDetails for memory
hotplug via probe interface, we need to refine its related unit test.

Fixes: #442

Signed-off-by: Penny Zheng <[email protected]>
  • Loading branch information
Pennyzct committed Jan 23, 2019
1 parent a6f156c commit ee5b506
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions grpc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -665,11 +665,18 @@ func TestGetGuestDetails(t *testing.T) {

req := &pb.GuestDetailsRequest{
MemBlockSize: true,
MemHotplugProbe: true,
}

// sysfsMemoryBlockSizePath exist with error format
file, err := ioutil.TempFile("", "test")
assert.NoError(err)

oldsysfsMemoryBlockSizePath := sysfsMemoryBlockSizePath
defer func() {
sysfsMemoryBlockSizePath = oldsysfsMemoryBlockSizePath
}()

sysfsMemoryBlockSizePath = file.Name()
// empty
_, err = a.GetGuestDetails(context.TODO(), req)
Expand Down Expand Up @@ -699,6 +706,26 @@ func TestGetGuestDetails(t *testing.T) {
resp, err = a.GetGuestDetails(context.TODO(), req)
assert.NoError(err)
assert.Equal(resp.MemBlockSizeBytes, uint64(0))

// sysfsMemoryHotplugProbePath exist
probeFile, err := ioutil.TempFile("", "probe")
assert.NoError(err)

oldSysfsMemoryHotplugProbePath := sysfsMemoryHotplugProbePath
defer func() {
sysfsMemoryHotplugProbePath = oldSysfsMemoryHotplugProbePath
}()

sysfsMemoryHotplugProbePath = probeFile.Name()
resp, err = a.GetGuestDetails(context.TODO(), req)
assert.NoError(err)
assert.Equal(resp.SupportMemHotplugProbe, true)

// sysfsMemoryHotplugProbePath does not exist
os.Remove(sysfsMemoryHotplugProbePath)
resp, err = a.GetGuestDetails(context.TODO(), req)
assert.NoError(err)
assert.Equal(resp.SupportMemHotplugProbe, false)
}

func TestGetAgentDetails(t *testing.T) {
Expand Down

0 comments on commit ee5b506

Please sign in to comment.