github.com/anthropics/anthropic-sdk-go@v1.70.1/paginationauto_test.go (about)

     1  // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
     2  
     3  package anthropic_test
     4  
     5  import (
     6  	"context"
     7  	"os"
     8  	"testing"
     9  
    10  	"github.com/anthropics/anthropic-sdk-go"
    11  	"github.com/anthropics/anthropic-sdk-go/internal/testutil"
    12  	"github.com/anthropics/anthropic-sdk-go/option"
    13  )
    14  
    15  func TestAutoPagination(t *testing.T) {
    16  	baseURL := "http://localhost:4010"
    17  	if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok {
    18  		baseURL = envURL
    19  	}
    20  	if !testutil.CheckTestServer(t, baseURL) {
    21  		return
    22  	}
    23  	client := anthropic.NewClient(
    24  		option.WithBaseURL(baseURL),
    25  		option.WithAPIKey("my-anthropic-api-key"),
    26  	)
    27  	iter := client.Beta.Messages.Batches.ListAutoPaging(context.TODO(), anthropic.BetaMessageBatchListParams{
    28  		Limit: anthropic.Int(20),
    29  	})
    30  	// The mock server isn't going to give us real pagination
    31  	for i := 0; i < 3 && iter.Next(); i++ {
    32  		batch := iter.Current()
    33  		t.Logf("%+v\n", batch.ID)
    34  	}
    35  	if err := iter.Err(); err != nil {
    36  		t.Fatalf("err should be nil: %s", err.Error())
    37  	}
    38  }