github.com/diamondburned/arikawa/v2@v2.1.0/api/api_test.go (about)

     1  package api
     2  
     3  import (
     4  	"context"
     5  	"errors"
     6  	"testing"
     7  )
     8  
     9  func TestContext(t *testing.T) {
    10  	ctx, cancel := context.WithCancel(context.Background())
    11  	cancel() // lol
    12  
    13  	client := NewClient("no. 3-chan").WithContext(ctx)
    14  
    15  	// This should fail.
    16  	_, err := client.Me()
    17  	if err == nil || !errors.Is(err, context.Canceled) {
    18  		t.Fatal("Unexpected error:", err)
    19  	}
    20  }