github.com/anthropics/anthropic-sdk-go@v1.70.1/betaorganizationapikey_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  	"errors"
     8  	"os"
     9  	"testing"
    10  
    11  	"github.com/anthropics/anthropic-sdk-go"
    12  	"github.com/anthropics/anthropic-sdk-go/internal/testutil"
    13  	"github.com/anthropics/anthropic-sdk-go/option"
    14  )
    15  
    16  func TestBetaOrganizationAPIKeyGet(t *testing.T) {
    17  	baseURL := "http://localhost:4010"
    18  	if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok {
    19  		baseURL = envURL
    20  	}
    21  	if !testutil.CheckTestServer(t, baseURL) {
    22  		return
    23  	}
    24  	client := anthropic.NewClient(
    25  		option.WithBaseURL(baseURL),
    26  		option.WithAPIKey("my-anthropic-api-key"),
    27  	)
    28  	_, err := client.Beta.Organization.APIKeys.Get(context.TODO(), "api_key_id")
    29  	if err != nil {
    30  		var apierr *anthropic.Error
    31  		if errors.As(err, &apierr) {
    32  			t.Log(string(apierr.DumpRequest(true)))
    33  		}
    34  		t.Fatalf("err should be nil: %s", err.Error())
    35  	}
    36  }
    37  
    38  func TestBetaOrganizationAPIKeyUpdateWithOptionalParams(t *testing.T) {
    39  	baseURL := "http://localhost:4010"
    40  	if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok {
    41  		baseURL = envURL
    42  	}
    43  	if !testutil.CheckTestServer(t, baseURL) {
    44  		return
    45  	}
    46  	client := anthropic.NewClient(
    47  		option.WithBaseURL(baseURL),
    48  		option.WithAPIKey("my-anthropic-api-key"),
    49  	)
    50  	_, err := client.Beta.Organization.APIKeys.Update(
    51  		context.TODO(),
    52  		"api_key_id",
    53  		anthropic.BetaOrganizationAPIKeyUpdateParams{
    54  			Name:   anthropic.String("x"),
    55  			Status: anthropic.BetaOrganizationAPIKeyUpdateParamsStatusActive,
    56  		},
    57  	)
    58  	if err != nil {
    59  		var apierr *anthropic.Error
    60  		if errors.As(err, &apierr) {
    61  			t.Log(string(apierr.DumpRequest(true)))
    62  		}
    63  		t.Fatalf("err should be nil: %s", err.Error())
    64  	}
    65  }
    66  
    67  func TestBetaOrganizationAPIKeyListWithOptionalParams(t *testing.T) {
    68  	baseURL := "http://localhost:4010"
    69  	if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok {
    70  		baseURL = envURL
    71  	}
    72  	if !testutil.CheckTestServer(t, baseURL) {
    73  		return
    74  	}
    75  	client := anthropic.NewClient(
    76  		option.WithBaseURL(baseURL),
    77  		option.WithAPIKey("my-anthropic-api-key"),
    78  	)
    79  	_, err := client.Beta.Organization.APIKeys.List(context.TODO(), anthropic.BetaOrganizationAPIKeyListParams{
    80  		AfterID:         anthropic.String("after_id"),
    81  		BeforeID:        anthropic.String("before_id"),
    82  		CreatedByUserID: anthropic.String("created_by_user_id"),
    83  		Limit:           anthropic.Int(1),
    84  		Status:          anthropic.BetaOrganizationAPIKeyListParamsStatusActive,
    85  		WorkspaceID:     anthropic.String("workspace_id"),
    86  	})
    87  	if err != nil {
    88  		var apierr *anthropic.Error
    89  		if errors.As(err, &apierr) {
    90  			t.Log(string(apierr.DumpRequest(true)))
    91  		}
    92  		t.Fatalf("err should be nil: %s", err.Error())
    93  	}
    94  }