Skip to content

Commit

Permalink
Bail fast if function returns error (#4016)
Browse files Browse the repository at this point in the history
Bail fast if func returns err
  • Loading branch information
jjngx authored Jun 16, 2023
1 parent 6494ab5 commit 763ad99
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions internal/metrics/collectors/latency_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func TestParseMessageWithValidInputs(t *testing.T) {
}
} else {
if err != nil {
t.Errorf("parseMessage returned an unexpected error: %v", err)
t.Fatalf("parseMessage returned an unexpected error: %v", err)
}
if actual != test.expected {
t.Errorf("parseMessage returned: %+v, expected: %+v", actual, test.expected)
Expand Down Expand Up @@ -112,7 +112,7 @@ func TestCreateLatencyLabelValuesWithCorrectNumberOfLabels(t *testing.T) {
expected := []string{"upstream-1", "10.0.0.1", "200", "service-1", "ingress", "ingress-1", "default", "pod-1"}
actual, err := collector.createLatencyLabelValues(lm)
if err != nil {
t.Errorf("createLatencyLabelValues returned unexpected error: %v", err)
t.Fatalf("createLatencyLabelValues returned unexpected error: %v", err)
}
if !reflect.DeepEqual(expected, actual) {
t.Errorf("createLatencyLabelValues returned: %v, expected: %v", actual, expected)
Expand Down Expand Up @@ -184,7 +184,7 @@ func TestMetricsPublished(t *testing.T) {
// verify metrics for upstream-1 are correct
upstream1Metrics, ok := collector.metricsPublishedMap["upstream-1/10.0.0.0:80"]
if !ok {
t.Errorf("updateMetricsPublished did not add upstream-1 as key to map")
t.Fatal("updateMetricsPublished did not add upstream-1 as key to map")
}
if l := len(upstream1Metrics); l != 2 {
t.Errorf("updateMetricsPublished did not update upstream-1 map correctly, length is %d expected 2", l)
Expand All @@ -208,7 +208,7 @@ func TestMetricsPublished(t *testing.T) {
// verify metrics for upstream-2 are correct
upstream2Metrics, ok := collector.metricsPublishedMap["upstream-2/10.0.0.0:80"]
if !ok {
t.Errorf("updateMetricsPublished did not add upstream-2 as key to map")
t.Fatal("updateMetricsPublished did not add upstream-2 as key to map")
}
if l := len(upstream2Metrics); l != 1 {
t.Errorf("updateMetricsPublished did not update upstream-2 map correctly, length is %d expected 1", l)
Expand Down

0 comments on commit 763ad99

Please sign in to comment.