github.com/anthropics/anthropic-sdk-go@v1.70.1/skill_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 "os" 11 "testing" 12 13 "github.com/anthropics/anthropic-sdk-go" 14 "github.com/anthropics/anthropic-sdk-go/internal/testutil" 15 "github.com/anthropics/anthropic-sdk-go/option" 16 ) 17 18 func TestSkillNewWithOptionalParams(t *testing.T) { 19 baseURL := "http://localhost:4010" 20 if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok { 21 baseURL = envURL 22 } 23 if !testutil.CheckTestServer(t, baseURL) { 24 return 25 } 26 client := anthropic.NewClient( 27 option.WithBaseURL(baseURL), 28 option.WithAPIKey("my-anthropic-api-key"), 29 ) 30 _, err := client.Skills.New(context.TODO(), anthropic.SkillNewParams{ 31 Files: []io.Reader{io.Reader(bytes.NewBuffer([]byte("Example data")))}, 32 DisplayName: anthropic.String("display_name"), 33 WorkspaceID: anthropic.String("wrkspc_011CZkZaBF1tNoB5wlCeusgy"), 34 }) 35 if err != nil { 36 var apierr *anthropic.Error 37 if errors.As(err, &apierr) { 38 t.Log(string(apierr.DumpRequest(true))) 39 } 40 t.Fatalf("err should be nil: %s", err.Error()) 41 } 42 } 43 44 func TestSkillGetWithOptionalParams(t *testing.T) { 45 baseURL := "http://localhost:4010" 46 if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok { 47 baseURL = envURL 48 } 49 if !testutil.CheckTestServer(t, baseURL) { 50 return 51 } 52 client := anthropic.NewClient( 53 option.WithBaseURL(baseURL), 54 option.WithAPIKey("my-anthropic-api-key"), 55 ) 56 _, err := client.Skills.Get( 57 context.TODO(), 58 "skill_id", 59 anthropic.SkillGetParams{ 60 WorkspaceID: anthropic.String("wrkspc_011CZkZaBF1tNoB5wlCeusgy"), 61 }, 62 ) 63 if err != nil { 64 var apierr *anthropic.Error 65 if errors.As(err, &apierr) { 66 t.Log(string(apierr.DumpRequest(true))) 67 } 68 t.Fatalf("err should be nil: %s", err.Error()) 69 } 70 } 71 72 func TestSkillListWithOptionalParams(t *testing.T) { 73 baseURL := "http://localhost:4010" 74 if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok { 75 baseURL = envURL 76 } 77 if !testutil.CheckTestServer(t, baseURL) { 78 return 79 } 80 client := anthropic.NewClient( 81 option.WithBaseURL(baseURL), 82 option.WithAPIKey("my-anthropic-api-key"), 83 ) 84 _, err := client.Skills.List(context.TODO(), anthropic.SkillListParams{ 85 Limit: anthropic.Int(1), 86 Page: anthropic.String("page"), 87 Source: anthropic.String("source"), 88 WorkspaceID: anthropic.String("wrkspc_011CZkZaBF1tNoB5wlCeusgy"), 89 }) 90 if err != nil { 91 var apierr *anthropic.Error 92 if errors.As(err, &apierr) { 93 t.Log(string(apierr.DumpRequest(true))) 94 } 95 t.Fatalf("err should be nil: %s", err.Error()) 96 } 97 } 98 99 func TestSkillDeleteWithOptionalParams(t *testing.T) { 100 baseURL := "http://localhost:4010" 101 if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok { 102 baseURL = envURL 103 } 104 if !testutil.CheckTestServer(t, baseURL) { 105 return 106 } 107 client := anthropic.NewClient( 108 option.WithBaseURL(baseURL), 109 option.WithAPIKey("my-anthropic-api-key"), 110 ) 111 _, err := client.Skills.Delete( 112 context.TODO(), 113 "skill_id", 114 anthropic.SkillDeleteParams{ 115 WorkspaceID: anthropic.String("wrkspc_011CZkZaBF1tNoB5wlCeusgy"), 116 }, 117 ) 118 if err != nil { 119 var apierr *anthropic.Error 120 if errors.As(err, &apierr) { 121 t.Log(string(apierr.DumpRequest(true))) 122 } 123 t.Fatalf("err should be nil: %s", err.Error()) 124 } 125 }