github.com/grailbio/base@v0.0.11/backgroundcontext/backgroundcontext_test.go (about)

     1  // Copyright 2019 GRAIL, Inc. All rights reserved.
     2  // Use of this source code is governed by the Apache 2.0
     3  // license that can be found in the LICENSE file.
     4  
     5  //+build !unit
     6  
     7  package backgroundcontext_test
     8  
     9  import (
    10  	"context"
    11  	"testing"
    12  
    13  	"github.com/grailbio/base/backgroundcontext"
    14  	"github.com/grailbio/base/vcontext"
    15  	v23 "v.io/v23"
    16  	v23context "v.io/v23/context"
    17  )
    18  
    19  func TestWrap(t *testing.T) {
    20  	// This sets the backgroundcontext.
    21  	_ = vcontext.Background()
    22  
    23  	ctx, cancel := context.WithCancel(context.Background())
    24  	bgctx := backgroundcontext.Wrap(ctx)
    25  	if v23.GetClient(v23context.FromGoContext(bgctx)) == nil {
    26  		t.Fatal("no v23 client returned")
    27  	}
    28  	cancel()
    29  	if got, want := bgctx.Err(), context.Canceled; got != want {
    30  		t.Errorf("got %v, want %v", got, want)
    31  	}
    32  }