Skip to content

Commit

Permalink
Add tests for generated code
Browse files Browse the repository at this point in the history
  • Loading branch information
pleshakov committed Mar 7, 2024
1 parent cd4a28c commit da0b5d2
Showing 1 changed file with 96 additions and 0 deletions.
96 changes: 96 additions & 0 deletions internal/mode/static/telemetry/data_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
package telemetry

import (
"testing"

tel "github.com/nginxinc/telemetry-exporter/pkg/telemetry"
. "github.com/onsi/gomega"
"go.opentelemetry.io/otel/attribute"
)

func TestDataAttributes(t *testing.T) {
data := Data{
ImageSource: "local",
Data: tel.Data{
ProjectName: "NGF",
ProjectVersion: "edge",
ProjectArchitecture: "arm64",
ClusterID: "1",
ClusterVersion: "1.23",
ClusterPlatform: "test",
InstallationID: "123",
ClusterNodeCount: 3,
},
FlagNames: []string{"test-flag"},
FlagValues: []string{"test-value"},
NGFResourceCounts: NGFResourceCounts{
GatewayCount: 1,
GatewayClassCount: 2,
HTTPRouteCount: 3,
SecretCount: 4,
ServiceCount: 5,
EndpointCount: 6,
},
NGFReplicaCount: 3,
}

expected := []attribute.KeyValue{
attribute.String("dataType", "ngf-product-telemetry"),
attribute.String("ImageSource", "local"),
attribute.String("ProjectName", "NGF"),
attribute.String("ProjectVersion", "edge"),
attribute.String("ProjectArchitecture", "arm64"),
attribute.String("ClusterID", "1"),
attribute.String("ClusterVersion", "1.23"),
attribute.String("ClusterPlatform", "test"),
attribute.String("InstallationID", "123"),
attribute.Int64("ClusterNodeCount", 3),
attribute.StringSlice("FlagNames", []string{"test-flag"}),
attribute.StringSlice("FlagValues", []string{"test-value"}),
attribute.Int64("GatewayCount", 1),
attribute.Int64("GatewayClassCount", 2),
attribute.Int64("HTTPRouteCount", 3),
attribute.Int64("SecretCount", 4),
attribute.Int64("ServiceCount", 5),
attribute.Int64("EndpointCount", 6),
attribute.Int64("NGFReplicaCount", 3),
}

result := data.Attributes()

g := NewWithT(t)

g.Expect(result).To(Equal(expected))
}

func TestDataAttributesWithEmptyData(t *testing.T) {
data := Data{}

expected := []attribute.KeyValue{
attribute.String("dataType", "ngf-product-telemetry"),
attribute.String("ImageSource", ""),
attribute.String("ProjectName", ""),
attribute.String("ProjectVersion", ""),
attribute.String("ProjectArchitecture", ""),
attribute.String("ClusterID", ""),
attribute.String("ClusterVersion", ""),
attribute.String("ClusterPlatform", ""),
attribute.String("InstallationID", ""),
attribute.Int64("ClusterNodeCount", 0),
attribute.StringSlice("FlagNames", nil),
attribute.StringSlice("FlagValues", nil),
attribute.Int64("GatewayCount", 0),
attribute.Int64("GatewayClassCount", 0),
attribute.Int64("HTTPRouteCount", 0),
attribute.Int64("SecretCount", 0),
attribute.Int64("ServiceCount", 0),
attribute.Int64("EndpointCount", 0),
attribute.Int64("NGFReplicaCount", 0),
}

result := data.Attributes()

g := NewWithT(t)

g.Expect(result).To(Equal(expected))
}

0 comments on commit da0b5d2

Please sign in to comment.