github.com/thiagoyeds/go-cloud@v0.26.0/docstore/oc_test.go (about)

     1  // Copyright 2019 The Go Cloud Development Kit 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  //     https://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 docstore_test
    16  
    17  import (
    18  	"context"
    19  	"testing"
    20  
    21  	"gocloud.dev/docstore"
    22  	"gocloud.dev/docstore/memdocstore"
    23  	"gocloud.dev/gcerrors"
    24  	"gocloud.dev/internal/testing/octest"
    25  )
    26  
    27  func TestOpenCensus(t *testing.T) {
    28  	ctx := context.Background()
    29  	te := octest.NewTestExporter(docstore.OpenCensusViews)
    30  	defer te.Unregister()
    31  
    32  	coll, err := memdocstore.OpenCollection("_id", nil)
    33  	if err != nil {
    34  		t.Fatal(err)
    35  	}
    36  	defer coll.Close()
    37  
    38  	// ActionList.Do.
    39  	if err := coll.Create(ctx, map[string]interface{}{"_id": "a", "count": 0}); err != nil {
    40  		t.Fatal(err)
    41  	}
    42  
    43  	// Query.Get.
    44  	iter := coll.Query().Get(ctx)
    45  	iter.Stop()
    46  
    47  	const driver = "gocloud.dev/docstore/memdocstore"
    48  
    49  	diff := octest.Diff(te.Spans(), te.Counts(), "gocloud.dev/docstore", driver, []octest.Call{
    50  		{Method: "ActionList.Do", Code: gcerrors.OK},
    51  		{Method: "Query.Get", Code: gcerrors.OK},
    52  	})
    53  	if diff != "" {
    54  		t.Error(diff)
    55  	}
    56  }