Skip to content

Commit 7c04ef2

Browse files
ci: add github workflow to run tests
Add a new GitHub workflow that runs all unit tests on each pushed commit of any branch. This will help to ensure that all changes are tested and that regressions are not introduced.
1 parent 92d197f commit 7c04ef2

File tree

5 files changed

+117
-12
lines changed

5 files changed

+117
-12
lines changed

.github/workflows/go-test.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
name: Go Test
2+
3+
on:
4+
push:
5+
branches: [ "**" ]
6+
7+
jobs:
8+
build:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- uses: actions/checkout@v3
12+
13+
- name: Set up Go
14+
uses: actions/setup-go@v3
15+
with:
16+
go-version: '1.18'
17+
18+
- name: Test
19+
run: go test -v ./...

access_int32_test.go

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package pgtalk
22

33
import "testing"
44

5+
56
func TestInt32InEmpty(t *testing.T) {
67
ta := NewInt32Access(ci, nil)
78
in := ta.In()
@@ -10,6 +11,78 @@ func TestInt32InEmpty(t *testing.T) {
1011
t.Errorf("got [%v:%T] want [%v:%T]", got, got, want, want)
1112
}
1213
}
14+
15+
func TestInt32FieldValueToScan(t *testing.T) {
16+
var i int32 = 42
17+
ta := NewInt32Access(ci, func(dest any) any {
18+
return &i
19+
})
20+
if got, want := ta.FieldValueToScan(nil), &i; got != want {
21+
t.Errorf("got [%v:%T] want [%v:%T]", got, got, want, want)
22+
}
23+
}
24+
25+
func TestInt32AppendScannable(t *testing.T) {
26+
ta := NewInt32Access(ci, nil)
27+
list := []any{}
28+
list = ta.AppendScannable(list)
29+
if got, want := len(list), 1; got != want {
30+
t.Errorf("got [%v:%T] want [%v:%T]", got, got, want, want)
31+
}
32+
}
33+
34+
func TestInt32TableAlias(t *testing.T) {
35+
ta := NewInt32Access(ci, nil)
36+
taa := ta.TableAlias("other")
37+
sql := SQL(taa.Equals(1))
38+
if got, want := sql, "(other.label = 1)"; got != want {
39+
t.Errorf("got [%v:%T] want [%v:%T]", got, got, want, want)
40+
}
41+
}
42+
43+
func TestInt32Get(t *testing.T) {
44+
ta := NewInt32Access(ci, nil)
45+
row := map[string]any{"label": int32(42)}
46+
if got, want := ta.Get(row), int32(42); got != want {
47+
t.Errorf("got [%v:%T] want [%v:%T]", got, got, want, want)
48+
}
49+
}
50+
51+
func TestInt32Set(t *testing.T) {
52+
ta := NewInt32Access(ci, nil)
53+
ta = ta.Set(42)
54+
if got, want := ta.ValueToInsert(), int32(42); got != want {
55+
t.Errorf("got [%v:%T] want [%v:%T]", got, got, want, want)
56+
}
57+
}
58+
59+
func TestInt32BetweenAnd(t *testing.T) {
60+
ta := NewInt32Access(ci, nil)
61+
in := ta.BetweenAnd(1, 100)
62+
sql := SQL(in)
63+
if got, want := sql, "(t1.label BETWEEN 1 AND 100)"; got != want {
64+
t.Errorf("got [%v:%T] want [%v:%T]", got, got, want, want)
65+
}
66+
}
67+
68+
func TestInt32Compare(t *testing.T) {
69+
ta := NewInt32Access(ci, nil)
70+
in := ta.Compare(">", 1)
71+
sql := SQL(in)
72+
if got, want := sql, "(t1.label > 1)"; got != want {
73+
t.Errorf("got [%v:%T] want [%v:%T]", got, got, want, want)
74+
}
75+
}
76+
77+
func TestInt32In(t *testing.T) {
78+
ta := NewInt32Access(ci, nil)
79+
in := ta.In(1, 2)
80+
sql := SQL(in)
81+
if got, want := sql, "(t1.label IN (1,2))"; got != want {
82+
t.Errorf("got [%v:%T] want [%v:%T]", got, got, want, want)
83+
}
84+
}
85+
1386
func TestInt32Euals(t *testing.T) {
1487
ta := NewInt32Access(ci, nil)
1588
in := ta.Equals(int32(1))

access_text_test.go

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,6 @@ import (
44
"testing"
55
)
66

7-
var (
8-
ti = TableInfo{
9-
Name: "things",
10-
Schema: "public",
11-
Alias: "t1",
12-
}
13-
ci = ColumnInfo{
14-
tableInfo: ti,
15-
columnName: "label",
16-
}
17-
)
187

198
func TestTextIn(t *testing.T) {
209
ta := NewTextAccess(ci, nil)

helpers_test.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,15 @@ import (
1414
)
1515

1616
var (
17+
ti = TableInfo{
18+
Name: "things",
19+
Schema: "public",
20+
Alias: "t1",
21+
}
22+
ci = ColumnInfo{
23+
tableInfo: ti,
24+
columnName: "label",
25+
}
1726
polyTable = TableInfo{Name: "polies", Schema: "public", Alias: "p1"}
1827
polyFTime = NewTimeAccess(MakeColumnInfo(polyTable, "ftime", NotPrimary, Nullable, 1),
1928
func(dest any) any { return &dest.(*poly).FTime })

operators.go

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,24 @@ func (o binaryExpression) Like(pattern string) SQLExpression {
6262
}
6363

6464
type betweenAnd struct {
65+
Column SQLExpression
66+
Begin SQLExpression
67+
End SQLExpression
6568
}
6669

67-
func makeBetweenAnd(_ ColumnAccessor, _, _ SQLExpression) betweenAnd { return betweenAnd{} }
70+
func (b betweenAnd) SQLOn(w WriteContext) {
71+
fmt.Fprint(w, "(")
72+
b.Column.SQLOn(w)
73+
fmt.Fprint(w, " BETWEEN ")
74+
b.Begin.SQLOn(w)
75+
fmt.Fprint(w, " AND ")
76+
b.End.SQLOn(w)
77+
fmt.Fprint(w, ")")
78+
}
79+
80+
func makeBetweenAnd(col SQLExpression, begin, end SQLExpression) betweenAnd {
81+
return betweenAnd{Column: col, Begin: begin, End: end}
82+
}
6883

6984
type unaryExpression struct {
7085
Operator string

0 commit comments

Comments
 (0)