blob: f1192b449df91b02c21d1e450b7ed43b17ac3141 [file] [log] [blame]
package config_parser
import (
"config"
"fmt"
"testing"
)
func TestExpandEventVectorBufferMax(t *testing.T) {
rep := config.ReportDefinition{
LocalAggregationProcedure: config.ReportDefinition_SELECT_FIRST,
EventVectorBufferMax: 0,
}
expandDefaultsForReport(&rep)
if rep.EventVectorBufferMax != 1 {
t.Errorf("Failed to set EventVectorBufferMax to default")
}
rep = config.ReportDefinition{
LocalAggregationProcedure: config.ReportDefinition_SELECT_FIRST,
EventVectorBufferMax: 100,
}
expandDefaultsForReport(&rep)
if rep.EventVectorBufferMax != 100 {
t.Errorf("Overrode EventVectorBufferMax from the value set in the registry")
}
rep = config.ReportDefinition{
LocalAggregationProcedure: config.ReportDefinition_AT_LEAST_ONCE,
EventVectorBufferMax: 0,
}
expandDefaultsForReport(&rep)
if rep.EventVectorBufferMax == 1 {
t.Errorf("Expanded EventVectorBufferMax default for non SELECT_FIRST procedure")
}
}
var expandDefaultsTest = []struct {
ty config.ReportDefinition_ReportType
policy config.SystemProfileSelectionPolicy
}{
{ty: config.ReportDefinition_FLEETWIDE_OCCURRENCE_COUNTS, policy: config.SystemProfileSelectionPolicy_REPORT_ALL},
{ty: config.ReportDefinition_FLEETWIDE_HISTOGRAMS, policy: config.SystemProfileSelectionPolicy_REPORT_ALL},
{ty: config.ReportDefinition_FLEETWIDE_MEANS, policy: config.SystemProfileSelectionPolicy_REPORT_ALL},
{ty: config.ReportDefinition_UNIQUE_DEVICE_NUMERIC_STATS, policy: config.SystemProfileSelectionPolicy_REPORT_ALL},
{ty: config.ReportDefinition_HOURLY_VALUE_NUMERIC_STATS, policy: config.SystemProfileSelectionPolicy_REPORT_ALL},
{ty: config.ReportDefinition_STRING_COUNTS, policy: config.SystemProfileSelectionPolicy_REPORT_ALL},
{ty: config.ReportDefinition_UNIQUE_DEVICE_COUNTS, policy: config.SystemProfileSelectionPolicy_SELECT_DEFAULT},
{ty: config.ReportDefinition_UNIQUE_DEVICE_HISTOGRAMS, policy: config.SystemProfileSelectionPolicy_SELECT_DEFAULT},
{ty: config.ReportDefinition_HOURLY_VALUE_HISTOGRAMS, policy: config.SystemProfileSelectionPolicy_SELECT_DEFAULT},
}
func TestExpandSystemProfileSelectionDefaults(t *testing.T) {
for _, tt := range expandDefaultsTest {
t.Run(fmt.Sprintf("ReportType_%v", tt.ty), func(t *testing.T) {
rep := config.ReportDefinition{
ReportType: tt.ty,
SystemProfileSelection: config.SystemProfileSelectionPolicy_SELECT_DEFAULT,
}
expandDefaultsForReport(&rep)
if rep.SystemProfileSelection != tt.policy {
t.Errorf("saw unexpected SystemProfileSelection, got %v, expected %v", rep.SystemProfileSelection, tt.policy)
}
})
}
}
func TestNoOverrideSystemProfileSelectionDefaults(t *testing.T) {
for _, tt := range expandDefaultsTest {
t.Run(fmt.Sprintf("ReportType_%v", tt.ty), func(t *testing.T) {
rep := config.ReportDefinition{
ReportType: tt.ty,
SystemProfileSelection: config.SystemProfileSelectionPolicy_SELECT_FIRST,
}
if tt.policy == rep.SystemProfileSelection {
rep.SystemProfileSelection = config.SystemProfileSelectionPolicy_SELECT_LAST
}
expandDefaultsForReport(&rep)
if rep.SystemProfileSelection == tt.policy {
t.Errorf("explicitly set SystemProfileSelection got overridden")
}
})
}
}