github.com/anthropics/anthropic-sdk-go@v1.70.1/betaorganizationfederationissuer_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 TestBetaOrganizationFederationIssuerNewWithOptionalParams(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.Federation.Issuers.New(context.TODO(), anthropic.BetaOrganizationFederationIssuerNewParams{
    29  		IssuerURL: "x",
    30  		Name:      "x",
    31  		CheckJTI:  anthropic.Bool(true),
    32  		JWKS: anthropic.BetaOrganizationFederationIssuerNewParamsJWKSUnion{
    33  			OfDiscovery: &anthropic.BetaJWKSDiscoveryParam{
    34  				CACertPEM:     anthropic.String("ca_cert_pem"),
    35  				DiscoveryBase: anthropic.String("discovery_base"),
    36  			},
    37  		},
    38  		MaxJWTLifetimeSeconds: anthropic.Int(1),
    39  		Betas:                 []anthropic.AnthropicBeta{anthropic.AnthropicBetaMessageBatches2024_09_24},
    40  	})
    41  	if err != nil {
    42  		var apierr *anthropic.Error
    43  		if errors.As(err, &apierr) {
    44  			t.Log(string(apierr.DumpRequest(true)))
    45  		}
    46  		t.Fatalf("err should be nil: %s", err.Error())
    47  	}
    48  }
    49  
    50  func TestBetaOrganizationFederationIssuerGetWithOptionalParams(t *testing.T) {
    51  	baseURL := "http://localhost:4010"
    52  	if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok {
    53  		baseURL = envURL
    54  	}
    55  	if !testutil.CheckTestServer(t, baseURL) {
    56  		return
    57  	}
    58  	client := anthropic.NewClient(
    59  		option.WithBaseURL(baseURL),
    60  		option.WithAPIKey("my-anthropic-api-key"),
    61  	)
    62  	_, err := client.Beta.Organization.Federation.Issuers.Get(
    63  		context.TODO(),
    64  		"federation_issuer_id",
    65  		anthropic.BetaOrganizationFederationIssuerGetParams{
    66  			Betas: []anthropic.AnthropicBeta{anthropic.AnthropicBetaMessageBatches2024_09_24},
    67  		},
    68  	)
    69  	if err != nil {
    70  		var apierr *anthropic.Error
    71  		if errors.As(err, &apierr) {
    72  			t.Log(string(apierr.DumpRequest(true)))
    73  		}
    74  		t.Fatalf("err should be nil: %s", err.Error())
    75  	}
    76  }
    77  
    78  func TestBetaOrganizationFederationIssuerUpdateWithOptionalParams(t *testing.T) {
    79  	baseURL := "http://localhost:4010"
    80  	if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok {
    81  		baseURL = envURL
    82  	}
    83  	if !testutil.CheckTestServer(t, baseURL) {
    84  		return
    85  	}
    86  	client := anthropic.NewClient(
    87  		option.WithBaseURL(baseURL),
    88  		option.WithAPIKey("my-anthropic-api-key"),
    89  	)
    90  	_, err := client.Beta.Organization.Federation.Issuers.Update(
    91  		context.TODO(),
    92  		"federation_issuer_id",
    93  		anthropic.BetaOrganizationFederationIssuerUpdateParams{
    94  			CheckJTI:  anthropic.Bool(true),
    95  			IssuerURL: anthropic.String("x"),
    96  			JWKS: anthropic.BetaOrganizationFederationIssuerUpdateParamsJWKSUnion{
    97  				OfDiscovery: &anthropic.BetaJWKSDiscoveryParam{
    98  					CACertPEM:     anthropic.String("ca_cert_pem"),
    99  					DiscoveryBase: anthropic.String("discovery_base"),
   100  				},
   101  			},
   102  			JWKSPollingDisabled:   anthropic.Bool(true),
   103  			MaxJWTLifetimeSeconds: anthropic.Int(1),
   104  			Name:                  anthropic.String("x"),
   105  			Betas:                 []anthropic.AnthropicBeta{anthropic.AnthropicBetaMessageBatches2024_09_24},
   106  		},
   107  	)
   108  	if err != nil {
   109  		var apierr *anthropic.Error
   110  		if errors.As(err, &apierr) {
   111  			t.Log(string(apierr.DumpRequest(true)))
   112  		}
   113  		t.Fatalf("err should be nil: %s", err.Error())
   114  	}
   115  }
   116  
   117  func TestBetaOrganizationFederationIssuerListWithOptionalParams(t *testing.T) {
   118  	baseURL := "http://localhost:4010"
   119  	if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok {
   120  		baseURL = envURL
   121  	}
   122  	if !testutil.CheckTestServer(t, baseURL) {
   123  		return
   124  	}
   125  	client := anthropic.NewClient(
   126  		option.WithBaseURL(baseURL),
   127  		option.WithAPIKey("my-anthropic-api-key"),
   128  	)
   129  	_, err := client.Beta.Organization.Federation.Issuers.List(context.TODO(), anthropic.BetaOrganizationFederationIssuerListParams{
   130  		IncludeArchived: anthropic.Bool(true),
   131  		Limit:           anthropic.Int(1),
   132  		Page:            anthropic.String("page"),
   133  		Betas:           []anthropic.AnthropicBeta{anthropic.AnthropicBetaMessageBatches2024_09_24},
   134  	})
   135  	if err != nil {
   136  		var apierr *anthropic.Error
   137  		if errors.As(err, &apierr) {
   138  			t.Log(string(apierr.DumpRequest(true)))
   139  		}
   140  		t.Fatalf("err should be nil: %s", err.Error())
   141  	}
   142  }
   143  
   144  func TestBetaOrganizationFederationIssuerArchiveWithOptionalParams(t *testing.T) {
   145  	baseURL := "http://localhost:4010"
   146  	if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok {
   147  		baseURL = envURL
   148  	}
   149  	if !testutil.CheckTestServer(t, baseURL) {
   150  		return
   151  	}
   152  	client := anthropic.NewClient(
   153  		option.WithBaseURL(baseURL),
   154  		option.WithAPIKey("my-anthropic-api-key"),
   155  	)
   156  	_, err := client.Beta.Organization.Federation.Issuers.Archive(
   157  		context.TODO(),
   158  		"federation_issuer_id",
   159  		anthropic.BetaOrganizationFederationIssuerArchiveParams{
   160  			Betas: []anthropic.AnthropicBeta{anthropic.AnthropicBetaMessageBatches2024_09_24},
   161  		},
   162  	)
   163  	if err != nil {
   164  		var apierr *anthropic.Error
   165  		if errors.As(err, &apierr) {
   166  			t.Log(string(apierr.DumpRequest(true)))
   167  		}
   168  		t.Fatalf("err should be nil: %s", err.Error())
   169  	}
   170  }