...

Source file src/go.opencensus.io/plugin/ochttp/stats_test.go

Documentation: go.opencensus.io/plugin/ochttp

     1  // Copyright 2018, OpenCensus Authors
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //     http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package ochttp
    16  
    17  import (
    18  	"reflect"
    19  	"strings"
    20  	"testing"
    21  
    22  	"go.opencensus.io/stats"
    23  	"go.opencensus.io/stats/view"
    24  	"go.opencensus.io/tag"
    25  )
    26  
    27  func TestClientViews(t *testing.T) {
    28  	for _, v := range []*view.View{
    29  		ClientSentBytesDistribution,
    30  		ClientReceivedBytesDistribution,
    31  		ClientRoundtripLatencyDistribution,
    32  		ClientCompletedCount,
    33  	} {
    34  
    35  		if v.Measure == nil {
    36  			t.Fatalf("nil measure: %v", v)
    37  		}
    38  		if m := v.Measure.Name(); !strings.HasPrefix(m, "opencensus.io/http/client/") {
    39  			t.Errorf("Unexpected measure name prefix: %v", v)
    40  		}
    41  		if v.Name == "" {
    42  			t.Errorf("Empty name: %v", v)
    43  		}
    44  		if !strings.HasPrefix(v.Name, "opencensus.io/http/client/") {
    45  			t.Errorf("Unexpected prefix: %s", v.Name)
    46  		}
    47  		if v.Description == "" {
    48  			t.Errorf("Empty description: %s", v.Name)
    49  		}
    50  		if !reflect.DeepEqual(v.TagKeys, []tag.Key{KeyClientMethod, KeyClientStatus}) {
    51  			t.Errorf("Unexpected tags for client view %s: %v", v.Name, v.TagKeys)
    52  		}
    53  		if strings.HasSuffix(v.Description, ".") {
    54  			t.Errorf("View description should not end with a period: %s", v.Name)
    55  		}
    56  	}
    57  }
    58  
    59  func TestClientTagKeys(t *testing.T) {
    60  	for _, k := range []tag.Key{
    61  		KeyClientStatus,
    62  		KeyClientMethod,
    63  		KeyClientHost,
    64  		KeyClientPath,
    65  	} {
    66  		if !strings.HasPrefix(k.Name(), "http_client_") {
    67  			t.Errorf("Unexpected prefix: %s", k.Name())
    68  		}
    69  	}
    70  }
    71  
    72  func TestClientMeasures(t *testing.T) {
    73  	for _, m := range []stats.Measure{
    74  		ClientSentBytes,
    75  		ClientReceivedBytes,
    76  		ClientRoundtripLatency,
    77  	} {
    78  		if !strings.HasPrefix(m.Name(), "opencensus.io/http/client/") {
    79  			t.Errorf("Unexpected prefix: %v", m)
    80  		}
    81  		if strings.HasSuffix(m.Description(), ".") {
    82  			t.Errorf("View description should not end with a period: %s", m.Name())
    83  		}
    84  		if len(m.Unit()) == 0 {
    85  			t.Errorf("No unit: %s", m.Name())
    86  		}
    87  	}
    88  }
    89  

View as plain text