blob: ebfa2b0c94131bd18b1848817d0e42beda1693de [file] [log] [blame]
// Copyright 2017 The Fuchsia Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
package config_parser
import (
"testing"
"config"
"google.golang.org/protobuf/encoding/prototext"
"google.golang.org/protobuf/proto"
)
// Basic test for parseProjectConfigData with a 1.0 project.
func TestParseProjectConfigData(t *testing.T) {
y := `
metric_definitions:
- metric_name: the_metric_name
id: 1
time_zone_policy: UTC
reports:
- report_name: the_report
id: 10
report_type: CUSTOM_RAW_DUMP
- report_name: the_other_report
id: 20
report_type: NUMERIC_AGGREGATION
- metric_name: the_other_metric_name
id: 2
time_zone_policy: LOCAL
reports:
- report_name: the_report
id: 10
report_type: NUMERIC_AGGREGATION
`
c := ProjectConfigData{
CustomerId: 1,
ProjectId: 10,
CustomerName: "customer_name",
ProjectName: "project_name",
CobaltVersion: CobaltVersion1,
}
if err := parseProjectConfigData(y, &c); err != nil {
t.Error(err)
}
e := config.ProjectConfigFile{
MetricDefinitions: []*config.MetricDefinition{
{
CustomerId: 1,
ProjectId: 10,
CustomerName: "customer_name",
ProjectName: "project_name",
MetricName: "the_metric_name",
Id: 1,
TimeZonePolicy: config.MetricDefinition_UTC,
Reports: []*config.ReportDefinition{
{
ReportName: "the_report",
Id: 10,
ReportType: config.ReportDefinition_CUSTOM_RAW_DUMP,
},
{
ReportName: "the_other_report",
Id: 20,
ReportType: config.ReportDefinition_NUMERIC_AGGREGATION,
},
},
},
{
CustomerId: 1,
ProjectId: 10,
CustomerName: "customer_name",
ProjectName: "project_name",
MetricName: "the_other_metric_name",
Id: 2,
TimeZonePolicy: config.MetricDefinition_LOCAL,
Reports: []*config.ReportDefinition{
{
ReportName: "the_report",
Id: 10,
ReportType: config.ReportDefinition_NUMERIC_AGGREGATION,
},
},
},
},
}
if !proto.Equal(&e, c.ProjectConfigFile) {
t.Errorf("%v\n!=\n%v", prototext.Format(&e), prototext.Format(c.ProjectConfigFile))
}
}
// Tests that we catch non-unique encoding ids.
func TestParseProjectConfigDataUniqueEncodingIds(t *testing.T) {
y := `
metric_configs:
- id: 1
name: metric_name
time_zone_policy: UTC
- id: 2
name: other_metric_name
time_zone_policy: LOCAL
encoding_configs:
- id: 1
basic_rappor:
prob_0_becomes_1: 0.5
prob_1_stays_1: 0.5
- id: 1
report_configs:
- id: 1
metric_id: 5
- id: 2
`
c := ProjectConfigData{
CustomerId: 1,
ProjectId: 10,
}
if err := parseProjectConfigData(y, &c); err == nil {
t.Error("Accepted non-unique encoding id.")
}
}