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 9e047b6 commit 7272690
Showing 1 changed file with 28 additions and 1 deletion.
29 changes: 28 additions & 1 deletion grpc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -664,12 +664,19 @@ func TestGetGuestDetails(t *testing.T) {
}

req := &pb.GuestDetailsRequest{
MemBlockSize: true,
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 7272690

Please sign in to comment.