github.com/anthropics/anthropic-sdk-go@v1.70.1/betaorganizationuser_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 TestBetaOrganizationUserGet(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.Users.Get(context.TODO(), "user_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 TestBetaOrganizationUserUpdate(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.Users.Update( 51 context.TODO(), 52 "user_id", 53 anthropic.BetaOrganizationUserUpdateParams{ 54 Role: anthropic.BetaOrganizationUserUpdateParamsRoleUser, 55 }, 56 ) 57 if err != nil { 58 var apierr *anthropic.Error 59 if errors.As(err, &apierr) { 60 t.Log(string(apierr.DumpRequest(true))) 61 } 62 t.Fatalf("err should be nil: %s", err.Error()) 63 } 64 } 65 66 func TestBetaOrganizationUserListWithOptionalParams(t *testing.T) { 67 baseURL := "http://localhost:4010" 68 if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok { 69 baseURL = envURL 70 } 71 if !testutil.CheckTestServer(t, baseURL) { 72 return 73 } 74 client := anthropic.NewClient( 75 option.WithBaseURL(baseURL), 76 option.WithAPIKey("my-anthropic-api-key"), 77 ) 78 _, err := client.Beta.Organization.Users.List(context.TODO(), anthropic.BetaOrganizationUserListParams{ 79 AfterID: anthropic.String("after_id"), 80 BeforeID: anthropic.String("before_id"), 81 Email: anthropic.String("dev@stainless.com"), 82 Limit: anthropic.Int(1), 83 Roles: []string{"string"}, 84 }) 85 if err != nil { 86 var apierr *anthropic.Error 87 if errors.As(err, &apierr) { 88 t.Log(string(apierr.DumpRequest(true))) 89 } 90 t.Fatalf("err should be nil: %s", err.Error()) 91 } 92 } 93 94 func TestBetaOrganizationUserRemove(t *testing.T) { 95 baseURL := "http://localhost:4010" 96 if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok { 97 baseURL = envURL 98 } 99 if !testutil.CheckTestServer(t, baseURL) { 100 return 101 } 102 client := anthropic.NewClient( 103 option.WithBaseURL(baseURL), 104 option.WithAPIKey("my-anthropic-api-key"), 105 ) 106 _, err := client.Beta.Organization.Users.Remove(context.TODO(), "user_id") 107 if err != nil { 108 var apierr *anthropic.Error 109 if errors.As(err, &apierr) { 110 t.Log(string(apierr.DumpRequest(true))) 111 } 112 t.Fatalf("err should be nil: %s", err.Error()) 113 } 114 }