Skip to content

Commit

Permalink
fix: test
Browse files Browse the repository at this point in the history
Signed-off-by: Bence Csati <[email protected]>
  • Loading branch information
csatib02 committed Dec 13, 2024
1 parent 4500227 commit 65d67fb
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 54 deletions.
2 changes: 0 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ require (
github.com/onsi/gomega v1.36.0
github.com/open-telemetry/opentelemetry-operator v0.114.0
github.com/prometheus/client_golang v1.20.5
github.com/siliconbrain/go-mapseqs v0.4.0
github.com/siliconbrain/go-seqs v0.13.0
github.com/stretchr/testify v1.10.0
go.opentelemetry.io/collector/component v0.115.0
go.opentelemetry.io/collector/config/configauth v0.115.0
Expand Down
4 changes: 0 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -308,10 +308,6 @@ github.com/scaleway/scaleway-sdk-go v1.0.0-beta.30 h1:yoKAVkEVwAqbGbR8n87rHQ1dul
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.30/go.mod h1:sH0u6fq6x4R5M7WxkoQFY/o7UaiItec0o1LinLCJNq8=
github.com/shirou/gopsutil/v4 v4.24.11 h1:WaU9xqGFKvFfsUv94SXcUPD7rCkU0vr/asVdQOBZNj8=
github.com/shirou/gopsutil/v4 v4.24.11/go.mod h1:s4D/wg+ag4rG0WO7AiTj2BeYCRhym0vM7DHbZRxnIT8=
github.com/siliconbrain/go-mapseqs v0.4.0 h1:r5GL26cEOiCtGHIVu1EIDMT1iQI5zNYZMoDjeoeRf+I=
github.com/siliconbrain/go-mapseqs v0.4.0/go.mod h1:WtBy7yxv/TS3Vc/WCro59kuYdRTqUnEr8OkgC9Rkllg=
github.com/siliconbrain/go-seqs v0.13.0 h1:3xvOlPDs4FB/XZzmagMU/DTTbHhLcEVPsjauKHsT990=
github.com/siliconbrain/go-seqs v0.13.0/go.mod h1:8kptI0u8epC1dPx/nCo3fUM2xJnfAoo59/UJiCsxkR4=
github.com/spf13/cast v1.7.0 h1:ntdiHjuueXFgm5nzDRdOS4yfT43P5Fnud6DH50rz/7w=
github.com/spf13/cast v1.7.0/go.mod h1:ancEpBxwJDODSW/UG4rDrAqiKolqNNh2DX3mk86cAdo=
github.com/spf13/cobra v1.8.1 h1:e5/vxKd/rZsfSJMUX1agtjeTDf+qv1/JdBF8gg5k9ZM=
Expand Down
79 changes: 31 additions & 48 deletions internal/controller/telemetry/otel_conf_gen/otel_conf_gen_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,12 @@ package otel_conf_gen
import (
"context"
_ "embed"
"encoding/json"
"reflect"
"testing"
"time"

"github.com/google/go-cmp/cmp"
otelv1beta1 "github.com/open-telemetry/opentelemetry-operator/apis/v1beta1"
"github.com/siliconbrain/go-mapseqs/mapseqs"
"github.com/siliconbrain/go-seqs/seqs"
"github.com/stretchr/testify/assert"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down Expand Up @@ -62,6 +59,9 @@ func TestOtelColConfComplex(t *testing.T) {
},
},
},
Status: v1alpha1.SubscriptionStatus{
Tenant: "example-tenant-a",
},
},
{Name: "subscription-example-2", Namespace: "example-tenant-a-ns"}: {
ObjectMeta: metav1.ObjectMeta{
Expand All @@ -77,6 +77,9 @@ func TestOtelColConfComplex(t *testing.T) {
},
},
},
Status: v1alpha1.SubscriptionStatus{
Tenant: "example-tenant-a",
},
},
{Name: "subscription-example-3", Namespace: "example-tenant-b-ns"}: {
ObjectMeta: metav1.ObjectMeta{
Expand All @@ -96,6 +99,9 @@ func TestOtelColConfComplex(t *testing.T) {
},
},
},
Status: v1alpha1.SubscriptionStatus{
Tenant: "example-tenant-b",
},
},
}
inputCfg := OtelColConfigInput{
Expand Down Expand Up @@ -129,6 +135,16 @@ func TestOtelColConfComplex(t *testing.T) {
LogSourceNamespaces: []string{
"example-tenant-a",
},
Subscriptions: []v1alpha1.NamespacedName{
{
Namespace: "example-tenant-a-ns",
Name: "subscription-example-1",
},
{
Namespace: "example-tenant-a-ns",
Name: "subscription-example-2",
},
},
},
},
{
Expand Down Expand Up @@ -158,25 +174,10 @@ func TestOtelColConfComplex(t *testing.T) {
LogSourceNamespaces: []string{
"example-tenant-b",
},
},
},
{
ObjectMeta: metav1.ObjectMeta{
Name: "example-tenant-a",
},
Spec: v1alpha1.TenantSpec{
SubscriptionNamespaceSelectors: []metav1.LabelSelector{
{
MatchLabels: map[string]string{
"nsSelector": "example-tenant-a",
},
},
},
LogSourceNamespaceSelectors: []metav1.LabelSelector{
Subscriptions: []v1alpha1.NamespacedName{
{
MatchLabels: map[string]string{
"nsSelector": "example-tenant-a",
},
Namespace: "example-tenant-b-ns",
Name: "subscription-example-3",
},
},
},
Expand Down Expand Up @@ -253,7 +254,7 @@ func TestOtelColConfComplex(t *testing.T) {
Spec: v1alpha1.OutputSpec{
OTLPHTTP: &v1alpha1.OTLPHTTP{
HTTPClientConfig: v1alpha1.HTTPClientConfig{
Endpoint: utils.ToPtr[string]("loki.example-tenant-a-ns.svc.cluster.local:4317"),
Endpoint: utils.ToPtr("loki.example-tenant-a-ns.svc.cluster.local:4317"),
TLSSetting: &v1alpha1.TLSClientSetting{
Insecure: true,
},
Expand Down Expand Up @@ -291,42 +292,24 @@ func TestOtelColConfComplex(t *testing.T) {
},
}

// TODO extract this logic

subscriptionOutputMap := map[v1alpha1.NamespacedName][]v1alpha1.NamespacedName{}
inputCfg.SubscriptionOutputMap = make(map[v1alpha1.NamespacedName][]v1alpha1.NamespacedName)
for _, subscription := range inputCfg.Subscriptions {
subscriptionOutputMap[subscription.NamespacedName()] = subscription.Spec.Outputs
inputCfg.SubscriptionOutputMap[subscription.NamespacedName()] = subscription.Spec.Outputs
}
inputCfg.SubscriptionOutputMap = subscriptionOutputMap

inputCfg.TenantSubscriptionMap = map[string][]v1alpha1.NamespacedName{}
tenantA := inputCfg.Tenants[0]
tenantASubscriptions := make(map[v1alpha1.NamespacedName]v1alpha1.Subscription)
for subName, sub := range inputCfg.Subscriptions {
if subName.Namespace != "example-tenant-b-ns" {
tenantASubscriptions[subName] = sub
inputCfg.TenantSubscriptionMap = make(map[string][]v1alpha1.NamespacedName)
for _, tenant := range inputCfg.Tenants {
for _, subscription := range inputCfg.Subscriptions {
if subscription.Status.Tenant == tenant.Name {
inputCfg.TenantSubscriptionMap[tenant.Name] = append(inputCfg.TenantSubscriptionMap[tenant.Name], subscription.NamespacedName())
}
}
}
inputCfg.TenantSubscriptionMap[tenantA.Name] = seqs.ToSlice(mapseqs.KeysOf(tenantASubscriptions))

tenantB := inputCfg.Tenants[1]
inputCfg.TenantSubscriptionMap[tenantB.Name] = []v1alpha1.NamespacedName{
{
Name: "subscription-example-3",
Namespace: "example-tenant-b-ns",
},
}

// Config

// The receiver and exporter entries are not serialized because of tags on the underlying data structure. The tests won't contain them, this is a known issue.
generatedConfig, _ := inputCfg.AssembleConfig(context.TODO())
actualJSONBytes, err1 := json.Marshal(generatedConfig)
if err1 != nil {
t.Fatalf("error %v", err1)

}
print(actualJSONBytes)
actualYAMLBytes, err := yaml.Marshal(generatedConfig)
if err != nil {
t.Fatalf("error %v", err)
Expand Down

0 comments on commit 65d67fb

Please sign in to comment.