Skip to content

Commit

Permalink
PMM-13057 Forgotten file.
Browse files Browse the repository at this point in the history
  • Loading branch information
JiriCtvrtka committed Oct 31, 2024
1 parent 93de7ef commit d9c6bd9
Showing 1 changed file with 24 additions and 24 deletions.
48 changes: 24 additions & 24 deletions managed/services/telemetry/transform_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,22 @@ package telemetry
import (
"testing"

genericv1 "github.com/percona/saas/gen/telemetry/generic"
telemetryv1 "github.com/percona/saas/gen/telemetry/generic"
"github.com/stretchr/testify/assert"
)

func TestTransformToJSON(t *testing.T) {
type args struct {
config *Config
metrics []*genericv1.GenericReport_Metric
metrics []*telemetryv1.GenericReport_Metric
}

noMetrics := []*genericv1.GenericReport_Metric{}
noMetrics := []*telemetryv1.GenericReport_Metric{}

tests := []struct {
name string
args args
want []*genericv1.GenericReport_Metric
want []*telemetryv1.GenericReport_Metric
wantErr assert.ErrorAssertionFunc
}{
{
Expand Down Expand Up @@ -85,7 +85,7 @@ func TestTransformToJSON(t *testing.T) {
name: "invalid seq",
args: args{
config: configJSON(),
metrics: []*genericv1.GenericReport_Metric{
metrics: []*telemetryv1.GenericReport_Metric{
{Key: "my-metric", Value: "v1"},
{Key: "b", Value: "v1"},
{Key: "b", Value: "v1"}, // <--- will override second metric
Expand All @@ -99,14 +99,14 @@ func TestTransformToJSON(t *testing.T) {
name: "correct seq",
args: args{
config: configJSON(),
metrics: []*genericv1.GenericReport_Metric{
metrics: []*telemetryv1.GenericReport_Metric{
{Key: "my-metric", Value: "v1"},
{Key: "b", Value: "v1"},
{Key: "my-metric", Value: "v1"},
{Key: "b", Value: "v1"},
},
},
want: []*genericv1.GenericReport_Metric{
want: []*telemetryv1.GenericReport_Metric{
{Key: configJSON().Transform.Metric, Value: `{"v":[{"b":"v1","my-metric":"v1"},{"b":"v1","my-metric":"v1"}]}`},
},
wantErr: assert.NoError,
Expand All @@ -115,12 +115,12 @@ func TestTransformToJSON(t *testing.T) {
name: "happy path",
args: args{
config: configJSON(),
metrics: []*genericv1.GenericReport_Metric{
metrics: []*telemetryv1.GenericReport_Metric{
{Key: configJSON().Data[0].MetricName, Value: "v1"},
{Key: configJSON().Data[0].MetricName, Value: "v2"},
},
},
want: []*genericv1.GenericReport_Metric{
want: []*telemetryv1.GenericReport_Metric{
{Key: configJSON().Transform.Metric, Value: `{"v":[{"my-metric":"v1"},{"my-metric":"v2"}]}`},
},
wantErr: assert.NoError,
Expand All @@ -135,14 +135,14 @@ func TestTransformToJSON(t *testing.T) {
{MetricName: "4", Label: "status"},
{MetricName: "5", Label: "type"},
}),
metrics: []*genericv1.GenericReport_Metric{
metrics: []*telemetryv1.GenericReport_Metric{
{Key: "licence", Value: `GPL`},
{Key: "name", Value: `INNODB_TABLES`},
{Key: "status", Value: `ACTIVE`},
{Key: "type", Value: `INFORMATION SCHEMA`},
},
},
want: []*genericv1.GenericReport_Metric{
want: []*telemetryv1.GenericReport_Metric{
{Key: "metric", Value: `{"v":[{"licence":"GPL","name":"INNODB_TABLES","status":"ACTIVE","type":"INFORMATION SCHEMA"}]}`},
},
wantErr: assert.NoError,
Expand All @@ -164,15 +164,15 @@ func TestTransformToJSON(t *testing.T) {
func TestTransformExportValues(t *testing.T) {
type args struct {
config *Config
metrics []*genericv1.GenericReport_Metric
metrics []*telemetryv1.GenericReport_Metric
}

noMetrics := []*genericv1.GenericReport_Metric{}
noMetrics := []*telemetryv1.GenericReport_Metric{}

tests := []struct {
name string
args args
want []*genericv1.GenericReport_Metric
want []*telemetryv1.GenericReport_Metric
wantErr assert.ErrorAssertionFunc
}{
{
Expand Down Expand Up @@ -215,7 +215,7 @@ func TestTransformExportValues(t *testing.T) {
name: "invalid data source",
args: args{
config: configEnvVars().changeDataSource(dsPMMDBSelect),
metrics: []*genericv1.GenericReport_Metric{
metrics: []*telemetryv1.GenericReport_Metric{
{Key: "metric-a", Value: "v1"},
{Key: "metric-b", Value: "v2"},
},
Expand All @@ -227,12 +227,12 @@ func TestTransformExportValues(t *testing.T) {
name: "happy path",
args: args{
config: configEnvVars(),
metrics: []*genericv1.GenericReport_Metric{
metrics: []*telemetryv1.GenericReport_Metric{
{Key: "metric-a", Value: "v1"},
{Key: "metric-b", Value: "v2"},
},
},
want: []*genericv1.GenericReport_Metric{
want: []*telemetryv1.GenericReport_Metric{
{Key: "metric-a", Value: "1"},
{Key: "metric-b", Value: "1"},
},
Expand Down Expand Up @@ -300,16 +300,16 @@ func (c *Config) changeData(d []ConfigData) *Config {

func TestRemoveEmpty(t *testing.T) {
type args struct {
metrics []*genericv1.GenericReport_Metric
metrics []*telemetryv1.GenericReport_Metric
}
tests := []struct {
name string
args args
want []*genericv1.GenericReport_Metric
want []*telemetryv1.GenericReport_Metric
}{
{
name: "should remove metrics with empty values",
args: args{metrics: []*genericv1.GenericReport_Metric{
args: args{metrics: []*telemetryv1.GenericReport_Metric{
{
Key: "empty_value",
Value: "",
Expand All @@ -323,7 +323,7 @@ func TestRemoveEmpty(t *testing.T) {
Value: "",
},
}},
want: []*genericv1.GenericReport_Metric{
want: []*telemetryv1.GenericReport_Metric{
{
Key: "not_empty",
Value: "not_empty",
Expand All @@ -332,7 +332,7 @@ func TestRemoveEmpty(t *testing.T) {
},
{
name: "should not remove anything if metrics are not empty",
args: args{metrics: []*genericv1.GenericReport_Metric{
args: args{metrics: []*telemetryv1.GenericReport_Metric{
{
Key: "not_empty",
Value: "not_empty",
Expand All @@ -342,7 +342,7 @@ func TestRemoveEmpty(t *testing.T) {
Value: "not_empty",
},
}},
want: []*genericv1.GenericReport_Metric{
want: []*telemetryv1.GenericReport_Metric{
{
Key: "not_empty",
Value: "not_empty",
Expand All @@ -356,7 +356,7 @@ func TestRemoveEmpty(t *testing.T) {
{
name: "should not remove anything if metrics are not empty",
args: args{metrics: nil},
want: []*genericv1.GenericReport_Metric{},
want: []*telemetryv1.GenericReport_Metric{},
},
}

Expand Down

0 comments on commit d9c6bd9

Please sign in to comment.