-
Notifications
You must be signed in to change notification settings - Fork 15
/
integration_helpers_test.go
74 lines (64 loc) · 1.55 KB
/
integration_helpers_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
// SPDX-FileCopyrightText: 2021 SAP SE
// SPDX-FileCopyrightText: 2022 SAP SE
// SPDX-FileCopyrightText: 2023 SAP SE
//
// SPDX-License-Identifier: Apache-2.0
// +build integration
package ase
import (
"context"
"database/sql"
"database/sql/driver"
"errors"
"fmt"
"io"
"testing"
)
// wrapper is used to wrap tests for the underlying driver connection in
// integration tests.
func wrapper(t *testing.T, db *sql.DB, tableName string, runner func(*testing.T, *Conn, string)) {
if err := createTable(db, tableName); err != nil {
t.Errorf("error creating table: %v", err)
return
}
conn, err := db.Conn(context.Background())
if err != nil {
t.Errorf("error getting conn from sql.DB: %v", err)
return
}
defer func() {
if err := conn.Close(); err != nil {
t.Errorf("error closing conn from sql.DB: %v", err)
}
}()
conn.Raw(func(driverConn interface{}) error {
aseConn, ok := driverConn.(*Conn)
if !ok {
t.Errorf("received driverConn is not *Conn: %v", err)
return nil
}
runner(t, aseConn, tableName)
return nil
})
}
// interface to match both Rows and CursorRows.
type sqlRows interface {
Next([]driver.Value) error
}
// fetchRows expects the passed rows to return {int, string} and prints
// all rows to stdout.
//
// rows is not closed automatically.
func fetchRows(t *testing.T, rows sqlRows) {
values := []driver.Value{0, ""}
for {
if err := rows.Next(values); err != nil {
if errors.Is(err, io.EOF) {
break
}
t.Errorf("error reading row: %v", err)
return
}
fmt.Printf("| %d | %s |\n", values[0], values[1])
}
}