Skip to content

Commit

Permalink
replace log.Printf in integration tests to test logging
Browse files Browse the repository at this point in the history
  • Loading branch information
rekby committed Dec 8, 2023
1 parent 068df80 commit ad2aaef
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 40 deletions.
16 changes: 8 additions & 8 deletions tests/integration/database_sql_containers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"context"
"database/sql"
"fmt"
"log"
"os"
"testing"

Expand Down Expand Up @@ -101,7 +100,7 @@ func TestDatabaseSqlContainers(t *testing.T) {
return rows.Scan(&testDatabaseSqlContainersVariantStruct{})
},
func() error {
return rows.Scan(&testDatabaseSqlContainersVariantTuple{})
return rows.Scan(&testDatabaseSqlContainersVariantTuple{test: t})
},
func() error {
var v int64
Expand Down Expand Up @@ -273,9 +272,10 @@ func (s *testDatabaseSqlContainersVariantStruct) Scan(res interface{}) error {
}

type testDatabaseSqlContainersVariantTuple struct {
a uint32
b string
c int64
a uint32
b string
c int64
test testing.TB
}

func (s *testDatabaseSqlContainersVariantTuple) Scan(res interface{}) error {
Expand Down Expand Up @@ -305,8 +305,8 @@ func (s *testDatabaseSqlContainersVariantTuple) Scan(res interface{}) error {
return fmt.Errorf("type '%T' is not a `types.Value` type", res)
}

func (*testDatabaseSqlContainersVariantTuple) UnmarshalYDB(res types.RawValue) error {
log.Printf("T: %s", res.Type())
func (s *testDatabaseSqlContainersVariantTuple) UnmarshalYDB(res types.RawValue) error {
s.test.Logf("T: %s", res.Type())
name, index := res.Variant()
var x interface{}
switch index {
Expand All @@ -317,7 +317,7 @@ func (*testDatabaseSqlContainersVariantTuple) UnmarshalYDB(res types.RawValue) e
case 2:
x = res.Int64()
}
log.Printf(
s.test.Logf(
"(tuple variant): %s %s %q %d = %v",
res.Path(), res.Type(), name, index, x,
)
Expand Down
75 changes: 43 additions & 32 deletions tests/integration/table_containers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ package integration

import (
"context"
"log"
"os"
"testing"

Expand Down Expand Up @@ -70,22 +69,22 @@ func TestContainers(t *testing.T) {

parsers := [...]func() error{
func() error {
return res.Scan(&testContainersExampleList{})
return res.Scan(&testContainersExampleList{test: t})
},
func() error {
return res.Scan(&testContainersExampleTuple{})
return res.Scan(&testContainersExampleTuple{test: t})
},
func() error {
return res.Scan(&testContainersExampleDict{})
return res.Scan(&testContainersExampleDict{test: t})
},
func() error {
return res.Scan(&testContainersExampleStruct{})
return res.Scan(&testContainersExampleStruct{test: t})
},
func() error {
return res.Scan(&testContainersVariantStruct{})
},
func() error {
return res.Scan(&testContainersVariantTuple{})
return res.Scan(&testContainersVariantTuple{test: t})
},
}

Expand All @@ -101,47 +100,53 @@ func TestContainers(t *testing.T) {
require.NoError(t, err)
}

type testContainersExampleStruct struct{}
type testContainersExampleStruct struct {
test testing.TB
}

func (*testContainersExampleStruct) UnmarshalYDB(res types.RawValue) error {
log.Printf("T: %s", res.Type())
func (s *testContainersExampleStruct) UnmarshalYDB(res types.RawValue) error {
s.test.Logf("T: %s", res.Type())
for i, n := 0, res.StructIn(); i < n; i++ {
name := res.StructField(i)
val := res.Int32()
log.Printf("(struct): %s: %d", name, val)
s.test.Logf("(struct): %s: %d", name, val)
}
res.StructOut()
return res.Err()
}

type testContainersExampleList struct{}
type testContainersExampleList struct {
test testing.TB
}

func (*testContainersExampleList) UnmarshalYDB(res types.RawValue) error {
log.Printf("T: %s", res.Type())
func (c *testContainersExampleList) UnmarshalYDB(res types.RawValue) error {
c.test.Logf("T: %s", res.Type())
for i, n := 0, res.ListIn(); i < n; i++ {
res.ListItem(i)
log.Printf("(list) %q: %s", res.Path(), res.String())
c.test.Logf("(list) %q: %s", res.Path(), res.String())
}
res.ListOut()
return res.Err()
}

type testContainersExampleTuple struct{}
type testContainersExampleTuple struct {
test testing.TB
}

func (*testContainersExampleTuple) UnmarshalYDB(res types.RawValue) error {
log.Printf("T: %s", res.Type())
func (c *testContainersExampleTuple) UnmarshalYDB(res types.RawValue) error {
c.test.Logf("T: %s", res.Type())
for i, n := 0, res.TupleIn(); i < n; i++ {
res.TupleItem(i)
switch i {
case 0:
log.Printf("(tuple) %q: %d", res.Path(), res.Int32())
c.test.Logf("(tuple) %q: %d", res.Path(), res.Int32())
case 1:
log.Printf("(tuple) %q: %s", res.Path(), res.String())
c.test.Logf("(tuple) %q: %s", res.Path(), res.String())
case 2:
n := res.ListIn()
for j := 0; j < n; j++ {
res.ListItem(j)
log.Printf("(tuple) %q: %d", res.Path(), res.Int32())
c.test.Logf("(tuple) %q: %d", res.Path(), res.Int32())
}
res.ListOut()
}
Expand All @@ -150,27 +155,31 @@ func (*testContainersExampleTuple) UnmarshalYDB(res types.RawValue) error {
return res.Err()
}

type testContainersExampleDict struct{}
type testContainersExampleDict struct {
test testing.TB
}

func (*testContainersExampleDict) UnmarshalYDB(res types.RawValue) error {
log.Printf("T: %s", res.Type())
func (c *testContainersExampleDict) UnmarshalYDB(res types.RawValue) error {
c.test.Logf("T: %s", res.Type())
for i, n := 0, res.DictIn(); i < n; i++ {
res.DictKey(i)
key := res.String()

res.DictPayload(i)
val := res.Int32()

log.Printf("(dict) %q: %s: %d", res.Path(), key, val)
c.test.Logf("(dict) %q: %s: %d", res.Path(), key, val)
}
res.DictOut()
return res.Err()
}

type testContainersVariantStruct struct{}
type testContainersVariantStruct struct {
test testing.TB
}

func (*testContainersVariantStruct) UnmarshalYDB(res types.RawValue) error {
log.Printf("T: %s", res.Type())
func (c *testContainersVariantStruct) UnmarshalYDB(res types.RawValue) error {
c.test.Logf("T: %s", res.Type())
name, index := res.Variant()
var x interface{}
switch name {
Expand All @@ -181,17 +190,19 @@ func (*testContainersVariantStruct) UnmarshalYDB(res types.RawValue) error {
case "baz":
x = res.Int64()
}
log.Printf(
c.test.Logf(
"(struct variant): %s %s %q %d = %v",
res.Path(), res.Type(), name, index, x,
)
return res.Err()
}

type testContainersVariantTuple struct{}
type testContainersVariantTuple struct {
test testing.TB
}

func (*testContainersVariantTuple) UnmarshalYDB(res types.RawValue) error {
log.Printf("T: %s", res.Type())
func (c *testContainersVariantTuple) UnmarshalYDB(res types.RawValue) error {
c.test.Logf("T: %s", res.Type())
name, index := res.Variant()
var x interface{}
switch index {
Expand All @@ -202,7 +213,7 @@ func (*testContainersVariantTuple) UnmarshalYDB(res types.RawValue) error {
case 2:
x = res.Int64()
}
log.Printf(
c.test.Logf(
"(tuple variant): %s %s %q %d = %v",
res.Path(), res.Type(), name, index, x,
)
Expand Down

0 comments on commit ad2aaef

Please sign in to comment.