github.com/cornelk/go-cloud@v0.17.1/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  	"github.com/cornelk/go-cloud/docstore"
    22  	"github.com/cornelk/go-cloud/docstore/memdocstore"
    23  	"github.com/cornelk/go-cloud/gcerrors"
    24  	"github.com/cornelk/go-cloud/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 = "github.com/cornelk/go-cloud/docstore/memdocstore"
    48  
    49  	diff := octest.Diff(te.Spans(), te.Counts(), "github.com/cornelk/go-cloud/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  }