Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
708 changes: 249 additions & 459 deletions builder_test.go

Large diffs are not rendered by default.

43 changes: 13 additions & 30 deletions column_inference_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ package filesql

import (
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

func TestInferColumnType(t *testing.T) {
Expand Down Expand Up @@ -107,9 +110,7 @@ func TestInferColumnType(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
result := inferColumnType(tt.values)
if result != tt.expected {
t.Errorf("inferColumnType(%v) = %v, want %v", tt.values, result, tt.expected)
}
assert.Equal(t, tt.expected, result, "inferColumnType failed for values: %v", tt.values)
})
}
}
Expand All @@ -135,17 +136,11 @@ func TestInferColumnsInfo(t *testing.T) {
{Name: "hire_date", Type: columnTypeDatetime},
}

if len(result) != len(expected) {
t.Fatalf("Expected %d columns, got %d", len(expected), len(result))
}
require.Len(t, result, len(expected), "Column count mismatch")

for i, exp := range expected {
if result[i].Name != exp.Name {
t.Errorf("Column %d: expected name %s, got %s", i, exp.Name, result[i].Name)
}
if result[i].Type != exp.Type {
t.Errorf("Column %d: expected type %s, got %s", i, exp.Type, result[i].Type)
}
assert.Equal(t, exp.Name, result[i].Name, "Column %d name mismatch", i)
assert.Equal(t, exp.Type, result[i].Type, "Column %d type mismatch", i)
}
})

Expand All @@ -155,14 +150,10 @@ func TestInferColumnsInfo(t *testing.T) {

result := inferColumnsInfo(header, records)

if len(result) != 2 {
t.Fatalf("Expected 2 columns, got %d", len(result))
}
require.Len(t, result, 2, "Expected 2 columns for empty records")

for i, col := range result {
if col.Type != columnTypeText {
t.Errorf("Column %d: expected TEXT type for empty records, got %s", i, col.Type)
}
assert.Equal(t, columnTypeText, col.Type, "Column %d should be TEXT type for empty records", i)
}
})

Expand All @@ -182,17 +173,11 @@ func TestInferColumnsInfo(t *testing.T) {
{Name: "timestamp", Type: columnTypeDatetime},
}

if len(result) != len(expected) {
t.Fatalf("Expected %d columns, got %d", len(expected), len(result))
}
require.Len(t, result, len(expected), "Datetime column count mismatch")

for i, exp := range expected {
if result[i].Name != exp.Name {
t.Errorf("Column %d: expected name %s, got %s", i, exp.Name, result[i].Name)
}
if result[i].Type != exp.Type {
t.Errorf("Column %d: expected type %s, got %s", i, exp.Type, result[i].Type)
}
assert.Equal(t, exp.Name, result[i].Name, "Column %d name mismatch", i)
assert.Equal(t, exp.Type, result[i].Type, "Column %d type mismatch", i)
}
})
}
Expand Down Expand Up @@ -239,9 +224,7 @@ func TestIsDatetime(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
result := isDatetime(tt.value)
if result != tt.expected {
t.Errorf("isDatetime(%q) = %v, want %v", tt.value, result, tt.expected)
}
assert.Equal(t, tt.expected, result, "isDatetime failed for value: %q", tt.value)
})
}
}
79 changes: 26 additions & 53 deletions dump_options_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package filesql

import (
"testing"

"github.com/stretchr/testify/assert"
)

func TestOutputFormat_String(t *testing.T) {
Expand Down Expand Up @@ -37,9 +39,8 @@ func TestOutputFormat_String(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
if got := tt.format.String(); got != tt.want {
t.Errorf("OutputFormat.String() = %v, want %v", got, tt.want)
}
got := tt.format.String()
assert.Equal(t, tt.want, got, "OutputFormat.String() returned unexpected value")
})
}
Comment on lines 39 to 45
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Fix loop variable capture with parallel subtests.

All these subtest loops call t.Parallel() but don’t rebind tt, leading to nondeterministic failures.

Patch each loop:

 for _, tt := range tests {
+    tt := tt
     t.Run(tt.name, func(t *testing.T) {
         t.Parallel()
         got := tt.format.String()
         assert.Equal(t, tt.want, got, "OutputFormat.String() returned unexpected value")
     })
 }

Repeat similarly for the other loops (Extension, CompressionType.String, CompressionType.Extension, FileExtension, and String edge cases), adding tt := tt immediately inside each for _, tt := range tests { ... }.

Also applies to: 78-84, 127-133, 176-182, 267-276, 296-302

🤖 Prompt for AI Agents
In dump_options_test.go around lines 39-45 (and likewise for ranges 78-84,
127-133, 176-182, 267-276, 296-302), the subtests call t.Parallel() but capture
the loop variable tt directly, causing racey/nondeterministic failures; fix by
rebinding the loop variable inside each loop body (i.e., add tt := tt
immediately after the for ... { and before t.Run) so each subtest gets its own
copy of tt before calling t.Parallel().

}
Expand Down Expand Up @@ -77,9 +78,8 @@ func TestOutputFormat_Extension(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
if got := tt.format.Extension(); got != tt.want {
t.Errorf("OutputFormat.Extension() = %v, want %v", got, tt.want)
}
got := tt.format.Extension()
assert.Equal(t, tt.want, got, "OutputFormat.Extension() returned unexpected value")
})
}
}
Expand Down Expand Up @@ -127,9 +127,8 @@ func TestCompressionType_String(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
if got := tt.compression.String(); got != tt.want {
t.Errorf("CompressionType.String() = %v, want %v", got, tt.want)
}
got := tt.compression.String()
assert.Equal(t, tt.want, got, "CompressionType.String() returned unexpected value")
})
}
}
Expand Down Expand Up @@ -177,9 +176,8 @@ func TestCompressionType_Extension(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
if got := tt.compression.Extension(); got != tt.want {
t.Errorf("CompressionType.Extension() = %v, want %v", got, tt.want)
}
got := tt.compression.Extension()
assert.Equal(t, tt.want, got, "CompressionType.Extension() returned unexpected value")
})
}
}
Expand All @@ -189,13 +187,8 @@ func TestNewDumpOptions(t *testing.T) {

options := NewDumpOptions()

if options.Format != OutputFormatCSV {
t.Errorf("NewDumpOptions().Format = %v, want %v", options.Format, OutputFormatCSV)
}

if options.Compression != CompressionNone {
t.Errorf("NewDumpOptions().Compression = %v, want %v", options.Compression, CompressionNone)
}
assert.Equal(t, OutputFormatCSV, options.Format, "NewDumpOptions().Format should default to CSV")
assert.Equal(t, CompressionNone, options.Compression, "NewDumpOptions().Compression should default to None")
}

func TestDumpOptions_WithFormat(t *testing.T) {
Expand All @@ -205,19 +198,13 @@ func TestDumpOptions_WithFormat(t *testing.T) {
newOptions := options.WithFormat(OutputFormatTSV)

// Original options should not be modified
if options.Format != OutputFormatCSV {
t.Errorf("Original options modified: Format = %v, want %v", options.Format, OutputFormatCSV)
}
assert.Equal(t, OutputFormatCSV, options.Format, "Original options should not be modified")

// New options should have the updated format
if newOptions.Format != OutputFormatTSV {
t.Errorf("WithFormat().Format = %v, want %v", newOptions.Format, OutputFormatTSV)
}
assert.Equal(t, OutputFormatTSV, newOptions.Format, "WithFormat() should update format")

// Other fields should remain unchanged
if newOptions.Compression != CompressionNone {
t.Errorf("WithFormat().Compression = %v, want %v", newOptions.Compression, CompressionNone)
}
assert.Equal(t, CompressionNone, newOptions.Compression, "WithFormat() should not change compression")
}

func TestDumpOptions_WithCompression(t *testing.T) {
Expand All @@ -227,19 +214,13 @@ func TestDumpOptions_WithCompression(t *testing.T) {
newOptions := options.WithCompression(CompressionGZ)

// Original options should not be modified
if options.Compression != CompressionNone {
t.Errorf("Original options modified: Compression = %v, want %v", options.Compression, CompressionNone)
}
assert.Equal(t, CompressionNone, options.Compression, "Original options should not be modified")

// New options should have the updated compression
if newOptions.Compression != CompressionGZ {
t.Errorf("WithCompression().Compression = %v, want %v", newOptions.Compression, CompressionGZ)
}
assert.Equal(t, CompressionGZ, newOptions.Compression, "WithCompression() should update compression")

// Other fields should remain unchanged
if newOptions.Format != OutputFormatCSV {
t.Errorf("WithCompression().Format = %v, want %v", newOptions.Format, OutputFormatCSV)
}
assert.Equal(t, OutputFormatCSV, newOptions.Format, "WithCompression() should not change format")
}

func TestDumpOptions_FileExtension(t *testing.T) {
Expand Down Expand Up @@ -290,9 +271,8 @@ func TestDumpOptions_FileExtension(t *testing.T) {
Format: tt.format,
Compression: tt.compression,
}
if got := options.FileExtension(); got != tt.want {
t.Errorf("DumpOptions.FileExtension() = %v, want %v", got, tt.want)
}
got := options.FileExtension()
assert.Equal(t, tt.want, got, "DumpOptions.FileExtension() returned unexpected value")
})
}
}
Expand All @@ -316,9 +296,8 @@ func TestOutputFormatStringEdgeCases(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
if got := tt.format.String(); got != tt.want {
t.Errorf("OutputFormat.String() = %v, want %v", got, tt.want)
}
got := tt.format.String()
assert.Equal(t, tt.want, got, "OutputFormat.String() returned unexpected value")
})
}
}
Expand All @@ -330,16 +309,10 @@ func TestDumpOptions_ChainedMethods(t *testing.T) {
WithFormat(OutputFormatLTSV).
WithCompression(CompressionZSTD)

if options.Format != OutputFormatLTSV {
t.Errorf("Chained WithFormat().Format = %v, want %v", options.Format, OutputFormatLTSV)
}

if options.Compression != CompressionZSTD {
t.Errorf("Chained WithCompression().Compression = %v, want %v", options.Compression, CompressionZSTD)
}
assert.Equal(t, OutputFormatLTSV, options.Format, "Chained WithFormat() should work")
assert.Equal(t, CompressionZSTD, options.Compression, "Chained WithCompression() should work")

expectedExt := ".ltsv.zst"
if got := options.FileExtension(); got != expectedExt {
t.Errorf("Chained options FileExtension() = %v, want %v", got, expectedExt)
}
got := options.FileExtension()
assert.Equal(t, expectedExt, got, "Chained options FileExtension() should work")
}
Loading
Loading