github.com/anthropics/anthropic-sdk-go@v1.70.1/betaorganizationserviceaccount_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 TestBetaOrganizationServiceAccountNewWithOptionalParams(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.ServiceAccounts.New(context.TODO(), anthropic.BetaOrganizationServiceAccountNewParams{
    29  		Name:             "ci-deploy-bot",
    30  		Description:      anthropic.String("description"),
    31  		OrganizationRole: anthropic.BetaOrganizationServiceAccountNewParamsOrganizationRoleAdmin,
    32  		Betas:            []anthropic.AnthropicBeta{anthropic.AnthropicBetaMessageBatches2024_09_24},
    33  	})
    34  	if err != nil {
    35  		var apierr *anthropic.Error
    36  		if errors.As(err, &apierr) {
    37  			t.Log(string(apierr.DumpRequest(true)))
    38  		}
    39  		t.Fatalf("err should be nil: %s", err.Error())
    40  	}
    41  }
    42  
    43  func TestBetaOrganizationServiceAccountGetWithOptionalParams(t *testing.T) {
    44  	baseURL := "http://localhost:4010"
    45  	if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok {
    46  		baseURL = envURL
    47  	}
    48  	if !testutil.CheckTestServer(t, baseURL) {
    49  		return
    50  	}
    51  	client := anthropic.NewClient(
    52  		option.WithBaseURL(baseURL),
    53  		option.WithAPIKey("my-anthropic-api-key"),
    54  	)
    55  	_, err := client.Beta.Organization.ServiceAccounts.Get(
    56  		context.TODO(),
    57  		"service_account_id",
    58  		anthropic.BetaOrganizationServiceAccountGetParams{
    59  			Betas: []anthropic.AnthropicBeta{anthropic.AnthropicBetaMessageBatches2024_09_24},
    60  		},
    61  	)
    62  	if err != nil {
    63  		var apierr *anthropic.Error
    64  		if errors.As(err, &apierr) {
    65  			t.Log(string(apierr.DumpRequest(true)))
    66  		}
    67  		t.Fatalf("err should be nil: %s", err.Error())
    68  	}
    69  }
    70  
    71  func TestBetaOrganizationServiceAccountUpdateWithOptionalParams(t *testing.T) {
    72  	baseURL := "http://localhost:4010"
    73  	if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok {
    74  		baseURL = envURL
    75  	}
    76  	if !testutil.CheckTestServer(t, baseURL) {
    77  		return
    78  	}
    79  	client := anthropic.NewClient(
    80  		option.WithBaseURL(baseURL),
    81  		option.WithAPIKey("my-anthropic-api-key"),
    82  	)
    83  	_, err := client.Beta.Organization.ServiceAccounts.Update(
    84  		context.TODO(),
    85  		"service_account_id",
    86  		anthropic.BetaOrganizationServiceAccountUpdateParams{
    87  			Description:      anthropic.String("description"),
    88  			OrganizationRole: anthropic.BetaOrganizationServiceAccountUpdateParamsOrganizationRoleAdmin,
    89  			Betas:            []anthropic.AnthropicBeta{anthropic.AnthropicBetaMessageBatches2024_09_24},
    90  		},
    91  	)
    92  	if err != nil {
    93  		var apierr *anthropic.Error
    94  		if errors.As(err, &apierr) {
    95  			t.Log(string(apierr.DumpRequest(true)))
    96  		}
    97  		t.Fatalf("err should be nil: %s", err.Error())
    98  	}
    99  }
   100  
   101  func TestBetaOrganizationServiceAccountListWithOptionalParams(t *testing.T) {
   102  	baseURL := "http://localhost:4010"
   103  	if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok {
   104  		baseURL = envURL
   105  	}
   106  	if !testutil.CheckTestServer(t, baseURL) {
   107  		return
   108  	}
   109  	client := anthropic.NewClient(
   110  		option.WithBaseURL(baseURL),
   111  		option.WithAPIKey("my-anthropic-api-key"),
   112  	)
   113  	_, err := client.Beta.Organization.ServiceAccounts.List(context.TODO(), anthropic.BetaOrganizationServiceAccountListParams{
   114  		IncludeArchived: anthropic.Bool(true),
   115  		Limit:           anthropic.Int(1),
   116  		Page:            anthropic.String("page"),
   117  		Betas:           []anthropic.AnthropicBeta{anthropic.AnthropicBetaMessageBatches2024_09_24},
   118  	})
   119  	if err != nil {
   120  		var apierr *anthropic.Error
   121  		if errors.As(err, &apierr) {
   122  			t.Log(string(apierr.DumpRequest(true)))
   123  		}
   124  		t.Fatalf("err should be nil: %s", err.Error())
   125  	}
   126  }
   127  
   128  func TestBetaOrganizationServiceAccountArchiveWithOptionalParams(t *testing.T) {
   129  	baseURL := "http://localhost:4010"
   130  	if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok {
   131  		baseURL = envURL
   132  	}
   133  	if !testutil.CheckTestServer(t, baseURL) {
   134  		return
   135  	}
   136  	client := anthropic.NewClient(
   137  		option.WithBaseURL(baseURL),
   138  		option.WithAPIKey("my-anthropic-api-key"),
   139  	)
   140  	_, err := client.Beta.Organization.ServiceAccounts.Archive(
   141  		context.TODO(),
   142  		"service_account_id",
   143  		anthropic.BetaOrganizationServiceAccountArchiveParams{
   144  			Betas: []anthropic.AnthropicBeta{anthropic.AnthropicBetaMessageBatches2024_09_24},
   145  		},
   146  	)
   147  	if err != nil {
   148  		var apierr *anthropic.Error
   149  		if errors.As(err, &apierr) {
   150  			t.Log(string(apierr.DumpRequest(true)))
   151  		}
   152  		t.Fatalf("err should be nil: %s", err.Error())
   153  	}
   154  }