Skip to content

Commit

Permalink
breaking: rename Type field in SecurityMetric to Id (#37)
Browse files Browse the repository at this point in the history
* breaking: rename Type field in SecurityMetric to Id
  • Loading branch information
Dara Hayes authored Mar 7, 2018
1 parent d6b751c commit 5d42dc4
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
8 changes: 4 additions & 4 deletions pkg/mobile/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ type DeviceMetric struct {
type SecurityMetrics []SecurityMetric

type SecurityMetric struct {
Type *string `json:"type,omitempty"`
Id *string `json:"id,omitempty"`
Name *string `json:"name,omitempty"`
Passed *bool `json:"passed,omitempty"`
}
Expand All @@ -49,7 +49,7 @@ const missingClientIdError = "missing clientId in payload"
const invalidTimestampError = "timestamp must be a valid number"
const missingDataError = "missing metrics data in payload"
const securityMetricsEmptyError = "data.security cannot be empty"
const securityMetricMissingTypeError = "invalid element in data.security at position %v, type must be included"
const securityMetricMissingIdError = "invalid element in data.security at position %v, id must be included"
const securityMetricMissingNameError = "invalid element in data.security at position %v, name must be included"
const securityMetricMissingPassedError = "invalid element in data.security at position %v, passed must be included"

Expand Down Expand Up @@ -84,8 +84,8 @@ func (m *Metric) Validate() (valid bool, reason string) {
return false, securityMetricsLengthError
}
for i, sm := range *m.Data.Security {
if sm.Type == nil {
return false, fmt.Sprintf(securityMetricMissingTypeError, i)
if sm.Id == nil {
return false, fmt.Sprintf(securityMetricMissingIdError, i)
}
if sm.Name == nil {
return false, fmt.Sprintf(securityMetricMissingNameError, i)
Expand Down
14 changes: 7 additions & 7 deletions pkg/mobile/types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ import (

func TestMetricValidate(t *testing.T) {

securityMetricType := "org.aerogear.mobile.security.checks.TestCheck"
securityMetricId := "org.aerogear.mobile.security.checks.TestCheck"
securityMetricName := "TestCheck"
securityMetricPassed := true

bigSecurityMetricList := SecurityMetrics{}
for i := 0; i <= clientIdMaxLength+1; i++ {
bigSecurityMetricList = append(bigSecurityMetricList, SecurityMetric{Type: &securityMetricType, Passed: &securityMetricPassed})
bigSecurityMetricList = append(bigSecurityMetricList, SecurityMetric{Id: &securityMetricId, Passed: &securityMetricPassed})
}

testCases := []struct {
Expand Down Expand Up @@ -72,20 +72,20 @@ func TestMetricValidate(t *testing.T) {
ExpectedReason: "",
},
{
Name: "Security Metrics with missing type field should be invalid",
Metric: Metric{ClientId: "org.aerogear.metrics.testing", Data: &MetricData{Security: &SecurityMetrics{SecurityMetric{Type: nil, Name: &securityMetricName, Passed: &securityMetricPassed}}}},
Name: "Security Metrics with missing id field should be invalid",
Metric: Metric{ClientId: "org.aerogear.metrics.testing", Data: &MetricData{Security: &SecurityMetrics{SecurityMetric{Id: nil, Name: &securityMetricName, Passed: &securityMetricPassed}}}},
Valid: false,
ExpectedReason: fmt.Sprintf(securityMetricMissingTypeError, 0),
ExpectedReason: fmt.Sprintf(securityMetricMissingIdError, 0),
},
{
Name: "Security Metrics with missing name field should be invalid",
Metric: Metric{ClientId: "org.aerogear.metrics.testing", Data: &MetricData{Security: &SecurityMetrics{SecurityMetric{Type: &securityMetricType, Name: nil, Passed: &securityMetricPassed}}}},
Metric: Metric{ClientId: "org.aerogear.metrics.testing", Data: &MetricData{Security: &SecurityMetrics{SecurityMetric{Id: &securityMetricId, Name: nil, Passed: &securityMetricPassed}}}},
Valid: false,
ExpectedReason: fmt.Sprintf(securityMetricMissingNameError, 0),
},
{
Name: "Security Metrics with missing passed field should be invalid",
Metric: Metric{ClientId: "org.aerogear.metrics.testing", Data: &MetricData{Security: &SecurityMetrics{SecurityMetric{Type: &securityMetricType, Name: &securityMetricName, Passed: nil}}}},
Metric: Metric{ClientId: "org.aerogear.metrics.testing", Data: &MetricData{Security: &SecurityMetrics{SecurityMetric{Id: &securityMetricId, Name: &securityMetricName, Passed: nil}}}},
Valid: false,
ExpectedReason: fmt.Sprintf(securityMetricMissingPassedError, 0),
},
Expand Down

0 comments on commit 5d42dc4

Please sign in to comment.