Skip to content

Commit

Permalink
test: add e2e discovery tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ansgarschulte committed Mar 19, 2024
1 parent 061538c commit 8daa8b1
Show file tree
Hide file tree
Showing 3 changed files with 203 additions and 4 deletions.
67 changes: 67 additions & 0 deletions e2e/integration_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
// SPDX-License-Identifier: MIT
// SPDX-FileCopyrightText: 2023 Steadybit GmbH

package e2e

import (
"context"
"github.com/rs/zerolog/log"
"github.com/steadybit/action-kit/go/action_kit_test/e2e"
"github.com/steadybit/discovery-kit/go/discovery_kit_api"
"github.com/steadybit/discovery-kit/go/discovery_kit_test/validate"
"github.com/steadybit/extension-kit/extlogging"
"github.com/steadybit/extension-prometheus/extinstance"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"testing"
"time"
)

func TestWithMinikube(t *testing.T) {
extlogging.InitZeroLog()

extFactory := e2e.HelmExtensionFactory{
Name: "extension-prometheus",
Port: 8087,
ExtraArgs: func(m *e2e.Minikube) []string {
return []string{
"--set", "logging.level=debug",
"--set", "extraEnv[0].name=STEADYBIT_EXTENSION_PROMETHEUS_INSTANCE_0_NAME",
"--set", "extraEnv[0].value=Test_Prometheus",
"--set", "extraEnv[1].name=STEADYBIT_EXTENSION_PROMETHEUS_INSTANCE_0_ORIGIN",
"--set", "extraEnv[1].value=http://host.minikube.internal",
}
},
}

e2e.WithDefaultMinikube(t, &extFactory, []e2e.WithMinikubeTestCase{
{
Name: "validate discovery",
Test: validateDiscovery,
},
{
Name: "target discovery",
Test: testDiscovery,
},
})
}

func validateDiscovery(t *testing.T, _ *e2e.Minikube, e *e2e.Extension) {
assert.NoError(t, validate.ValidateEndpointReferences("/", e.Client))
}

func testDiscovery(t *testing.T, _ *e2e.Minikube, e *e2e.Extension) {
log.Info().Msg("Starting testDiscovery")
ctx, cancel := context.WithTimeout(context.Background(), 60*time.Second)
defer cancel()

target, err := e2e.PollForTarget(ctx, e, extinstance.PrometheusInstanceTargetId, func(target discovery_kit_api.Target) bool {
log.Info().Msgf("Checking target: %v", target)
return e2e.HasAttribute(target, "prometheus.instance.name", "Test_Prometheus") && e2e.HasAttribute(target, "prometheus.instance.url", "http://host.minikube.internal")
})

require.NoError(t, err)
assert.Equal(t, target.TargetType, extinstance.PrometheusInstanceTargetId)
assert.Contains(t, target.Attributes, "prometheus.instance.name")
assert.Contains(t, target.Attributes, "prometheus.instance.url")
}
32 changes: 32 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,13 @@ require (
github.com/rs/zerolog v1.32.0
github.com/steadybit/action-kit/go/action_kit_api/v2 v2.9.0
github.com/steadybit/action-kit/go/action_kit_sdk v1.1.9
github.com/steadybit/action-kit/go/action_kit_test v1.2.9
github.com/steadybit/discovery-kit/go/discovery_kit_api v1.5.2
github.com/steadybit/discovery-kit/go/discovery_kit_commons v0.1.0
github.com/steadybit/discovery-kit/go/discovery_kit_sdk v1.0.6
github.com/steadybit/discovery-kit/go/discovery_kit_test v1.1.2
github.com/steadybit/extension-kit v1.8.14
github.com/steadybit/extension-newrelic v1.0.1
github.com/stretchr/testify v1.9.0
github.com/testcontainers/testcontainers-go v0.26.0
go.uber.org/automaxprocs v1.5.3
Expand All @@ -44,14 +47,22 @@ require (
github.com/docker/go-units v0.5.0 // indirect
github.com/elastic/go-sysinfo v1.13.1 // indirect
github.com/elastic/go-windows v1.0.0 // indirect
github.com/emicklei/go-restful/v3 v3.11.0 // indirect
github.com/getkin/kin-openapi v0.123.0 // indirect
github.com/go-logr/logr v1.3.0 // indirect
github.com/go-ole/go-ole v1.2.6 // indirect
github.com/go-openapi/jsonpointer v0.20.3 // indirect
github.com/go-openapi/jsonreference v0.20.2 // indirect
github.com/go-openapi/swag v0.22.10 // indirect
github.com/go-resty/resty/v2 v2.11.0 // indirect
github.com/godbus/dbus/v5 v5.1.0 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/google/gnostic-models v0.6.8 // indirect
github.com/google/gofuzz v1.2.0 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/gorilla/websocket v1.5.0 // indirect
github.com/imdario/mergo v0.3.16 // indirect
github.com/invopop/yaml v0.2.0 // indirect
github.com/joeshaw/multierror v0.0.0-20140124173710-69b34d4ec901 // indirect
github.com/josharian/intern v1.0.0 // indirect
Expand All @@ -63,12 +74,15 @@ require (
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/moby/patternmatcher v0.6.0 // indirect
github.com/moby/spdystream v0.2.0 // indirect
github.com/moby/sys/sequential v0.5.0 // indirect
github.com/moby/term v0.5.0 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 // indirect
github.com/morikuni/aec v1.0.0 // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/mxk/go-flowrate v0.0.0-20140419014527-cca7078d478f // indirect
github.com/oapi-codegen/runtime v1.1.1 // indirect
github.com/opencontainers/go-digest v1.0.0 // indirect
github.com/opencontainers/image-spec v1.1.0-rc5 // indirect
Expand All @@ -85,18 +99,36 @@ require (
github.com/shirou/gopsutil/v3 v3.23.10 // indirect
github.com/shoenig/go-m1cpu v0.1.6 // indirect
github.com/sirupsen/logrus v1.9.3 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/tklauser/go-sysconf v0.3.12 // indirect
github.com/tklauser/numcpus v0.6.1 // indirect
github.com/yalp/jsonpath v0.0.0-20180802001716-5cc68e5049a0 // indirect
github.com/yusufpapurcu/wmi v1.2.3 // indirect
github.com/zmwangx/debounce v1.0.0 // indirect
golang.org/x/exp v0.0.0-20240222234643-814bf88cf225 // indirect
golang.org/x/mod v0.15.0 // indirect
golang.org/x/net v0.22.0 // indirect
golang.org/x/oauth2 v0.18.0 // indirect
golang.org/x/sys v0.18.0 // indirect
golang.org/x/term v0.18.0 // indirect
golang.org/x/text v0.14.0 // indirect
golang.org/x/time v0.5.0 // indirect
golang.org/x/tools v0.18.0 // indirect
google.golang.org/appengine v1.6.8 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20230711160842-782d3b101e98 // indirect
google.golang.org/grpc v1.58.3 // indirect
google.golang.org/protobuf v1.33.0 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
howett.net/plist v0.0.0-20181124034731-591f970eefbb // indirect
k8s.io/api v0.29.1 // indirect
k8s.io/apimachinery v0.29.1 // indirect
k8s.io/client-go v0.29.1 // indirect
k8s.io/klog/v2 v2.110.1 // indirect
k8s.io/kube-openapi v0.0.0-20231010175941-2dd684a91f00 // indirect
k8s.io/utils v0.0.0-20240102154912-e7106e64919e // indirect
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.4.1 // indirect
sigs.k8s.io/yaml v1.3.0 // indirect
)
Loading

0 comments on commit 8daa8b1

Please sign in to comment.