Skip to content

Commit c0c17b1

Browse files
committed
merge main-convert-custom-types into convert-custom-types
2 parents 1601ba4 + 6997cc1 commit c0c17b1

4 files changed

Lines changed: 103 additions & 3 deletions

File tree

.github/workflows/testing.yaml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@ jobs:
2626
uses: golangci/golangci-lint-action@v6
2727
with:
2828
version: latest
29-
- name: Tests
29+
- name: Unit Tests
30+
run: make test-unit-codecov
31+
- name: Integration Tests
3032
env:
3133
SQLITE_CONNECTION_STRING: ${{ vars.SQLITE_CONNECTION_STRING }}
3234
SQLITE_USER: ${{ secrets.SQLITE_USER }}
@@ -40,4 +42,4 @@ jobs:
4042
uses: codecov/codecov-action@v4.0.1
4143
with:
4244
token: ${{ secrets.CODECOV_TOKEN }}
43-
files: ./test/coverage.out
45+
files: ./coverage-unit.out,./test/coverage.out

Makefile

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,14 @@ setup-ide:
77
cd test; go mod tidy
88
cd cli; go mod tidy
99

10-
# Test SDK
10+
# Unit tests (root package)
11+
test-unit:
12+
go test -v .
13+
14+
test-unit-codecov:
15+
go test -v -race -coverprofile=coverage-unit.out -covermode=atomic .
16+
17+
# Integration tests (test/ directory)
1118
test:
1219
cd test; go mod tidy && go test -v .
1320

chunk_internal_test.go

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,64 @@ import (
99
type testStringEnum string
1010
type testIntEnum int
1111

12+
func TestProtocolBufferFromValue(t *testing.T) {
13+
type unsupported struct{}
14+
intVal := 42
15+
strVal := "hello"
16+
17+
tests := []struct {
18+
name string
19+
value interface{}
20+
wantLen int
21+
wantType byte
22+
wantError bool
23+
}{
24+
{"nil", nil, 1, CMD_NULL, false},
25+
{"string", "hello", 1, CMD_ZEROSTRING, false},
26+
{"int", int(42), 1, CMD_INT, false},
27+
{"int8", int8(8), 1, CMD_INT, false},
28+
{"int16", int16(16), 1, CMD_INT, false},
29+
{"int32", int32(32), 1, CMD_INT, false},
30+
{"int64", int64(64), 1, CMD_INT, false},
31+
{"uint", uint(1), 1, CMD_INT, false},
32+
{"uint8", uint8(1), 1, CMD_INT, false},
33+
{"uint16", uint16(1), 1, CMD_INT, false},
34+
{"uint32", uint32(1), 1, CMD_INT, false},
35+
{"uint64", uint64(1), 1, CMD_INT, false},
36+
{"float32", float32(3.14), 1, CMD_FLOAT, false},
37+
{"float64", float64(2.71), 1, CMD_FLOAT, false},
38+
{"[]byte", []byte("blob"), 2, CMD_BLOB, false},
39+
{"bool true", true, 1, CMD_INT, false},
40+
{"bool false", false, 1, CMD_INT, false},
41+
{"*int", &intVal, 1, CMD_INT, false},
42+
{"*string", &strVal, 1, CMD_ZEROSTRING, false},
43+
{"*int nil", (*int)(nil), 1, CMD_NULL, false},
44+
{"*string nil", (*string)(nil), 1, CMD_NULL, false},
45+
{"unsupported", unsupported{}, 0, 0, true},
46+
}
47+
48+
for _, tt := range tests {
49+
t.Run(tt.name, func(t *testing.T) {
50+
buffers, err := protocolBufferFromValue(tt.value)
51+
if tt.wantError {
52+
if err == nil {
53+
t.Fatalf("expected error, got nil")
54+
}
55+
return
56+
}
57+
if err != nil {
58+
t.Fatalf("unexpected error: %v", err)
59+
}
60+
if len(buffers) != tt.wantLen {
61+
t.Fatalf("got %d buffers, want %d", len(buffers), tt.wantLen)
62+
}
63+
if tt.wantLen > 0 && buffers[0][0] != tt.wantType {
64+
t.Fatalf("got first buffer type %q, want %q", buffers[0][0], tt.wantType)
65+
}
66+
})
67+
}
68+
}
69+
1270
func TestProtocolBufferFromValueSupportsStringAlias(t *testing.T) {
1371
val := testStringEnum("active")
1472
buffers, err := protocolBufferFromValue(val)
@@ -68,3 +126,33 @@ func TestProtocolBufferFromValueUnsupportedTypeReturnsError(t *testing.T) {
68126
t.Fatalf("expected error for unsupported type")
69127
}
70128
}
129+
130+
func TestProtocolBufferFromValueMixedArrayNoSilentDrops(t *testing.T) {
131+
pInt := 99
132+
values := []interface{}{
133+
"hello",
134+
int(42),
135+
nil,
136+
&pInt,
137+
float64(3),
138+
uint(7),
139+
[]byte("x"),
140+
true,
141+
}
142+
143+
buffers := [][]byte{}
144+
for i, v := range values {
145+
valueBuffers, err := protocolBufferFromValue(v)
146+
if err != nil {
147+
t.Fatalf("unexpected error at index %d (%T): %v", i, v, err)
148+
}
149+
if len(valueBuffers) == 0 {
150+
t.Fatalf("value at index %d produced zero buffers", i)
151+
}
152+
buffers = append(buffers, valueBuffers...)
153+
}
154+
155+
if len(buffers) < len(values) {
156+
t.Fatalf("got %d total buffers, expected at least %d", len(buffers), len(values))
157+
}
158+
}

cli/sqlc.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,9 @@ func parseParameters() (Parameter, error) {
344344
if err := p.Bind(&parameter); err != nil {
345345
return Parameter{}, err
346346
}
347+
if parameter.NewLine == "" {
348+
parameter.NewLine = "\r\n"
349+
}
347350

348351
// Postprocessing...
349352
if parameter.OutFile != "" {

0 commit comments

Comments
 (0)