MCPcopy
hub / github.com/jmoiron/sqlx / TestSelectReset

Function TestSelectReset

sqlx_test.go:1895–1925  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

1893}
1894
1895func TestSelectReset(t *testing.T) {
1896 RunWithSchema(defaultSchema, t, func(db *DB, t *testing.T, now string) {
1897 loadDefaultFixture(db, t)
1898
1899 filledDest := []string{"a", "b", "c"}
1900 err := db.Select(&filledDest, "SELECT first_name FROM person ORDER BY first_name ASC;")
1901 if err != nil {
1902 t.Fatal(err)
1903 }
1904 if len(filledDest) != 2 {
1905 t.Errorf("Expected 2 first names, got %d.", len(filledDest))
1906 }
1907 expected := []string{"Jason", "John"}
1908 for i, got := range filledDest {
1909 if got != expected[i] {
1910 t.Errorf("Expected %d result to be %s, but got %s.", i, expected[i], got)
1911 }
1912 }
1913
1914 var emptyDest []string
1915 err = db.Select(&emptyDest, "SELECT first_name FROM person WHERE first_name = 'Jack';")
1916 if err != nil {
1917 t.Fatal(err)
1918 }
1919 // Verify that selecting 0 rows into a nil target didn't create a
1920 // non-nil slice.
1921 if emptyDest != nil {
1922 t.Error("Expected emptyDest to be nil")
1923 }
1924 })
1925}

Callers

nothing calls this directly

Calls 5

RunWithSchemaFunction · 0.85
loadDefaultFixtureFunction · 0.85
ErrorfMethod · 0.80
ErrorMethod · 0.80
SelectMethod · 0.45

Tested by

no test coverage detected