github.com/anthropics/anthropic-sdk-go@v1.70.1/betavault_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 TestBetaVaultNewWithOptionalParams(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.Vaults.New(context.TODO(), anthropic.BetaVaultNewParams{ 29 DisplayName: "Example vault", 30 Metadata: map[string]string{ 31 "environment": "production", 32 }, 33 Betas: []anthropic.AnthropicBeta{anthropic.AnthropicBetaMessageBatches2024_09_24}, 34 WorkspaceID: anthropic.String("wrkspc_011CZkZaBF1tNoB5wlCeusgy"), 35 }) 36 if err != nil { 37 var apierr *anthropic.Error 38 if errors.As(err, &apierr) { 39 t.Log(string(apierr.DumpRequest(true))) 40 } 41 t.Fatalf("err should be nil: %s", err.Error()) 42 } 43 } 44 45 func TestBetaVaultGetWithOptionalParams(t *testing.T) { 46 baseURL := "http://localhost:4010" 47 if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok { 48 baseURL = envURL 49 } 50 if !testutil.CheckTestServer(t, baseURL) { 51 return 52 } 53 client := anthropic.NewClient( 54 option.WithBaseURL(baseURL), 55 option.WithAPIKey("my-anthropic-api-key"), 56 ) 57 _, err := client.Beta.Vaults.Get( 58 context.TODO(), 59 "vlt_011CZkZDLs7fYzm1hXNPeRjv", 60 anthropic.BetaVaultGetParams{ 61 Betas: []anthropic.AnthropicBeta{anthropic.AnthropicBetaMessageBatches2024_09_24}, 62 WorkspaceID: anthropic.String("wrkspc_011CZkZaBF1tNoB5wlCeusgy"), 63 }, 64 ) 65 if err != nil { 66 var apierr *anthropic.Error 67 if errors.As(err, &apierr) { 68 t.Log(string(apierr.DumpRequest(true))) 69 } 70 t.Fatalf("err should be nil: %s", err.Error()) 71 } 72 } 73 74 func TestBetaVaultUpdateWithOptionalParams(t *testing.T) { 75 baseURL := "http://localhost:4010" 76 if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok { 77 baseURL = envURL 78 } 79 if !testutil.CheckTestServer(t, baseURL) { 80 return 81 } 82 client := anthropic.NewClient( 83 option.WithBaseURL(baseURL), 84 option.WithAPIKey("my-anthropic-api-key"), 85 ) 86 _, err := client.Beta.Vaults.Update( 87 context.TODO(), 88 "vlt_011CZkZDLs7fYzm1hXNPeRjv", 89 anthropic.BetaVaultUpdateParams{ 90 DisplayName: anthropic.String("Example vault"), 91 Metadata: map[string]string{ 92 "environment": "production", 93 }, 94 Betas: []anthropic.AnthropicBeta{anthropic.AnthropicBetaMessageBatches2024_09_24}, 95 WorkspaceID: anthropic.String("wrkspc_011CZkZaBF1tNoB5wlCeusgy"), 96 }, 97 ) 98 if err != nil { 99 var apierr *anthropic.Error 100 if errors.As(err, &apierr) { 101 t.Log(string(apierr.DumpRequest(true))) 102 } 103 t.Fatalf("err should be nil: %s", err.Error()) 104 } 105 } 106 107 func TestBetaVaultListWithOptionalParams(t *testing.T) { 108 t.Skip("buildURL drops path-level query params (SDK-4349)") 109 baseURL := "http://localhost:4010" 110 if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok { 111 baseURL = envURL 112 } 113 if !testutil.CheckTestServer(t, baseURL) { 114 return 115 } 116 client := anthropic.NewClient( 117 option.WithBaseURL(baseURL), 118 option.WithAPIKey("my-anthropic-api-key"), 119 ) 120 _, err := client.Beta.Vaults.List(context.TODO(), anthropic.BetaVaultListParams{ 121 IncludeArchived: anthropic.Bool(true), 122 Limit: anthropic.Int(0), 123 Page: anthropic.String("page"), 124 Betas: []anthropic.AnthropicBeta{anthropic.AnthropicBetaMessageBatches2024_09_24}, 125 WorkspaceID: anthropic.String("wrkspc_011CZkZaBF1tNoB5wlCeusgy"), 126 }) 127 if err != nil { 128 var apierr *anthropic.Error 129 if errors.As(err, &apierr) { 130 t.Log(string(apierr.DumpRequest(true))) 131 } 132 t.Fatalf("err should be nil: %s", err.Error()) 133 } 134 } 135 136 func TestBetaVaultDeleteWithOptionalParams(t *testing.T) { 137 baseURL := "http://localhost:4010" 138 if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok { 139 baseURL = envURL 140 } 141 if !testutil.CheckTestServer(t, baseURL) { 142 return 143 } 144 client := anthropic.NewClient( 145 option.WithBaseURL(baseURL), 146 option.WithAPIKey("my-anthropic-api-key"), 147 ) 148 _, err := client.Beta.Vaults.Delete( 149 context.TODO(), 150 "vlt_011CZkZDLs7fYzm1hXNPeRjv", 151 anthropic.BetaVaultDeleteParams{ 152 Betas: []anthropic.AnthropicBeta{anthropic.AnthropicBetaMessageBatches2024_09_24}, 153 WorkspaceID: anthropic.String("wrkspc_011CZkZaBF1tNoB5wlCeusgy"), 154 }, 155 ) 156 if err != nil { 157 var apierr *anthropic.Error 158 if errors.As(err, &apierr) { 159 t.Log(string(apierr.DumpRequest(true))) 160 } 161 t.Fatalf("err should be nil: %s", err.Error()) 162 } 163 } 164 165 func TestBetaVaultArchiveWithOptionalParams(t *testing.T) { 166 baseURL := "http://localhost:4010" 167 if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok { 168 baseURL = envURL 169 } 170 if !testutil.CheckTestServer(t, baseURL) { 171 return 172 } 173 client := anthropic.NewClient( 174 option.WithBaseURL(baseURL), 175 option.WithAPIKey("my-anthropic-api-key"), 176 ) 177 _, err := client.Beta.Vaults.Archive( 178 context.TODO(), 179 "vlt_011CZkZDLs7fYzm1hXNPeRjv", 180 anthropic.BetaVaultArchiveParams{ 181 Betas: []anthropic.AnthropicBeta{anthropic.AnthropicBetaMessageBatches2024_09_24}, 182 WorkspaceID: anthropic.String("wrkspc_011CZkZaBF1tNoB5wlCeusgy"), 183 }, 184 ) 185 if err != nil { 186 var apierr *anthropic.Error 187 if errors.As(err, &apierr) { 188 t.Log(string(apierr.DumpRequest(true))) 189 } 190 t.Fatalf("err should be nil: %s", err.Error()) 191 } 192 }