github.com/anthropics/anthropic-sdk-go@v1.70.1/skillversion_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 TestSkillVersionNewWithOptionalParams(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.Versions.New(
    31  		context.TODO(),
    32  		"skill_id",
    33  		anthropic.SkillVersionNewParams{
    34  			Files:       []io.Reader{io.Reader(bytes.NewBuffer([]byte("Example data")))},
    35  			WorkspaceID: anthropic.String("wrkspc_011CZkZaBF1tNoB5wlCeusgy"),
    36  		},
    37  	)
    38  	if err != nil {
    39  		var apierr *anthropic.Error
    40  		if errors.As(err, &apierr) {
    41  			t.Log(string(apierr.DumpRequest(true)))
    42  		}
    43  		t.Fatalf("err should be nil: %s", err.Error())
    44  	}
    45  }
    46  
    47  func TestSkillVersionGetWithOptionalParams(t *testing.T) {
    48  	baseURL := "http://localhost:4010"
    49  	if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok {
    50  		baseURL = envURL
    51  	}
    52  	if !testutil.CheckTestServer(t, baseURL) {
    53  		return
    54  	}
    55  	client := anthropic.NewClient(
    56  		option.WithBaseURL(baseURL),
    57  		option.WithAPIKey("my-anthropic-api-key"),
    58  	)
    59  	_, err := client.Skills.Versions.Get(
    60  		context.TODO(),
    61  		"version",
    62  		anthropic.SkillVersionGetParams{
    63  			SkillID:     "skill_id",
    64  			WorkspaceID: anthropic.String("wrkspc_011CZkZaBF1tNoB5wlCeusgy"),
    65  		},
    66  	)
    67  	if err != nil {
    68  		var apierr *anthropic.Error
    69  		if errors.As(err, &apierr) {
    70  			t.Log(string(apierr.DumpRequest(true)))
    71  		}
    72  		t.Fatalf("err should be nil: %s", err.Error())
    73  	}
    74  }
    75  
    76  func TestSkillVersionListWithOptionalParams(t *testing.T) {
    77  	baseURL := "http://localhost:4010"
    78  	if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok {
    79  		baseURL = envURL
    80  	}
    81  	if !testutil.CheckTestServer(t, baseURL) {
    82  		return
    83  	}
    84  	client := anthropic.NewClient(
    85  		option.WithBaseURL(baseURL),
    86  		option.WithAPIKey("my-anthropic-api-key"),
    87  	)
    88  	_, err := client.Skills.Versions.List(
    89  		context.TODO(),
    90  		"skill_id",
    91  		anthropic.SkillVersionListParams{
    92  			Limit:       anthropic.Int(1),
    93  			Page:        anthropic.String("page"),
    94  			WorkspaceID: anthropic.String("wrkspc_011CZkZaBF1tNoB5wlCeusgy"),
    95  		},
    96  	)
    97  	if err != nil {
    98  		var apierr *anthropic.Error
    99  		if errors.As(err, &apierr) {
   100  			t.Log(string(apierr.DumpRequest(true)))
   101  		}
   102  		t.Fatalf("err should be nil: %s", err.Error())
   103  	}
   104  }
   105  
   106  func TestSkillVersionDeleteWithOptionalParams(t *testing.T) {
   107  	baseURL := "http://localhost:4010"
   108  	if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok {
   109  		baseURL = envURL
   110  	}
   111  	if !testutil.CheckTestServer(t, baseURL) {
   112  		return
   113  	}
   114  	client := anthropic.NewClient(
   115  		option.WithBaseURL(baseURL),
   116  		option.WithAPIKey("my-anthropic-api-key"),
   117  	)
   118  	_, err := client.Skills.Versions.Delete(
   119  		context.TODO(),
   120  		"version",
   121  		anthropic.SkillVersionDeleteParams{
   122  			SkillID:     "skill_id",
   123  			WorkspaceID: anthropic.String("wrkspc_011CZkZaBF1tNoB5wlCeusgy"),
   124  		},
   125  	)
   126  	if err != nil {
   127  		var apierr *anthropic.Error
   128  		if errors.As(err, &apierr) {
   129  			t.Log(string(apierr.DumpRequest(true)))
   130  		}
   131  		t.Fatalf("err should be nil: %s", err.Error())
   132  	}
   133  }