-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathintegration_test.go
More file actions
144 lines (116 loc) · 3.66 KB
/
integration_test.go
File metadata and controls
144 lines (116 loc) · 3.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
// Integration tests that require ELEVENLABS_API_KEY to be set.
// These tests verify that ogen-generated code correctly handles nullable fields
// returned by the ElevenLabs API.
//
// Run with:
// ELEVENLABS_API_KEY=your_key go test -v -tags=integration ./...
//
// These tests are placed in the root directory (not internal/api/) so they
// won't be overwritten when ogen regenerates code with --clean.
//go:build integration
package elevenlabs
import (
"context"
"os"
"strings"
"testing"
"time"
)
func skipIfNoAPIKey(t *testing.T) {
t.Helper()
if os.Getenv("ELEVENLABS_API_KEY") == "" {
t.Skip("ELEVENLABS_API_KEY not set, skipping integration test")
}
}
// skipOn401 skips the test if the error is a 401 unauthorized error.
// Some API keys may not have access to all endpoints.
func skipOn401(t *testing.T, err error) {
t.Helper()
if err != nil && strings.Contains(err.Error(), "401") {
t.Skipf("API key does not have access to this endpoint: %v", err)
}
}
// TestVoicesListNullHandling tests that the voices list endpoint correctly
// handles nullable fields like manual_verification, settings, and sharing.
// This catches ogen null handling issues like https://github.com/ogen-go/ogen/issues/1358
func TestVoicesListNullHandling(t *testing.T) {
skipIfNoAPIKey(t)
client, err := NewClient()
if err != nil {
t.Fatalf("NewClient: %v", err)
}
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
defer cancel()
voices, err := client.Voices().List(ctx)
if err != nil {
t.Fatalf("Voices().List: %v", err)
}
t.Logf("Successfully listed %d voices", len(voices))
// Verify we got some voices back
if len(voices) == 0 {
t.Log("Warning: no voices returned, but API call succeeded")
}
// Log some details to help debug if issues arise
for i, v := range voices {
if i >= 3 {
t.Logf("... and %d more voices", len(voices)-3)
break
}
t.Logf("Voice %d: %s (ID: %s)", i+1, v.Name, v.VoiceID)
}
}
// TestModelsListNullHandling tests that the models list endpoint correctly
// handles nullable fields.
func TestModelsListNullHandling(t *testing.T) {
skipIfNoAPIKey(t)
client, err := NewClient()
if err != nil {
t.Fatalf("NewClient: %v", err)
}
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
defer cancel()
models, err := client.Models().List(ctx)
skipOn401(t, err)
if err != nil {
t.Fatalf("Models().List: %v", err)
}
t.Logf("Successfully listed %d models", len(models))
if len(models) == 0 {
t.Log("Warning: no models returned, but API call succeeded")
}
}
// TestUserGetNullHandling tests that the user info endpoint correctly
// handles nullable fields in the subscription response.
func TestUserGetNullHandling(t *testing.T) {
skipIfNoAPIKey(t)
client, err := NewClient()
if err != nil {
t.Fatalf("NewClient: %v", err)
}
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
defer cancel()
user, err := client.User().GetInfo(ctx)
skipOn401(t, err)
if err != nil {
t.Fatalf("User().GetInfo: %v", err)
}
t.Logf("Successfully got user info for: %s", user.FirstName)
}
// TestHistoryListNullHandling tests that the history list endpoint correctly
// handles nullable fields.
func TestHistoryListNullHandling(t *testing.T) {
skipIfNoAPIKey(t)
client, err := NewClient()
if err != nil {
t.Fatalf("NewClient: %v", err)
}
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
defer cancel()
// Just fetch first page with a small limit
history, err := client.History().List(ctx, &HistoryListOptions{PageSize: 10})
skipOn401(t, err)
if err != nil {
t.Fatalf("History().List: %v", err)
}
t.Logf("Successfully listed %d history items", len(history.Items))
}