github.com/anthropics/anthropic-sdk-go@v1.70.1/paginationmanual_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 TestManualPagination(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  	page, err := client.Beta.Messages.Batches.List(context.TODO(), anthropic.BetaMessageBatchListParams{
    28  		Limit: anthropic.Int(20),
    29  	})
    30  	if err != nil {
    31  		t.Fatalf("err should be nil: %s", err.Error())
    32  	}
    33  	for _, batch := range page.Data {
    34  		t.Logf("%+v\n", batch.ID)
    35  	}
    36  	// The mock server isn't going to give us real pagination
    37  	page, err = page.GetNextPage()
    38  	if err != nil {
    39  		t.Fatalf("err should be nil: %s", err.Error())
    40  	}
    41  	if page != nil {
    42  		for _, batch := range page.Data {
    43  			t.Logf("%+v\n", batch.ID)
    44  		}
    45  	}
    46  }