Skip to content

Commit

Permalink
Fixing failed Indexers UT
Browse files Browse the repository at this point in the history
  • Loading branch information
vjsamuel committed Jan 12, 2018
1 parent 9123dcc commit 012f5a2
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
2 changes: 1 addition & 1 deletion libbeat/processors/add_kubernetes_metadata/indexers.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ func NewContainerIndexer(_ common.Config, metaGen kubernetes.MetaGenerator) (Ind
func (c *ContainerIndexer) GetMetadata(pod *kubernetes.Pod) []MetadataIndex {
var metadata []MetadataIndex
for _, status := range append(pod.Status.ContainerStatuses, pod.Status.InitContainerStatuses...) {
cID := status.ContainerID
cID := status.GetContainerID()
if cID == "" {
continue
}
Expand Down
16 changes: 14 additions & 2 deletions libbeat/processors/add_kubernetes_metadata/indexers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ func TestPodIndexer(t *testing.T) {
"labelkey": "labelvalue",
},
},
Spec: kubernetes.PodSpec{},
Spec: kubernetes.PodSpec{
NodeName: "testnode",
},
}

indexers := podIndexer.GetMetadata(&pod)
Expand All @@ -43,6 +45,9 @@ func TestPodIndexer(t *testing.T) {
"labels": common.MapStr{
"labelkey": "labelvalue",
},
"node": common.MapStr{
"name": "testnode",
},
}

assert.Equal(t, expected.String(), indexers[0].Data.String())
Expand Down Expand Up @@ -89,8 +94,11 @@ func TestContainerIndexer(t *testing.T) {
"labels": common.MapStr{
"labelkey": "labelvalue",
},
"node": common.MapStr{
"name": "testnode",
},
}

pod.Spec.NodeName = "testnode"
pod.Status.ContainerStatuses = []kubernetes.PodContainerStatus{
{
Name: container,
Expand Down Expand Up @@ -282,6 +290,9 @@ func TestIpPortIndexer(t *testing.T) {
"labels": common.MapStr{
"labelkey": "labelvalue",
},
"node": common.MapStr{
"name": "testnode",
},
}

pod.Spec.Containers = []kubernetes.Container{
Expand All @@ -295,6 +306,7 @@ func TestIpPortIndexer(t *testing.T) {
},
},
}
pod.Spec.NodeName = "testnode"

indexers = ipIndexer.GetMetadata(&pod)
assert.Equal(t, 2, len(indexers))
Expand Down

0 comments on commit 012f5a2

Please sign in to comment.