Files
fn-serverless/vendor/go.opencensus.io/plugin/ocgrpc/client_metrics_test.go
Reed Allman 4084b727c0 phase 2: mattes/migrate -> migratex (#848)
* move mattes migrations to migratex

* changes format of migrations to migratex format
* updates test runner to use new interface (double checked this with printlns,
the tests go fully down and then up, and work on pg/mysql)

* remove mattes/migrate

* update tests from deps

* update readme

* fix other file extensions
2018-03-13 14:12:34 -07:00

72 lines
2.8 KiB
Go

// Copyright 2017, OpenCensus Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
package ocgrpc
import (
"reflect"
"runtime"
"testing"
"go.opencensus.io/stats/view"
)
func TestViewsAggregationsConform(t *testing.T) {
// See Issue https://github.com/census-instrumentation/opencensus-go/issues/210.
// This test ensures that the types of our Views match up with those
// from the Java reference at
// https://github.com/census-instrumentation/opencensus-java/blob/2b464864e3dd3f80e8e4c9dc72fccc225444a939/contrib/grpc_metrics/src/main/java/io/opencensus/contrib/grpc/metrics/RpcViewConstants.java#L113-L658
// Add any other defined views to be type checked during tests to ensure we don't regress.
assertTypeOf := func(v *view.View, wantSample view.Aggregation) {
aggregation := v.Aggregation
gotValue := reflect.ValueOf(aggregation)
wantValue := reflect.ValueOf(wantSample)
if gotValue.Type() != wantValue.Type() {
_, _, line, _ := runtime.Caller(1)
t.Errorf("Item on line: %d got %T want %T", line, aggregation, wantSample)
}
}
assertTypeOf(ClientErrorCountView, view.MeanAggregation{})
assertTypeOf(ClientRoundTripLatencyView, view.DistributionAggregation{})
assertTypeOf(ClientRequestBytesView, view.DistributionAggregation{})
assertTypeOf(ClientResponseBytesView, view.DistributionAggregation{})
assertTypeOf(ClientRequestCountView, view.DistributionAggregation{})
assertTypeOf(ClientResponseCountView, view.DistributionAggregation{})
}
func TestStrictViewNames(t *testing.T) {
alreadySeen := make(map[string]int)
assertName := func(v *view.View, want string) {
_, _, line, _ := runtime.Caller(1)
if prevLine, ok := alreadySeen[v.Name]; ok {
t.Errorf("Item's Name on line %d was already used on line %d", line, prevLine)
return
}
if got := v.Name; got != want {
t.Errorf("Item on line: %d got %q want %q", line, got, want)
}
alreadySeen[v.Name] = line
}
assertName(ClientErrorCountView, "grpc.io/client/error_count")
assertName(ClientRoundTripLatencyView, "grpc.io/client/roundtrip_latency")
assertName(ClientRequestBytesView, "grpc.io/client/request_bytes")
assertName(ClientResponseBytesView, "grpc.io/client/response_bytes")
assertName(ClientRequestCountView, "grpc.io/client/request_count")
assertName(ClientResponseCountView, "grpc.io/client/response_count")
}