Skip to content

Commit 1464871

Browse files
committed
Test that Columns() avoids allocating on second call
1 parent 50edee1 commit 1464871

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

driver_test.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1916,3 +1916,36 @@ func TestInterruptBySignal(t *testing.T) {
19161916
}
19171917
})
19181918
}
1919+
1920+
func TestColumnsReusesSlice(t *testing.T) {
1921+
rows := mysqlRows{
1922+
rs: resultSet{
1923+
columns: []mysqlField{
1924+
{
1925+
tableName: "test",
1926+
name: "A",
1927+
},
1928+
{
1929+
tableName: "test",
1930+
name: "B",
1931+
},
1932+
},
1933+
},
1934+
}
1935+
1936+
allocs := testing.AllocsPerRun(1, func() {
1937+
cols := rows.Columns()
1938+
1939+
if len(cols) != 2 {
1940+
t.Fatalf("expected 2 columns, got %d", len(cols))
1941+
}
1942+
})
1943+
1944+
if allocs != 0 {
1945+
t.Fatalf("expected 0 allocations, got %d", int(allocs))
1946+
}
1947+
1948+
if rows.rs.columnNames == nil {
1949+
t.Fatalf("expected columnNames to be set, got nil")
1950+
}
1951+
}

0 commit comments

Comments
 (0)