forked from elastic/beats
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add basic cloudfoundry integration tests (elastic#19018)
- Loading branch information
1 parent
60ccaa5
commit b80c1e3
Showing
6 changed files
with
259 additions
and
0 deletions.
There are no files selected for viewing
75 changes: 75 additions & 0 deletions
75
x-pack/filebeat/input/cloudfoundry/input_integration_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
// or more contributor license agreements. Licensed under the Elastic License; | ||
// you may not use this file except in compliance with the Elastic License. | ||
|
||
// +build integration | ||
// +build cloudfoundry | ||
|
||
package cloudfoundry | ||
|
||
import ( | ||
"testing" | ||
"time" | ||
|
||
"github.com/stretchr/testify/require" | ||
|
||
"github.com/elastic/beats/v7/filebeat/channel" | ||
"github.com/elastic/beats/v7/filebeat/input" | ||
"github.com/elastic/beats/v7/libbeat/beat" | ||
"github.com/elastic/beats/v7/libbeat/common" | ||
cftest "github.com/elastic/beats/v7/x-pack/libbeat/common/cloudfoundry/test" | ||
) | ||
|
||
func TestInput(t *testing.T) { | ||
config := common.MustNewConfigFrom(cftest.GetConfigFromEnv(t)) | ||
|
||
events := make(chan beat.Event) | ||
connector := channel.ConnectorFunc(func(*common.Config, beat.ClientConfig) (channel.Outleter, error) { | ||
return newOutleter(events), nil | ||
}) | ||
|
||
inputCtx := input.Context{Done: make(chan struct{})} | ||
|
||
input, err := NewInput(config, connector, inputCtx) | ||
require.NoError(t, err) | ||
|
||
go input.Run() | ||
defer input.Stop() | ||
|
||
select { | ||
case e := <-events: | ||
t.Logf("Event received: %+v", e) | ||
case <-time.After(10 * time.Second): | ||
t.Fatal("timeout waiting for events") | ||
} | ||
} | ||
|
||
type outleter struct { | ||
events chan<- beat.Event | ||
done chan struct{} | ||
} | ||
|
||
func newOutleter(events chan<- beat.Event) *outleter { | ||
return &outleter{ | ||
events: events, | ||
done: make(chan struct{}), | ||
} | ||
} | ||
|
||
func (o *outleter) Close() error { | ||
close(o.done) | ||
return nil | ||
} | ||
|
||
func (o *outleter) Done() <-chan struct{} { | ||
return o.done | ||
} | ||
|
||
func (o *outleter) OnEvent(e beat.Event) bool { | ||
select { | ||
case o.events <- e: | ||
return true | ||
default: | ||
return false | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
// or more contributor license agreements. Licensed under the Elastic License; | ||
// you may not use this file except in compliance with the Elastic License. | ||
|
||
package test | ||
|
||
import ( | ||
"os" | ||
"testing" | ||
) | ||
|
||
func GetConfigFromEnv(t *testing.T) map[string]interface{} { | ||
t.Helper() | ||
|
||
config := map[string]interface{}{ | ||
"api_address": lookupEnv(t, "CLOUDFOUNDRY_API_ADDRESS"), | ||
"client_id": lookupEnv(t, "CLOUDFOUNDRY_CLIENT_ID"), | ||
"client_secret": lookupEnv(t, "CLOUDFOUNDRY_CLIENT_SECRET"), | ||
|
||
"ssl.verification_mode": "none", | ||
} | ||
|
||
optionalConfig(config, "uaa_address", "CLOUDFOUNDRY_UAA_ADDRESS") | ||
optionalConfig(config, "rlp_address", "CLOUDFOUNDRY_RLP_ADDRESS") | ||
optionalConfig(config, "doppler_address", "CLOUDFOUNDRY_DOPPLER_ADDRESS") | ||
|
||
if t.Failed() { | ||
t.FailNow() | ||
} | ||
|
||
return config | ||
} | ||
|
||
func lookupEnv(t *testing.T, name string) string { | ||
value, ok := os.LookupEnv(name) | ||
if !ok { | ||
t.Errorf("Environment variable %s is not set", name) | ||
} | ||
return value | ||
} | ||
|
||
func optionalConfig(config map[string]interface{}, key string, envVar string) { | ||
if value, ok := os.LookupEnv(envVar); ok { | ||
config[key] = value | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
x-pack/metricbeat/module/cloudfoundry/container/container_integration_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
// or more contributor license agreements. Licensed under the Elastic License; | ||
// you may not use this file except in compliance with the Elastic License. | ||
|
||
// +build integration | ||
// +build cloudfoundry | ||
|
||
package container | ||
|
||
import ( | ||
"testing" | ||
"time" | ||
|
||
"github.com/stretchr/testify/require" | ||
|
||
mbtest "github.com/elastic/beats/v7/metricbeat/mb/testing" | ||
"github.com/elastic/beats/v7/x-pack/metricbeat/module/cloudfoundry/mtest" | ||
) | ||
|
||
func TestFetch(t *testing.T) { | ||
config := mtest.GetConfig(t, "container") | ||
|
||
ms := mbtest.NewPushMetricSetV2(t, config) | ||
events := mbtest.RunPushMetricSetV2(60*time.Second, 1, ms) | ||
|
||
require.NotEmpty(t, events) | ||
} | ||
|
||
func TestData(t *testing.T) { | ||
config := mtest.GetConfig(t, "container") | ||
|
||
ms := mbtest.NewPushMetricSetV2(t, config) | ||
events := mbtest.RunPushMetricSetV2(60*time.Second, 1, ms) | ||
|
||
require.NotEmpty(t, events) | ||
|
||
beatEvent := mbtest.StandardizeEvent(ms, events[0]) | ||
mbtest.WriteEventToDataJSON(t, beatEvent, "") | ||
} |
39 changes: 39 additions & 0 deletions
39
x-pack/metricbeat/module/cloudfoundry/counter/counter_integration_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
// or more contributor license agreements. Licensed under the Elastic License; | ||
// you may not use this file except in compliance with the Elastic License. | ||
|
||
// +build integration | ||
// +build cloudfoundry | ||
|
||
package counter | ||
|
||
import ( | ||
"testing" | ||
"time" | ||
|
||
"github.com/stretchr/testify/require" | ||
|
||
mbtest "github.com/elastic/beats/v7/metricbeat/mb/testing" | ||
"github.com/elastic/beats/v7/x-pack/metricbeat/module/cloudfoundry/mtest" | ||
) | ||
|
||
func TestFetch(t *testing.T) { | ||
config := mtest.GetConfig(t, "counter") | ||
|
||
ms := mbtest.NewPushMetricSetV2(t, config) | ||
events := mbtest.RunPushMetricSetV2(10*time.Second, 1, ms) | ||
|
||
require.NotEmpty(t, events) | ||
} | ||
|
||
func TestData(t *testing.T) { | ||
config := mtest.GetConfig(t, "counter") | ||
|
||
ms := mbtest.NewPushMetricSetV2(t, config) | ||
events := mbtest.RunPushMetricSetV2(10*time.Second, 1, ms) | ||
|
||
require.NotEmpty(t, events) | ||
|
||
beatEvent := mbtest.StandardizeEvent(ms, events[0]) | ||
mbtest.WriteEventToDataJSON(t, beatEvent, "") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
// or more contributor license agreements. Licensed under the Elastic License; | ||
// you may not use this file except in compliance with the Elastic License. | ||
|
||
package mtest | ||
|
||
import ( | ||
"testing" | ||
|
||
cftest "github.com/elastic/beats/v7/x-pack/libbeat/common/cloudfoundry/test" | ||
) | ||
|
||
func GetConfig(t *testing.T, metricset string) map[string]interface{} { | ||
t.Helper() | ||
|
||
config := cftest.GetConfigFromEnv(t) | ||
config["module"] = "cloudfoundry" | ||
config["metricsets"] = []string{metricset} | ||
|
||
return config | ||
} |
39 changes: 39 additions & 0 deletions
39
x-pack/metricbeat/module/cloudfoundry/value/value_integration_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
// or more contributor license agreements. Licensed under the Elastic License; | ||
// you may not use this file except in compliance with the Elastic License. | ||
|
||
// +build integration | ||
// +build cloudfoundry | ||
|
||
package value | ||
|
||
import ( | ||
"testing" | ||
"time" | ||
|
||
"github.com/stretchr/testify/require" | ||
|
||
mbtest "github.com/elastic/beats/v7/metricbeat/mb/testing" | ||
"github.com/elastic/beats/v7/x-pack/metricbeat/module/cloudfoundry/mtest" | ||
) | ||
|
||
func TestFetch(t *testing.T) { | ||
config := mtest.GetConfig(t, "value") | ||
|
||
ms := mbtest.NewPushMetricSetV2(t, config) | ||
events := mbtest.RunPushMetricSetV2(10*time.Second, 1, ms) | ||
|
||
require.NotEmpty(t, events) | ||
} | ||
|
||
func TestData(t *testing.T) { | ||
config := mtest.GetConfig(t, "value") | ||
|
||
ms := mbtest.NewPushMetricSetV2(t, config) | ||
events := mbtest.RunPushMetricSetV2(10*time.Second, 1, ms) | ||
|
||
require.NotEmpty(t, events) | ||
|
||
beatEvent := mbtest.StandardizeEvent(ms, events[0]) | ||
mbtest.WriteEventToDataJSON(t, beatEvent, "") | ||
} |