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

Commit

Permalink
grpc: add unit test for ListProcesses
Browse files Browse the repository at this point in the history
mockreaper and mockcontainer are used to implement TestListProcesses.
This patch increases a little the code coverage.

Signed-off-by: Julio Montes <julio.montes@intel.com>
  • Loading branch information
Julio Montes committed Apr 9, 2018
1 parent f00ec0d commit a2a806f
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions grpc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,3 +179,50 @@ func TestGetPIDIndex(t *testing.T) {
index = getPIDIndex(title)
assert.Equal(pidIndex, index)
}

func TestListProcesses(t *testing.T) {
containerID := "1"
assert := assert.New(t)
req := &pb.ListProcessesRequest{
ContainerId: containerID,
Format: "table",
Args: []string{"-ef"},
}

a := &agentGRPC{
sandbox: &sandbox{
containers: make(map[string]*container),
subreaper: &mockreaper{},
},
}
// getContainer should fail
r, err := a.ListProcesses(nil, req)
assert.Error(err)
assert.NotNil(r)

// should fail, unknown format
req.Format = "unknown"
a.sandbox.containers[containerID] = &container{
container: &mockContainer{
id: containerID,
processes: []int{1},
},
}
r, err = a.ListProcesses(nil, req)
assert.Error(err)
assert.NotNil(r)

// json format
req.Format = "json"
r, err = a.ListProcesses(nil, req)
assert.NoError(err)
assert.NotNil(r)
assert.NotEmpty(r.ProcessList)

// table format
req.Format = "table"
r, err = a.ListProcesses(nil, req)
assert.NoError(err)
assert.NotNil(r)
assert.NotEmpty(r.ProcessList)
}

0 comments on commit a2a806f

Please sign in to comment.