-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: basic validation to Metric struct (#18)
- Loading branch information
Dara Hayes
committed
Feb 23, 2018
1 parent
bc1ee5d
commit a2bade2
Showing
5 changed files
with
93 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package mobile | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
) | ||
|
||
func TestMetricValidate(t *testing.T) { | ||
|
||
testCases := []struct { | ||
Name string | ||
Metric Metric | ||
Valid bool | ||
ExpectedReason string | ||
}{ | ||
{ | ||
Name: "Empty metric should be invalid", | ||
Metric: Metric{}, | ||
Valid: false, | ||
ExpectedReason: "missing clientId in payload", | ||
}, | ||
{ | ||
Name: "Metric with no clientId should be invalid", | ||
Metric: Metric{Data: &MetricData{App: &AppMetric{SDKVersion: "1"}}}, | ||
Valid: false, | ||
ExpectedReason: "missing clientId in payload", | ||
}, | ||
{ | ||
Name: "Metric with no Data should be invalid", | ||
Metric: Metric{ClientId: "org.aerogear.metrics.testing"}, | ||
Valid: false, | ||
ExpectedReason: "missing metrics data in payload", | ||
}, | ||
{ | ||
Name: "Metric with empty Data should be invalid", | ||
Metric: Metric{ClientId: "org.aerogear.metrics.testing", Data: &MetricData{}}, | ||
Valid: false, | ||
ExpectedReason: "missing metrics data in payload", | ||
}, | ||
{ | ||
Name: "Metric with ClientId and Some Data should be valid", | ||
Metric: Metric{ClientId: "org.aerogear.metrics.testing", Data: &MetricData{App: &AppMetric{SDKVersion: "1"}}}, | ||
Valid: true, | ||
ExpectedReason: "", | ||
}, | ||
} | ||
|
||
for _, tc := range testCases { | ||
valid, reason := tc.Metric.Validate() | ||
|
||
if valid != tc.Valid { | ||
fmt.Errorf("case failed: %s. Expected: %v, got %v", tc.Name, tc.Valid, valid) | ||
} | ||
|
||
if reason != tc.ExpectedReason { | ||
fmt.Errorf("case failed: %s. Expected: %v, got %v", tc.Name, tc.ExpectedReason, reason) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters