Repository navigation
Expand file tree
/
Copy pathexec_test.go
More file actions
725 lines (626 loc) · 19.6 KB
/
Copy pathexec_test.go
File metadata and controls
725 lines (626 loc) · 19.6 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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
package sprites
import (
"bytes"
"context"
"errors"
"fmt"
"io"
"net/http"
"net/http/httptest"
"os"
"strings"
"syscall"
"testing"
"testing/iotest"
"time"
"github.com/gorilla/websocket"
)
type recordedStreamFrame struct {
stream StreamID
data []byte
}
type recordingStreamSocket struct {
frames []recordedStreamFrame
}
func (w *recordingStreamSocket) WriteStream(stream StreamID, data []byte) error {
w.frames = append(w.frames, recordedStreamFrame{
stream: stream,
data: bytes.Clone(data),
})
return nil
}
func TestCopyNonTTYStdinUsesStreamFrames(t *testing.T) {
socket := &recordingStreamSocket{}
n, err := copyNonTTYStdin(socket, strings.NewReader("hello\n"))
if err != nil {
t.Fatalf("copyNonTTYStdin() error = %v", err)
}
if n != 6 {
t.Fatalf("copyNonTTYStdin() copied %d bytes, want 6", n)
}
if len(socket.frames) != 2 {
t.Fatalf("got %d frames, want stdin and EOF frames", len(socket.frames))
}
if socket.frames[0].stream != StreamStdin || string(socket.frames[0].data) != "hello\n" {
t.Errorf("stdin frame = %#v, want stream %d with payload %q", socket.frames[0], StreamStdin, "hello\n")
}
if socket.frames[1].stream != StreamStdinEOF || len(socket.frames[1].data) != 0 {
t.Errorf("EOF frame = %#v, want empty stream %d frame", socket.frames[1], StreamStdinEOF)
}
}
func TestCopyNonTTYStdinSendsEOFAfterReadError(t *testing.T) {
socket := &recordingStreamSocket{}
copyErr := errors.New("read failed")
stdin := io.MultiReader(strings.NewReader("hello"), iotest.ErrReader(copyErr))
n, err := copyNonTTYStdin(socket, stdin)
if !errors.Is(err, copyErr) {
t.Fatalf("copyNonTTYStdin() error = %v, want %v", err, copyErr)
}
if n != 5 {
t.Fatalf("copyNonTTYStdin() copied %d bytes, want 5", n)
}
if len(socket.frames) != 2 {
t.Fatalf("got %d frames, want stdin and EOF frames", len(socket.frames))
}
if socket.frames[0].stream != StreamStdin || string(socket.frames[0].data) != "hello" {
t.Errorf("stdin frame = %#v, want stream %d with payload %q", socket.frames[0], StreamStdin, "hello")
}
if socket.frames[1].stream != StreamStdinEOF || len(socket.frames[1].data) != 0 {
t.Errorf("EOF frame = %#v, want empty stream %d frame", socket.frames[1], StreamStdinEOF)
}
}
func TestCmdWaitPreservesWebSocketReadError(t *testing.T) {
const closeReason = "transport interrupted"
serverErr := make(chan error, 1)
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
conn, err := (&websocket.Upgrader{}).Upgrade(w, r, nil)
if err != nil {
serverErr <- err
return
}
defer conn.Close()
serverErr <- conn.WriteControl(
websocket.CloseMessage,
websocket.FormatCloseMessage(websocket.CloseInternalServerErr, closeReason),
time.Now().Add(time.Second),
)
}))
defer server.Close()
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()
req, err := http.NewRequestWithContext(ctx, http.MethodGet, "ws"+strings.TrimPrefix(server.URL, "http"), nil)
if err != nil {
t.Fatalf("NewRequestWithContext() error = %v", err)
}
stdinReader, stdinWriter := io.Pipe()
defer stdinReader.Close()
defer stdinWriter.Close()
wsCmd := newWSCmdContext(ctx, req, "true")
wsCmd.Stdin = stdinReader
if err := wsCmd.Start(); err != nil {
t.Fatalf("wsCmd.Start() error = %v", err)
}
cmd := &Cmd{started: true, wsCmd: wsCmd}
err = cmd.Wait()
_ = stdinWriter.Close()
var closeErr *websocket.CloseError
if !errors.As(err, &closeErr) {
t.Fatalf("Cmd.Wait() error = %v (%T), want *websocket.CloseError", err, err)
}
if closeErr.Code != websocket.CloseInternalServerErr {
t.Errorf("close code = %d, want %d", closeErr.Code, websocket.CloseInternalServerErr)
}
if closeErr.Text != closeReason {
t.Errorf("close reason = %q, want %q", closeErr.Text, closeReason)
}
if err := <-serverErr; err != nil {
t.Fatalf("server close error = %v", err)
}
}
func TestCmdWaitReturnsExecProtocolError(t *testing.T) {
const protocolError = "cannot resume output at byte 0: earliest retained byte is 1"
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
conn, err := (&websocket.Upgrader{}).Upgrade(w, r, nil)
if err != nil {
return
}
defer conn.Close()
_ = conn.WriteJSON(map[string]string{
"type": "error",
"error": protocolError,
})
}))
defer server.Close()
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()
req, err := http.NewRequestWithContext(ctx, http.MethodGet, "ws"+strings.TrimPrefix(server.URL, "http"), nil)
if err != nil {
t.Fatalf("NewRequestWithContext() error = %v", err)
}
wsCmd := newWSCmdContext(ctx, req, "true")
if err := wsCmd.Start(); err != nil {
t.Fatalf("wsCmd.Start() error = %v", err)
}
cmd := &Cmd{started: true, wsCmd: wsCmd}
if err := cmd.Wait(); err == nil || err.Error() != protocolError {
t.Fatalf("Cmd.Wait() error = %v, want %q", err, protocolError)
}
}
func TestCmdString(t *testing.T) {
client := New("test-token", WithBaseURL("http://localhost:8080"))
sprite := client.Sprite("my-sprite")
cmd := sprite.Command("echo", "hello", "world")
str := cmd.String()
if str != "echo [hello world]" {
t.Errorf("String() = %q, want %q", str, "echo [hello world]")
}
}
func TestCmdBuildWebSocketURL(t *testing.T) {
outputOffset := int64(42)
tests := []struct {
name string
spriteName string
serverVersion string
useLegacyEndpoint bool
cmd *Cmd
wantPath string
wantQuery map[string][]string
}{
{
name: "basic command",
spriteName: "my-sprite",
cmd: &Cmd{
Path: "echo",
Args: []string{"echo", "hello"},
},
wantPath: "/v1/sprites/my-sprite/exec",
wantQuery: map[string][]string{
"cmd": {"echo", "hello"},
"path": {"echo"},
},
},
{
name: "command with environment",
spriteName: "test-sprite",
cmd: &Cmd{
Path: "env",
Args: []string{"env"},
Env: []string{"FOO=bar", "BAZ=qux"},
},
wantPath: "/v1/sprites/test-sprite/exec",
wantQuery: map[string][]string{
"cmd": {"env"},
"path": {"env"},
"env": {"FOO=bar", "BAZ=qux"},
},
},
{
name: "command with working dir",
spriteName: "my-sprite",
cmd: &Cmd{
Path: "pwd",
Args: []string{"pwd"},
Dir: "/tmp",
},
wantPath: "/v1/sprites/my-sprite/exec",
wantQuery: map[string][]string{
"cmd": {"pwd"},
"path": {"pwd"},
"dir": {"/tmp"},
},
},
{
name: "command with TTY",
spriteName: "my-sprite",
cmd: &Cmd{
Path: "bash",
Args: []string{"bash"},
tty: true,
ttySize: &ttySize{Rows: 24, Cols: 80},
},
wantPath: "/v1/sprites/my-sprite/exec",
wantQuery: map[string][]string{
"cmd": {"bash"},
"path": {"bash"},
"tty": {"true"},
"rows": {"24"},
"cols": {"80"},
},
},
{
name: "command with no stdin",
spriteName: "my-sprite",
cmd: &Cmd{
Path: "echo",
Args: []string{"echo", "hello"},
Stdin: nil,
},
wantPath: "/v1/sprites/my-sprite/exec",
wantQuery: map[string][]string{
"cmd": {"echo", "hello"},
"path": {"echo"},
"stdin": {"false"},
},
},
{
name: "command with stdin set",
spriteName: "my-sprite",
cmd: &Cmd{
Path: "cat",
Args: []string{"cat"},
Stdin: strings.NewReader("test input"),
},
wantPath: "/v1/sprites/my-sprite/exec",
wantQuery: map[string][]string{
"cmd": {"cat"},
"path": {"cat"},
"stdin": {"true"},
},
},
{
name: "attach with path format (new servers)",
spriteName: "my-sprite",
serverVersion: "0.1.0", // Release version supports path attach
cmd: &Cmd{
sessionID: "abc123",
outputOffset: &outputOffset,
},
wantPath: "/v1/sprites/my-sprite/exec/abc123",
wantQuery: map[string][]string{
"output_offset": {"42"},
"stdin": {"false"},
},
},
{
name: "attach with query format (legacy servers)",
spriteName: "my-sprite",
useLegacyEndpoint: true,
cmd: &Cmd{
sessionID: "abc123",
},
wantPath: "/v1/sprites/my-sprite/exec",
wantQuery: map[string][]string{
"id": {"abc123"},
"stdin": {"false"},
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
client := New("test-token", WithBaseURL("http://localhost:8080"))
if tt.serverVersion != "" {
client.spriteVersion.Store(tt.serverVersion)
}
sprite := client.Sprite(tt.spriteName)
sprite.useLegacyExecEndpoint = tt.useLegacyEndpoint
tt.cmd.sprite = sprite
u, err := tt.cmd.buildWebSocketURL()
if err != nil {
t.Fatalf("buildWebSocketURL() error = %v", err)
}
// Check scheme conversion
if u.Scheme != "ws" {
t.Errorf("scheme = %q, want %q", u.Scheme, "ws")
}
// Check path
if u.Path != tt.wantPath {
t.Errorf("path = %q, want %q", u.Path, tt.wantPath)
}
// Check query parameters
query := u.Query()
for key, wantValues := range tt.wantQuery {
gotValues := query[key]
if len(gotValues) != len(wantValues) {
t.Errorf("query[%q] has %d values, want %d", key, len(gotValues), len(wantValues))
continue
}
for i, want := range wantValues {
if gotValues[i] != want {
t.Errorf("query[%q][%d] = %q, want %q", key, i, gotValues[i], want)
}
}
}
// Verify stdin parameter behavior
// If Stdin is nil, stdin=false should be present
// If Stdin is set, stdin=true should be present
stdinParam := query.Get("stdin")
if tt.cmd.Stdin == nil {
if stdinParam != "false" {
t.Errorf("Expected stdin=false when Stdin is nil, got stdin=%q", stdinParam)
}
} else {
if stdinParam != "true" {
t.Errorf("Expected stdin=true when Stdin is set, got stdin=%q", stdinParam)
}
}
})
}
}
func TestCmdContextCancellation(t *testing.T) {
client := New("test-token", WithBaseURL("http://localhost:8080"))
sprite := client.Sprite("my-sprite")
// Test that nil context panics
defer func() {
if r := recover(); r == nil {
t.Error("CommandContext with nil context should panic")
}
}()
//nolint:staticcheck // We're testing that nil context panics
sprite.CommandContext(nil, "echo")
}
func TestExitError(t *testing.T) {
err := &ExitError{Code: 42}
if err.Error() != "exit status 42" {
t.Errorf("Error() = %q, want %q", err.Error(), "exit status 42")
}
if err.ExitCode() != 42 {
t.Errorf("ExitCode() = %d, want %d", err.ExitCode(), 42)
}
// Test Sys() returns proper wait status
if status, ok := err.Sys().(syscall.WaitStatus); ok {
if status.ExitStatus() != 42 {
t.Errorf("Sys().ExitStatus() = %d, want %d", status.ExitStatus(), 42)
}
} else {
t.Error("Sys() should return syscall.WaitStatus")
}
}
func TestCmdValidation(t *testing.T) {
client := New("test-token", WithBaseURL("http://localhost:8080"))
sprite := client.Sprite("my-sprite")
cmd := sprite.Command("echo", "test")
// Test that various operations succeed before Start
if _, err := cmd.StdinPipe(); err != nil {
t.Error("StdinPipe should succeed before Start")
}
cmd = sprite.Command("echo", "test")
if _, err := cmd.StdoutPipe(); err != nil {
t.Error("StdoutPipe should succeed before Start")
}
cmd = sprite.Command("echo", "test")
if _, err := cmd.StderrPipe(); err != nil {
t.Error("StderrPipe should succeed before Start")
}
// Test double pipe creation fails
cmd = sprite.Command("echo", "test")
cmd.Stdin = os.Stdin
if _, err := cmd.StdinPipe(); err == nil {
t.Error("StdinPipe should fail when Stdin is already set")
}
cmd = sprite.Command("echo", "test")
cmd.Stdout = os.Stdout
if _, err := cmd.StdoutPipe(); err == nil {
t.Error("StdoutPipe should fail when Stdout is already set")
}
cmd = sprite.Command("echo", "test")
cmd.Stderr = os.Stderr
if _, err := cmd.StderrPipe(); err == nil {
t.Error("StderrPipe should fail when Stderr is already set")
}
}
// TestSpriteLifecycle tests the complete lifecycle of a sprite with exec:
// 1. Create a sprite (or use existing if SPRITE_TEST_NAME is set)
// 2. Run exec commands on it
// 3. Destroy the sprite (unless SPRITE_TEST_NAME is set)
func TestSpriteLifecycle(t *testing.T) {
// Skip if no test token is provided
token := os.Getenv("SPRITES_TEST_TOKEN")
if token == "" {
t.Skip("SPRITES_TEST_TOKEN environment variable not set")
}
// Create client
client := New(token)
// Check if we should use an existing sprite or create a new one
spriteName := os.Getenv("SPRITE_TEST_NAME")
useExistingSprite := spriteName != ""
if !useExistingSprite {
// Generate unique sprite name to avoid conflicts
spriteName = fmt.Sprintf("test-sprite-%d", time.Now().UnixNano())
} else {
t.Logf("Using existing sprite: %s", spriteName)
}
// Test 1: Create sprite (skip if using existing sprite)
if !useExistingSprite {
t.Run("CreateSprite", func(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), 2*time.Minute)
defer cancel()
sprite, err := client.CreateSprite(ctx, spriteName, nil)
if err != nil {
t.Fatalf("Failed to create sprite: %v", err)
}
if sprite.Name() != spriteName {
t.Errorf("Expected sprite name %q, got %q", spriteName, sprite.Name())
}
// Verify sprite was created by getting it
retrievedSprite, err := client.GetSprite(ctx, spriteName)
if err != nil {
t.Fatalf("Failed to retrieve created sprite: %v", err)
}
if retrievedSprite.Name() != spriteName {
t.Errorf("Expected retrieved sprite name %q, got %q", spriteName, retrievedSprite.Name())
}
t.Logf("Successfully created sprite: %s", spriteName)
})
} else {
t.Logf("Skipping sprite creation (using existing sprite from SPRITE_TEST_NAME: %s)", spriteName)
}
// Test 2: Run exec commands
t.Run("ExecCommands", func(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
defer cancel()
sprite := client.Sprite(spriteName)
// Test simple echo command
t.Run("EchoCommand", func(t *testing.T) {
cmd := sprite.CommandContext(ctx, "echo", "hello", "world")
output, err := cmd.Output()
if err != nil {
t.Fatalf("Echo command failed: %v", err)
}
expected := "hello world\n"
if string(output) != expected {
t.Errorf("Expected output %q, got %q", expected, string(output))
}
t.Logf("Echo command output: %q", string(output))
})
// Test pwd command
t.Run("PwdCommand", func(t *testing.T) {
cmd := sprite.CommandContext(ctx, "pwd")
output, err := cmd.Output()
if err != nil {
t.Fatalf("Pwd command failed: %v", err)
}
// Should be in the home directory
if !strings.Contains(string(output), "/home") {
t.Errorf("Expected pwd to contain /home, got %q", string(output))
}
t.Logf("Pwd command output: %q", string(output))
})
// Test command with environment variables
t.Run("EnvCommand", func(t *testing.T) {
cmd := sprite.CommandContext(ctx, "env")
cmd.Env = []string{"TEST_VAR=hello", "ANOTHER_VAR=world"}
output, err := cmd.Output()
if err != nil {
t.Fatalf("Env command failed: %v", err)
}
outputStr := string(output)
if !strings.Contains(outputStr, "TEST_VAR=hello") {
t.Error("Expected output to contain TEST_VAR=hello")
}
if !strings.Contains(outputStr, "ANOTHER_VAR=world") {
t.Error("Expected output to contain ANOTHER_VAR=world")
}
t.Logf("Env command found expected variables")
})
// Test command with working directory
t.Run("DirCommand", func(t *testing.T) {
cmd := sprite.CommandContext(ctx, "pwd")
cmd.Dir = "/tmp"
output, err := cmd.Output()
if err != nil {
t.Fatalf("Dir command failed: %v", err)
}
expected := "/tmp\n"
if string(output) != expected {
t.Errorf("Expected output %q, got %q", expected, string(output))
}
t.Logf("Dir command output: %q", string(output))
})
// Test command that returns non-zero exit code
t.Run("ErrorCommand", func(t *testing.T) {
cmd := sprite.CommandContext(ctx, "sh", "-c", "exit 42")
err := cmd.Run()
if err == nil {
t.Error("Expected command to return error")
}
exitErr, ok := err.(*ExitError)
if !ok {
t.Errorf("Expected ExitError, got %T", err)
} else if exitErr.ExitCode() != 42 {
t.Errorf("Expected exit code 42, got %d", exitErr.ExitCode())
} else {
t.Logf("Error command failed as expected with exit code %d", exitErr.ExitCode())
}
})
// Test command with pipes
t.Run("PipeCommand", func(t *testing.T) {
cmd := sprite.CommandContext(ctx, "cat")
// Set up stdin pipe
stdin, err := cmd.StdinPipe()
if err != nil {
t.Fatalf("Failed to create stdin pipe: %v", err)
}
// Start command
err = cmd.Start()
if err != nil {
t.Fatalf("Failed to start command: %v", err)
}
// Write to stdin
testInput := "hello from pipe test\n"
_, err = stdin.Write([]byte(testInput))
if err != nil {
t.Fatalf("Failed to write to stdin: %v", err)
}
stdin.Close()
// Wait for command to complete
err = cmd.Wait()
if err != nil {
t.Fatalf("Command failed: %v", err)
}
t.Logf("Pipe test completed successfully")
})
// Test TTY mode with tty command
t.Run("TTYCommand", func(t *testing.T) {
cmd := sprite.CommandContext(ctx, "tty")
cmd.SetTTY(true)
cmd.SetTTYSize(24, 80)
output, err := cmd.Output()
if err != nil {
t.Fatalf("TTY command failed: %v", err)
}
outputStr := string(output)
// When TTY mode is enabled, tty command should output a device path
if !strings.Contains(outputStr, "/dev/") {
t.Errorf("Expected TTY output to contain /dev/, got %q", outputStr)
}
t.Logf("TTY command output: %q", outputStr)
})
// Test non-TTY mode
t.Run("NonTTYCommand", func(t *testing.T) {
cmd := sprite.CommandContext(ctx, "tty")
// Don't enable TTY mode
output, err := cmd.CombinedOutput()
// tty command exits with status 1 when not connected to a tty
if err != nil {
if exitErr, ok := err.(*ExitError); !ok || exitErr.ExitCode() != 1 {
t.Fatalf("Non-TTY command failed with unexpected error: %v", err)
}
}
outputStr := string(output)
// When TTY mode is disabled, tty command should output "not a tty"
if !strings.Contains(outputStr, "not a tty") {
t.Errorf("Expected non-TTY output to contain 'not a tty', got %q", outputStr)
}
t.Logf("Non-TTY command output: %q", outputStr)
})
// Test interactive command with TTY
t.Run("InteractiveCommand", func(t *testing.T) {
// Test that a command requiring TTY works (e.g., reading terminal size)
cmd := sprite.CommandContext(ctx, "sh", "-c", "stty size")
cmd.SetTTY(true)
cmd.SetTTYSize(24, 80)
output, err := cmd.Output()
if err != nil {
t.Fatalf("Interactive TTY command failed: %v", err)
}
outputStr := strings.TrimSpace(string(output))
// stty size should output "24 80" when TTY is set to those dimensions
if outputStr != "24 80" {
t.Errorf("Expected stty size to output '24 80', got %q", outputStr)
}
t.Logf("Terminal size output: %q", outputStr)
})
})
// Test 3: Destroy sprite (skip if using existing sprite)
if !useExistingSprite {
t.Run("DestroySprite", func(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), 2*time.Minute)
defer cancel()
err := client.DeleteSprite(ctx, spriteName)
if err != nil {
t.Fatalf("Failed to destroy sprite: %v", err)
}
// Verify sprite was destroyed by trying to get it
_, err = client.GetSprite(ctx, spriteName)
if err == nil {
t.Error("Expected sprite to be deleted, but GetSprite succeeded")
} else {
// Sprite was successfully deleted, we expect some kind of error
t.Logf("Sprite deletion verified (got expected error: %v)", err)
}
t.Logf("Successfully destroyed sprite: %s", spriteName)
})
} else {
t.Logf("Skipping sprite destruction (using existing sprite from SPRITE_TEST_NAME: %s)", spriteName)
}
}