Skip to content

Commit

Permalink
Adding more test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
ycombinator committed Dec 1, 2020
1 parent 4cb337f commit 672ee5e
Show file tree
Hide file tree
Showing 2 changed files with 598 additions and 29 deletions.
347 changes: 330 additions & 17 deletions metricbeat/module/logstash/node/data_xpack_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,30 +28,343 @@ import (
)

func TestMakeClusterToPipelinesMap(t *testing.T) {
pipelines := []logstash.PipelineState{
{
ID: "test_pipeline",
Graph: &logstash.GraphContainer{
Graph: &logstash.Graph{
Vertices: []map[string]interface{}{
{
"id": "vertex_1",
tests := map[string]struct {
pipelines []logstash.PipelineState
overrideClusterUUID string
expectedMap map[string][]logstash.PipelineState
}{
"no_vertex_cluster_id": {
pipelines: []logstash.PipelineState{
{
ID: "test_pipeline",
Graph: &logstash.GraphContainer{
Graph: &logstash.Graph{
Vertices: []map[string]interface{}{
{
"id": "vertex_1",
},
{
"id": "vertex_2",
},
{
"id": "vertex_3",
},
},
},
{
"id": "vertex_2",
},
},
},
overrideClusterUUID: "prod_cluster_id",
expectedMap: map[string][]logstash.PipelineState{
"prod_cluster_id": {
{
ID: "test_pipeline",
Graph: &logstash.GraphContainer{
Graph: &logstash.Graph{
Vertices: []map[string]interface{}{
{
"id": "vertex_1",
},
{
"id": "vertex_2",
},
{
"id": "vertex_3",
},
},
},
},
},
},
},
},
"one_vertex_cluster_id": {
pipelines: []logstash.PipelineState{
{
ID: "test_pipeline",
Graph: &logstash.GraphContainer{
Graph: &logstash.Graph{
Vertices: []map[string]interface{}{
{
"id": "vertex_1",
"cluster_uuid": "es_1",
},
{
"id": "vertex_2",
},
{
"id": "vertex_3",
},
},
},
},
},
},
overrideClusterUUID: "prod_cluster_id",
expectedMap: map[string][]logstash.PipelineState{
"prod_cluster_id": {
{
ID: "test_pipeline",
Graph: &logstash.GraphContainer{
Graph: &logstash.Graph{
Vertices: []map[string]interface{}{
{
"id": "vertex_1",
"cluster_uuid": "es_1",
},
{
"id": "vertex_2",
},
{
"id": "vertex_3",
},
},
},
},
},
},
"es_1": {
{
ID: "test_pipeline",
Graph: &logstash.GraphContainer{
Graph: &logstash.Graph{
Vertices: []map[string]interface{}{
{
"id": "vertex_1",
"cluster_uuid": "es_1",
},
{
"id": "vertex_2",
},
{
"id": "vertex_3",
},
},
},
},
},
},
},
},
"two_pipelines": {
pipelines: []logstash.PipelineState{
{
ID: "test_pipeline_1",
Graph: &logstash.GraphContainer{
Graph: &logstash.Graph{
Vertices: []map[string]interface{}{
{
"id": "vertex_1_1",
"cluster_uuid": "es_1",
},
{
"id": "vertex_1_2",
},
{
"id": "vertex_1_3",
},
},
},
},
},
{
ID: "test_pipeline_2",
Graph: &logstash.GraphContainer{
Graph: &logstash.Graph{
Vertices: []map[string]interface{}{
{
"id": "vertex_2_1",
},
{
"id": "vertex_2_2",
},
{
"id": "vertex_2_3",
},
},
},
},
},
},
overrideClusterUUID: "prod_cluster_id",
expectedMap: map[string][]logstash.PipelineState{
"prod_cluster_id": {
{
ID: "test_pipeline_1",
Graph: &logstash.GraphContainer{
Graph: &logstash.Graph{
Vertices: []map[string]interface{}{
{
"id": "vertex_1_1",
"cluster_uuid": "es_1",
},
{
"id": "vertex_1_2",
},
{
"id": "vertex_1_3",
},
},
},
},
{
"id": "vertex_3",
},
{
ID: "test_pipeline_2",
Graph: &logstash.GraphContainer{
Graph: &logstash.Graph{
Vertices: []map[string]interface{}{
{
"id": "vertex_2_1",
},
{
"id": "vertex_2_2",
},
{
"id": "vertex_2_3",
},
},
},
},
},
},
"es_1": {
{
ID: "test_pipeline_1",
Graph: &logstash.GraphContainer{
Graph: &logstash.Graph{
Vertices: []map[string]interface{}{
{
"id": "vertex_1_1",
"cluster_uuid": "es_1",
},
{
"id": "vertex_1_2",
},
{
"id": "vertex_1_3",
},
},
},
},
},
},
},
},
"no_override_cluster_id": {
pipelines: []logstash.PipelineState{
{
ID: "test_pipeline_1",
Graph: &logstash.GraphContainer{
Graph: &logstash.Graph{
Vertices: []map[string]interface{}{
{
"id": "vertex_1_1",
"cluster_uuid": "es_1",
},
{
"id": "vertex_1_2",
"cluster_uuid": "es_2",
},
{
"id": "vertex_1_3",
},
},
},
},
},
{
ID: "test_pipeline_2",
Graph: &logstash.GraphContainer{
Graph: &logstash.Graph{
Vertices: []map[string]interface{}{
{
"id": "vertex_2_1",
},
{
"id": "vertex_2_2",
},
{
"id": "vertex_2_3",
},
},
},
},
},
},
overrideClusterUUID: "",
expectedMap: map[string][]logstash.PipelineState{
"es_1": {
{
ID: "test_pipeline_1",
Graph: &logstash.GraphContainer{
Graph: &logstash.Graph{
Vertices: []map[string]interface{}{
{
"id": "vertex_1_1",
"cluster_uuid": "es_1",
},
{
"id": "vertex_1_2",
"cluster_uuid": "es_2",
},
{
"id": "vertex_1_3",
},
},
},
},
},
},
"es_2": {
{
ID: "test_pipeline_1",
Graph: &logstash.GraphContainer{
Graph: &logstash.Graph{
Vertices: []map[string]interface{}{
{
"id": "vertex_1_1",
"cluster_uuid": "es_1",
},
{
"id": "vertex_1_2",
"cluster_uuid": "es_2",
},
{
"id": "vertex_1_3",
},
},
},
},
},
},
"": {
{
ID: "test_pipeline_2",
Graph: &logstash.GraphContainer{
Graph: &logstash.Graph{
Vertices: []map[string]interface{}{
{
"id": "vertex_2_1",
},
{
"id": "vertex_2_2",
},
{
"id": "vertex_2_3",
},
},
},
},
},
},
},
},
}
m := makeClusterToPipelinesMap(pipelines, "prod_cluster_id")
require.Len(t, m, 1)
for clusterID, pipelines := range m {
require.Equal(t, "prod_cluster_id", clusterID)
require.Len(t, pipelines, 1)

for name, test := range tests {
t.Run(name, func(t *testing.T) {
actualMap := makeClusterToPipelinesMap(test.pipelines, test.overrideClusterUUID)
require.Equal(t, test.expectedMap, actualMap)
})
}
}
Loading

0 comments on commit 672ee5e

Please sign in to comment.