github.com/anthropics/anthropic-sdk-go@v1.70.1/betaskill_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 TestBetaSkillNewWithOptionalParams(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.Beta.Skills.New(context.TODO(), anthropic.BetaSkillNewParams{
    31  		Files:       []io.Reader{io.Reader(bytes.NewBuffer([]byte("Example data")))},
    32  		DisplayName: anthropic.String("display_name"),
    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 TestBetaSkillGetWithOptionalParams(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.Skills.Get(
    58  		context.TODO(),
    59  		"skill_id",
    60  		anthropic.BetaSkillGetParams{
    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 TestBetaSkillListWithOptionalParams(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.Skills.List(context.TODO(), anthropic.BetaSkillListParams{
    87  		Limit:       anthropic.Int(1),
    88  		Page:        anthropic.String("page"),
    89  		Source:      anthropic.String("source"),
    90  		Betas:       []anthropic.AnthropicBeta{anthropic.AnthropicBetaMessageBatches2024_09_24},
    91  		WorkspaceID: anthropic.String("wrkspc_011CZkZaBF1tNoB5wlCeusgy"),
    92  	})
    93  	if err != nil {
    94  		var apierr *anthropic.Error
    95  		if errors.As(err, &apierr) {
    96  			t.Log(string(apierr.DumpRequest(true)))
    97  		}
    98  		t.Fatalf("err should be nil: %s", err.Error())
    99  	}
   100  }
   101  
   102  func TestBetaSkillDeleteWithOptionalParams(t *testing.T) {
   103  	baseURL := "http://localhost:4010"
   104  	if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok {
   105  		baseURL = envURL
   106  	}
   107  	if !testutil.CheckTestServer(t, baseURL) {
   108  		return
   109  	}
   110  	client := anthropic.NewClient(
   111  		option.WithBaseURL(baseURL),
   112  		option.WithAPIKey("my-anthropic-api-key"),
   113  	)
   114  	_, err := client.Beta.Skills.Delete(
   115  		context.TODO(),
   116  		"skill_id",
   117  		anthropic.BetaSkillDeleteParams{
   118  			Betas:       []anthropic.AnthropicBeta{anthropic.AnthropicBetaMessageBatches2024_09_24},
   119  			WorkspaceID: anthropic.String("wrkspc_011CZkZaBF1tNoB5wlCeusgy"),
   120  		},
   121  	)
   122  	if err != nil {
   123  		var apierr *anthropic.Error
   124  		if errors.As(err, &apierr) {
   125  			t.Log(string(apierr.DumpRequest(true)))
   126  		}
   127  		t.Fatalf("err should be nil: %s", err.Error())
   128  	}
   129  }