github.com/anthropics/anthropic-sdk-go@v1.70.1/betaskillversion_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 "bytes" 7 "context" 8 "errors" 9 "io" 10 "net/http" 11 "net/http/httptest" 12 "os" 13 "testing" 14 15 "github.com/anthropics/anthropic-sdk-go" 16 "github.com/anthropics/anthropic-sdk-go/internal/testutil" 17 "github.com/anthropics/anthropic-sdk-go/option" 18 ) 19 20 func TestBetaSkillVersionNewWithOptionalParams(t *testing.T) { 21 baseURL := "http://localhost:4010" 22 if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok { 23 baseURL = envURL 24 } 25 if !testutil.CheckTestServer(t, baseURL) { 26 return 27 } 28 client := anthropic.NewClient( 29 option.WithBaseURL(baseURL), 30 option.WithAPIKey("my-anthropic-api-key"), 31 ) 32 _, err := client.Beta.Skills.Versions.New( 33 context.TODO(), 34 "skill_id", 35 anthropic.BetaSkillVersionNewParams{ 36 Files: []io.Reader{io.Reader(bytes.NewBuffer([]byte("Example data")))}, 37 Betas: []anthropic.AnthropicBeta{anthropic.AnthropicBetaMessageBatches2024_09_24}, 38 WorkspaceID: anthropic.String("wrkspc_011CZkZaBF1tNoB5wlCeusgy"), 39 }, 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 TestBetaSkillVersionGetWithOptionalParams(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.Skills.Versions.Get( 63 context.TODO(), 64 "version", 65 anthropic.BetaSkillVersionGetParams{ 66 SkillID: "skill_id", 67 Betas: []anthropic.AnthropicBeta{anthropic.AnthropicBetaMessageBatches2024_09_24}, 68 WorkspaceID: anthropic.String("wrkspc_011CZkZaBF1tNoB5wlCeusgy"), 69 }, 70 ) 71 if err != nil { 72 var apierr *anthropic.Error 73 if errors.As(err, &apierr) { 74 t.Log(string(apierr.DumpRequest(true))) 75 } 76 t.Fatalf("err should be nil: %s", err.Error()) 77 } 78 } 79 80 func TestBetaSkillVersionListWithOptionalParams(t *testing.T) { 81 baseURL := "http://localhost:4010" 82 if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok { 83 baseURL = envURL 84 } 85 if !testutil.CheckTestServer(t, baseURL) { 86 return 87 } 88 client := anthropic.NewClient( 89 option.WithBaseURL(baseURL), 90 option.WithAPIKey("my-anthropic-api-key"), 91 ) 92 _, err := client.Beta.Skills.Versions.List( 93 context.TODO(), 94 "skill_id", 95 anthropic.BetaSkillVersionListParams{ 96 Limit: anthropic.Int(1), 97 Page: anthropic.String("page"), 98 Betas: []anthropic.AnthropicBeta{anthropic.AnthropicBetaMessageBatches2024_09_24}, 99 WorkspaceID: anthropic.String("wrkspc_011CZkZaBF1tNoB5wlCeusgy"), 100 }, 101 ) 102 if err != nil { 103 var apierr *anthropic.Error 104 if errors.As(err, &apierr) { 105 t.Log(string(apierr.DumpRequest(true))) 106 } 107 t.Fatalf("err should be nil: %s", err.Error()) 108 } 109 } 110 111 func TestBetaSkillVersionDeleteWithOptionalParams(t *testing.T) { 112 baseURL := "http://localhost:4010" 113 if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok { 114 baseURL = envURL 115 } 116 if !testutil.CheckTestServer(t, baseURL) { 117 return 118 } 119 client := anthropic.NewClient( 120 option.WithBaseURL(baseURL), 121 option.WithAPIKey("my-anthropic-api-key"), 122 ) 123 _, err := client.Beta.Skills.Versions.Delete( 124 context.TODO(), 125 "version", 126 anthropic.BetaSkillVersionDeleteParams{ 127 SkillID: "skill_id", 128 Betas: []anthropic.AnthropicBeta{anthropic.AnthropicBetaMessageBatches2024_09_24}, 129 WorkspaceID: anthropic.String("wrkspc_011CZkZaBF1tNoB5wlCeusgy"), 130 }, 131 ) 132 if err != nil { 133 var apierr *anthropic.Error 134 if errors.As(err, &apierr) { 135 t.Log(string(apierr.DumpRequest(true))) 136 } 137 t.Fatalf("err should be nil: %s", err.Error()) 138 } 139 } 140 141 func TestBetaSkillVersionDownloadWithOptionalParams(t *testing.T) { 142 server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { 143 w.WriteHeader(200) 144 w.Write([]byte("abc")) 145 })) 146 defer server.Close() 147 baseURL := server.URL 148 client := anthropic.NewClient( 149 option.WithBaseURL(baseURL), 150 option.WithAPIKey("my-anthropic-api-key"), 151 ) 152 resp, err := client.Beta.Skills.Versions.Download( 153 context.TODO(), 154 "version", 155 anthropic.BetaSkillVersionDownloadParams{ 156 SkillID: "skill_id", 157 Betas: []anthropic.AnthropicBeta{anthropic.AnthropicBetaMessageBatches2024_09_24}, 158 WorkspaceID: anthropic.String("wrkspc_011CZkZaBF1tNoB5wlCeusgy"), 159 }, 160 ) 161 if err != nil { 162 var apierr *anthropic.Error 163 if errors.As(err, &apierr) { 164 t.Log(string(apierr.DumpRequest(true))) 165 } 166 t.Fatalf("err should be nil: %s", err.Error()) 167 } 168 defer resp.Body.Close() 169 170 b, err := io.ReadAll(resp.Body) 171 if err != nil { 172 var apierr *anthropic.Error 173 if errors.As(err, &apierr) { 174 t.Log(string(apierr.DumpRequest(true))) 175 } 176 t.Fatalf("err should be nil: %s", err.Error()) 177 } 178 if !bytes.Equal(b, []byte("abc")) { 179 t.Fatalf("return value not %s: %s", "abc", b) 180 } 181 }