Skip to content

Commit c8592bb

Browse files
authored
Merge pull request #358 from k1LoW/debug-test
chore: Define BuildTestOptions for debugging on testing
2 parents faf0ff4 + aa71917 commit c8592bb

File tree

4 files changed

+32
-6
lines changed

4 files changed

+32
-6
lines changed

integration_action_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,8 @@ func TestAction(t *testing.T) {
165165
// Acquire a presentation from the pool
166166
presentationID := AcquirePresentation(t)
167167

168-
d, err := New(ctx, WithPresentationID(presentationID))
168+
opts := append([]Option{WithPresentationID(presentationID)}, BuildTestOptions()...)
169+
d, err := New(ctx, opts...)
169170
if err != nil {
170171
t.Fatal(err)
171172
}

integration_apply_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ func TestApply(t *testing.T) {
2929
// Acquire a presentation from the pool
3030
presentationID := AcquirePresentation(t)
3131

32-
d, err := New(ctx, WithPresentationID(presentationID))
32+
opts := append([]Option{WithPresentationID(presentationID)}, BuildTestOptions()...)
33+
d, err := New(ctx, opts...)
3334
if err != nil {
3435
t.Fatal(err)
3536
}

integration_test.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,8 @@ func TestApplyMarkdown(t *testing.T) {
8181
if err != nil {
8282
t.Fatal(err)
8383
}
84-
d, err := deck.New(ctx, deck.WithPresentationID(presentationID))
84+
opts := append([]deck.Option{deck.WithPresentationID(presentationID)}, deck.BuildTestOptions()...)
85+
d, err := deck.New(ctx, opts...)
8586
if err != nil {
8687
t.Fatal(err)
8788
}
@@ -211,7 +212,8 @@ func TestRoundTripSlidesToGoogleSlidesPresentationAndBack(t *testing.T) {
211212
if err != nil {
212213
t.Fatal(err)
213214
}
214-
d, err := deck.New(ctx, deck.WithPresentationID(presentationID))
215+
opts := append([]deck.Option{deck.WithPresentationID(presentationID)}, deck.BuildTestOptions()...)
216+
d, err := deck.New(ctx, opts...)
215217
if err != nil {
216218
t.Fatal(err)
217219
}

poolutil_test.go

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"context"
55
"fmt"
66
"log"
7+
"log/slog"
78
"os"
89
"sync"
910
"testing"
@@ -16,6 +17,24 @@ const (
1617
titleForTest = "For deck integration test (Unless you are testing the deck, you can delete this file without any problems)"
1718
)
1819

20+
// BuildTestOptions creates test options with logger if DECK_TEST_DEBUG is set.
21+
func BuildTestOptions() []Option {
22+
var opts []Option
23+
24+
if os.Getenv("DECK_TEST_DEBUG") != "" {
25+
logger := slog.New(slog.NewTextHandler(os.Stdout, &slog.HandlerOptions{
26+
Level: slog.LevelDebug,
27+
}))
28+
opts = append(opts, WithLogger(logger))
29+
}
30+
31+
if testFolderID := os.Getenv("DECK_TEST_FOLDER_ID"); testFolderID != "" {
32+
opts = append(opts, WithFolderID(testFolderID))
33+
}
34+
35+
return opts
36+
}
37+
1938
// global presentation pool instance.
2039
var presentationPool chan string
2140

@@ -34,7 +53,8 @@ func initPresentationPool(ctx context.Context) ([]string, error) {
3453

3554
for i := range parallelCount {
3655
eg.Go(func() error {
37-
d, err := CreateFrom(egCtx, basePresentationID)
56+
opts := BuildTestOptions()
57+
d, err := CreateFrom(egCtx, basePresentationID, opts...)
3858
if err != nil {
3959
return fmt.Errorf("failed to create presentation %d: %w", i, err)
4060
}
@@ -88,7 +108,9 @@ func TestMain(m *testing.M) {
88108
wg.Add(1)
89109
go func(presentationID string) {
90110
defer wg.Done()
91-
if err := Delete(context.Background(), presentationID); err != nil {
111+
112+
opts := BuildTestOptions()
113+
if err := Delete(context.Background(), presentationID, opts...); err != nil {
92114
log.Printf("Failed to delete presentation %s: %v\n", presentationID, err)
93115
}
94116
}(id)

0 commit comments

Comments
 (0)