Skip to content

Commit 0160c1c

Browse files
committed
Fix test
1 parent ab9223c commit 0160c1c

13 files changed

+81
-62
lines changed

config/lint_test.go

+24-22
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,11 @@ func TestRequireTableComment(t *testing.T) {
3636
AllOrNothing: tt.allOrNothing,
3737
Exclude: tt.exclude,
3838
}
39-
s := newTestSchema()
39+
s := newTestSchema(t)
4040
if warns := r.Check(s, tt.lintExclude); len(warns) != tt.want {
4141
t.Errorf("TestRequireTableComment(%d): got %v\nwant %v", i, len(warns), tt.want)
4242
}
43-
ns := newTestNoCommentSchema()
43+
ns := newTestNoCommentSchema(t)
4444
if warns := r.Check(ns, tt.lintExclude); len(warns) != tt.wantNoComment {
4545
t.Errorf("TestRequireTableComment(%d) (no comment schema): got %v\nwant %v", i, len(warns), tt.wantNoComment)
4646
}
@@ -85,12 +85,12 @@ func TestRequireColumnComment(t *testing.T) {
8585
Exclude: tt.exclude,
8686
ExcludeTables: tt.excludeTables,
8787
}
88-
s := newTestSchema()
88+
s := newTestSchema(t)
8989
if warns := r.Check(s, tt.lintExclude); len(warns) != tt.want {
9090
t.Errorf("TestRequireColumnComment(%d): got %v\nwant %v", i, len(warns), tt.want)
9191
}
9292

93-
ns := newTestNoCommentSchema()
93+
ns := newTestNoCommentSchema(t)
9494
if warns := r.Check(ns, tt.lintExclude); len(warns) != tt.wantNoComment {
9595
t.Errorf("TestRequireColumnComment(%d) (no comment schema): got %v\nwant %v", i, len(warns), tt.wantNoComment)
9696
}
@@ -129,12 +129,12 @@ func TestRequireIndexComment(t *testing.T) {
129129
Exclude: tt.exclude,
130130
ExcludeTables: tt.excludeTables,
131131
}
132-
s := newTestSchema()
132+
s := newTestSchema(t)
133133
if warns := r.Check(s, tt.lintExclude); len(warns) != tt.want {
134134
t.Errorf("TestRequireIndexComment(%d): got %v\nwant %v", i, len(warns), tt.want)
135135
}
136136

137-
ns := newTestNoCommentSchema()
137+
ns := newTestNoCommentSchema(t)
138138
if warns := r.Check(ns, tt.lintExclude); len(warns) != tt.wantNoComment {
139139
t.Errorf("TestRequireIndexComment(%d) (no comment schema): got %v\nwant %v", i, len(warns), tt.wantNoComment)
140140
}
@@ -173,12 +173,12 @@ func TestRequireConstraintComment(t *testing.T) {
173173
Exclude: tt.exclude,
174174
ExcludeTables: tt.excludeTables,
175175
}
176-
s := newTestSchema()
176+
s := newTestSchema(t)
177177
if warns := r.Check(s, tt.lintExclude); len(warns) != tt.want {
178178
t.Errorf("TestRequireConstraintComment(%d): got %v\nwant %v", i, len(warns), tt.want)
179179
}
180180

181-
ns := newTestNoCommentSchema()
181+
ns := newTestNoCommentSchema(t)
182182
if warns := r.Check(ns, tt.lintExclude); len(warns) != tt.wantNoComment {
183183
t.Errorf("TestRequireConstraintComment(%d) (no comment schema): got %v\nwant %v", i, len(warns), tt.wantNoComment)
184184
}
@@ -217,12 +217,12 @@ func TestRequireTriggerComment(t *testing.T) {
217217
Exclude: tt.exclude,
218218
ExcludeTables: tt.excludeTables,
219219
}
220-
s := newTestSchema()
220+
s := newTestSchema(t)
221221
if warns := r.Check(s, tt.lintExclude); len(warns) != tt.want {
222222
t.Errorf("TestRequireTriggerComment(%d): got %v\nwant %v", i, len(warns), tt.want)
223223
}
224224

225-
ns := newTestNoCommentSchema()
225+
ns := newTestNoCommentSchema(t)
226226
if warns := r.Check(ns, tt.lintExclude); len(warns) != tt.wantNoComment {
227227
t.Errorf("TestRequireTriggerComment(%d) (no comment schema): got %v\nwant %v", i, len(warns), tt.wantNoComment)
228228
}
@@ -262,7 +262,7 @@ func TestUnrelatedTable(t *testing.T) {
262262
AllOrNothing: tt.allOrNothing,
263263
Exclude: tt.exclude,
264264
}
265-
s := newTestSchema()
265+
s := newTestSchema(t)
266266
warns := r.Check(s, tt.lintExclude)
267267
if len(warns) != tt.want {
268268
t.Errorf("TestUnrelatedTable(%d): got %v\nwant %v", i, len(warns), tt.want)
@@ -272,7 +272,7 @@ func TestUnrelatedTable(t *testing.T) {
272272
t.Errorf("TestUnrelatedTable(%d): got %v\nwant %v", i, warns[0].Message, tt.wantMsg)
273273
}
274274
}
275-
ns := newTestNoRelationSchema()
275+
ns := newTestNoRelationSchema(t)
276276
if warns := r.Check(ns, tt.lintExclude); len(warns) != tt.wantNoRelation {
277277
fmt.Printf("%v\n", warns)
278278
t.Errorf("TestUnrelatedTable(%d) (no relation): got %v\nwant %v", i, len(warns), tt.wantNoRelation)
@@ -301,7 +301,7 @@ func TestColumnCount(t *testing.T) {
301301
Exclude: tt.exclude,
302302
Max: 3,
303303
}
304-
s := newTestSchema()
304+
s := newTestSchema(t)
305305
warns := r.Check(s, tt.lintExclude)
306306
if len(warns) != tt.want {
307307
t.Errorf("TestColumnCount(%d): got %v\nwant %v", i, len(warns), tt.want)
@@ -339,7 +339,7 @@ func TestRequireColumns(t *testing.T) {
339339
},
340340
},
341341
}
342-
s := newTestSchema()
342+
s := newTestSchema(t)
343343
warns := r.Check(s, tt.lintExclude)
344344
if len(warns) != tt.want {
345345
t.Errorf("TestRequireColumns(%d): got %v\nwant %v", i, len(warns), tt.want)
@@ -363,7 +363,7 @@ func TestDuplicateRelations(t *testing.T) {
363363
r := DuplicateRelations{
364364
Enabled: tt.enabled,
365365
}
366-
s := newTestSchema()
366+
s := newTestSchema(t)
367367
copy := *s.Relations[0]
368368
copy.Def = "copy"
369369
s.Relations = append(s.Relations, &copy)
@@ -401,7 +401,7 @@ func TestRequireForeignKeyIndex(t *testing.T) {
401401
Enabled: tt.enabled,
402402
Exclude: tt.exclude,
403403
}
404-
s := newTestSchema()
404+
s := newTestSchema(t)
405405
warns := r.Check(s, tt.lintExclude)
406406
if len(warns) != tt.want {
407407
t.Errorf("TestRequireForeignKeyIndex(%d): got %v\nwant %v", i, len(warns), tt.want)
@@ -423,7 +423,7 @@ func TestLabelStyleBigQuery(t *testing.T) {
423423
r := LabelStyleBigQuery{
424424
Enabled: tt.enabled,
425425
}
426-
s := newTestSchema()
426+
s := newTestSchema(t)
427427
warns := r.Check(s, tt.lintExclude)
428428
if len(warns) != tt.want {
429429
t.Errorf("TestLabelStyleBigQuery(%d): got %v\nwant %v", i, len(warns), tt.want)
@@ -461,7 +461,7 @@ func TestCheckLabelStyleBigQuery(t *testing.T) {
461461
}
462462
}
463463

464-
func newTestSchema() *schema.Schema {
464+
func newTestSchema(t *testing.T) *schema.Schema {
465465
ca := &schema.Column{
466466
Name: "column_a1",
467467
Type: "bigint(20)",
@@ -615,8 +615,9 @@ func newTestSchema() *schema.Schema {
615615
return s
616616
}
617617

618-
func newTestNoCommentSchema() *schema.Schema {
619-
s := newTestSchema()
618+
func newTestNoCommentSchema(t *testing.T) *schema.Schema {
619+
t.Helper()
620+
s := newTestSchema(t)
620621
for _, t := range s.Tables {
621622
t.Comment = ""
622623
for _, c := range t.Columns {
@@ -635,8 +636,9 @@ func newTestNoCommentSchema() *schema.Schema {
635636
return s
636637
}
637638

638-
func newTestNoRelationSchema() *schema.Schema {
639-
s := newTestSchema()
639+
func newTestNoRelationSchema(t *testing.T) *schema.Schema {
640+
t.Helper()
641+
s := newTestSchema(t)
640642
for _, t := range s.Tables {
641643
for _, c := range t.Columns {
642644
c.ChildRelations = nil

coverage/coverage_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88
)
99

1010
func TestMeasure(t *testing.T) {
11-
s := newTestSchema()
11+
s := newTestSchema(t)
1212
got := Measure(s)
1313
if want := 10; got.Covered != want {
1414
t.Errorf("got %v want %v", got.Covered, want)
@@ -37,7 +37,7 @@ func TestRound(t *testing.T) {
3737
}
3838
}
3939

40-
func newTestSchema() *schema.Schema {
40+
func newTestSchema(t *testing.T) *schema.Schema {
4141
ca := &schema.Column{
4242
Name: "column_a1",
4343
Type: "bigint(20)",

output/config/config_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111
)
1212

1313
func TestOutputSchema(t *testing.T) {
14-
s := newTestSchema()
14+
s := newTestSchema(t)
1515
c, err := config.New()
1616
if err != nil {
1717
t.Error(err)
@@ -38,7 +38,7 @@ func testdataDir() string {
3838
return dir
3939
}
4040

41-
func newTestSchema() *schema.Schema {
41+
func newTestSchema(t *testing.T) *schema.Schema {
4242
ca := &schema.Column{
4343
Name: "a",
4444
Comment: "column a",

output/dot/dot_test.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111
)
1212

1313
func TestOutputSchema(t *testing.T) {
14-
s := newTestSchema()
14+
s := newTestSchema(t)
1515
c, err := config.New()
1616
if err != nil {
1717
t.Error(err)
@@ -38,7 +38,7 @@ func TestOutputSchema(t *testing.T) {
3838
}
3939

4040
func TestOutputSchemaTemplate(t *testing.T) {
41-
s := newTestSchema()
41+
s := newTestSchema(t)
4242
c, err := config.New()
4343
if err != nil {
4444
t.Error(err)
@@ -69,7 +69,7 @@ func TestOutputSchemaTemplate(t *testing.T) {
6969
}
7070

7171
func TestOutputTable(t *testing.T) {
72-
s := newTestSchema()
72+
s := newTestSchema(t)
7373
c, err := config.New()
7474
if err != nil {
7575
t.Error(err)
@@ -95,7 +95,7 @@ func TestOutputTable(t *testing.T) {
9595
}
9696

9797
func TestOutputTableTemplate(t *testing.T) {
98-
s := newTestSchema()
98+
s := newTestSchema(t)
9999
c, err := config.New()
100100
if err != nil {
101101
t.Error(err)
@@ -129,7 +129,7 @@ func testdataDir() string {
129129
return dir
130130
}
131131

132-
func newTestSchema() *schema.Schema {
132+
func newTestSchema(t *testing.T) *schema.Schema {
133133
ca := &schema.Column{
134134
Name: "a",
135135
Comment: "column a",

output/gviz/gviz_test.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import (
1313
func TestOutputSchema(t *testing.T) {
1414
format := "svg"
1515

16-
s := newTestSchema()
16+
s := newTestSchema(t)
1717
c, err := config.New()
1818
if err != nil {
1919
t.Fatal(err)
@@ -43,7 +43,7 @@ func TestOutputSchema(t *testing.T) {
4343

4444
func TestOutputTable(t *testing.T) {
4545
format := "svg"
46-
s := newTestSchema()
46+
s := newTestSchema(t)
4747
c, err := config.New()
4848
if err != nil {
4949
t.Error(err)
@@ -76,7 +76,7 @@ func testdataDir() string {
7676
return dir
7777
}
7878

79-
func newTestSchema() *schema.Schema {
79+
func newTestSchema(t *testing.T) *schema.Schema {
8080
ca := &schema.Column{
8181
Name: "a",
8282
Comment: "column a",

output/json/json_test.go

+11-6
Original file line numberDiff line numberDiff line change
@@ -12,25 +12,30 @@ import (
1212
"github.com/google/go-cmp/cmp/cmpopts"
1313
"github.com/k1LoW/tbls/dict"
1414
"github.com/k1LoW/tbls/schema"
15+
"github.com/tenntenn/golden"
1516
)
1617

1718
func TestOutputSchema(t *testing.T) {
18-
s := newTestSchema()
19+
s := newTestSchema(t)
1920
o := new(JSON)
2021
buf := &bytes.Buffer{}
2122
err := o.OutputSchema(buf, s)
2223
if err != nil {
2324
t.Error(err)
2425
}
25-
want, _ := os.ReadFile(filepath.Join(testdataDir(), "json_test_schema.json.golden"))
2626
got := buf.String()
27-
if got != string(want) {
28-
t.Errorf("got %v\nwant %v", got, string(want))
27+
f := "json_output_schema"
28+
if os.Getenv("UPDATE_GOLDEN") != "" {
29+
golden.Update(t, testdataDir(), f, got)
30+
return
31+
}
32+
if diff := golden.Diff(t, testdataDir(), f, got); diff != "" {
33+
t.Error(diff)
2934
}
3035
}
3136

3237
func TestEncodeAndDecode(t *testing.T) {
33-
s1 := newTestSchema()
38+
s1 := newTestSchema(t)
3439
o := new(JSON)
3540
buf := &bytes.Buffer{}
3641
err := o.OutputSchema(buf, s1)
@@ -72,7 +77,7 @@ func testdataDir() string {
7277
return dir
7378
}
7479

75-
func newTestSchema() *schema.Schema {
80+
func newTestSchema(t *testing.T) *schema.Schema {
7681
ca := &schema.Column{
7782
Name: "a",
7883
Type: "bigint(20)",

output/plantuml/plantuml_test.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111
)
1212

1313
func TestOutputSchema(t *testing.T) {
14-
s := newTestSchema()
14+
s := newTestSchema(t)
1515
c, err := config.New()
1616
if err != nil {
1717
t.Error(err)
@@ -38,7 +38,7 @@ func TestOutputSchema(t *testing.T) {
3838
}
3939

4040
func TestOutputSchemaTemplate(t *testing.T) {
41-
s := newTestSchema()
41+
s := newTestSchema(t)
4242
c, err := config.New()
4343
if err != nil {
4444
t.Error(err)
@@ -67,7 +67,7 @@ func TestOutputSchemaTemplate(t *testing.T) {
6767
}
6868

6969
func TestOutputTable(t *testing.T) {
70-
s := newTestSchema()
70+
s := newTestSchema(t)
7171
c, err := config.New()
7272
if err != nil {
7373
t.Error(err)
@@ -93,7 +93,7 @@ func TestOutputTable(t *testing.T) {
9393
}
9494

9595
func TestOutputTableTemplate(t *testing.T) {
96-
s := newTestSchema()
96+
s := newTestSchema(t)
9797
c, err := config.New()
9898
if err != nil {
9999
t.Error(err)
@@ -126,7 +126,7 @@ func testdataDir() string {
126126
return dir
127127
}
128128

129-
func newTestSchema() *schema.Schema {
129+
func newTestSchema(t *testing.T) *schema.Schema {
130130
ca := &schema.Column{
131131
Name: "a",
132132
Comment: "column a",

0 commit comments

Comments
 (0)