From 005c404c239546d17c46fe3679b18296ff01d613 Mon Sep 17 00:00:00 2001 From: Jack Christensen Date: Sat, 20 Apr 2019 10:02:49 -0500 Subject: [PATCH] Remove CopyFromReader tests Equivalent functionality is in pgconn.PgConn.CopyFrom. --- copy_from_test.go | 147 ---------------------------------------------- 1 file changed, 147 deletions(-) diff --git a/copy_from_test.go b/copy_from_test.go index dc9dc072..7f00df7b 100644 --- a/copy_from_test.go +++ b/copy_from_test.go @@ -34,8 +34,6 @@ func TestConnCopyFromSmall(t *testing.T) { {int16(0), int32(1), int64(2), "abc", "efg", time.Date(2000, 1, 1, 0, 0, 0, 0, time.UTC), tzedTime}, {nil, nil, nil, nil, nil, nil, nil}, } - // inputReader := strings.NewReader("0\t1\t2\tabc\tefg\t2000-01-01\t" + tzedTime.Format(time.RFC3339Nano) + "\n" + - // "\\N\t\\N\t\\N\t\\N\t\\N\t\\N\t\\N\n") copyCount, err := conn.CopyFrom(pgx.Identifier{"foo"}, []string{"a", "b", "c", "d", "e", "f", "g"}, pgx.CopyFromRows(inputRows)) if err != nil { @@ -67,41 +65,6 @@ func TestConnCopyFromSmall(t *testing.T) { t.Errorf("Input rows and output rows do not equal: %v -> %v", inputRows, outputRows) } - mustExec(t, conn, "truncate foo") - - // TODO - - // res, err := conn.CopyFromReader(inputReader, "copy foo from stdin") - // if err != nil { - // t.Errorf("Unexpected error for CopyFromReader: %v", err) - // } - // copyCount = int(res.RowsAffected()) - // if copyCount != len(inputRows) { - // t.Errorf("Expected CopyFromReader to return %d copied rows, but got %d", len(inputRows), copyCount) - // } - - // rows, err = conn.Query("select * from foo") - // if err != nil { - // t.Errorf("Unexpected error for Query: %v", err) - // } - - // outputRows = make([][]interface{}, 0) - // for rows.Next() { - // row, err := rows.Values() - // if err != nil { - // t.Errorf("Unexpected error for rows.Values(): %v", err) - // } - // outputRows = append(outputRows, row) - // } - - // if rows.Err() != nil { - // t.Errorf("Unexpected error for rows.Err(): %v", rows.Err()) - // } - - // if !reflect.DeepEqual(inputRows, outputRows) { - // t.Errorf("Input rows and output rows do not equal: %v -> %v", inputRows, outputRows) - // } - ensureConnValid(t, conn) } @@ -125,11 +88,9 @@ func TestConnCopyFromLarge(t *testing.T) { tzedTime := time.Date(2010, 2, 3, 4, 5, 6, 0, time.Local) inputRows := [][]interface{}{} - inputStringRows := "" for i := 0; i < 10000; i++ { inputRows = append(inputRows, []interface{}{int16(0), int32(1), int64(2), "abc", "efg", time.Date(2000, 1, 1, 0, 0, 0, 0, time.UTC), tzedTime, []byte{111, 111, 111, 111}}) - inputStringRows += "0\t1\t2\tabc\tefg\t2000-01-01\t" + tzedTime.Format(time.RFC3339Nano) + "\toooo\n" } copyCount, err := conn.CopyFrom(pgx.Identifier{"foo"}, []string{"a", "b", "c", "d", "e", "f", "g", "h"}, pgx.CopyFromRows(inputRows)) @@ -162,41 +123,6 @@ func TestConnCopyFromLarge(t *testing.T) { t.Errorf("Input rows and output rows do not equal") } - mustExec(t, conn, "truncate foo") - - // TODO - - // res, err := conn.CopyFromReader(strings.NewReader(inputStringRows), "copy foo from stdin") - // if err != nil { - // t.Errorf("Unexpected error for CopyFromReader: %v", err) - // } - // copyCount = int(res.RowsAffected()) - // if copyCount != len(inputRows) { - // t.Errorf("Expected CopyFromReader to return %d copied rows, but got %d", len(inputRows), copyCount) - // } - - // rows, err = conn.Query("select * from foo") - // if err != nil { - // t.Errorf("Unexpected error for Query: %v", err) - // } - - // outputRows = make([][]interface{}, 0) - // for rows.Next() { - // row, err := rows.Values() - // if err != nil { - // t.Errorf("Unexpected error for rows.Values(): %v", err) - // } - // outputRows = append(outputRows, row) - // } - - // if rows.Err() != nil { - // t.Errorf("Unexpected error for rows.Err(): %v", rows.Err()) - // } - - // if !reflect.DeepEqual(inputRows, outputRows) { - // t.Errorf("Input rows and output rows do not equal") - // } - ensureConnValid(t, conn) } @@ -221,7 +147,6 @@ func TestConnCopyFromJSON(t *testing.T) { {map[string]interface{}{"foo": "bar"}, map[string]interface{}{"bar": "quz"}}, {nil, nil}, } - // inputReader := strings.NewReader("{\"foo\":\"bar\"}\t{\"bar\":\"quz\"}\n\\N\t\\N\n") copyCount, err := conn.CopyFrom(pgx.Identifier{"foo"}, []string{"a", "b"}, pgx.CopyFromRows(inputRows)) if err != nil { @@ -253,41 +178,6 @@ func TestConnCopyFromJSON(t *testing.T) { t.Errorf("Input rows and output rows do not equal: %v -> %v", inputRows, outputRows) } - mustExec(t, conn, "truncate foo") - - // TODO - - // res, err := conn.CopyFromReader(inputReader, "copy foo from stdin") - // if err != nil { - // t.Errorf("Unexpected error for CopyFrom: %v", err) - // } - // copyCount = int(res.RowsAffected()) - // if copyCount != len(inputRows) { - // t.Errorf("Expected CopyFromReader to return %d copied rows, but got %d", len(inputRows), copyCount) - // } - - // rows, err = conn.Query("select * from foo") - // if err != nil { - // t.Errorf("Unexpected error for Query: %v", err) - // } - - // outputRows = make([][]interface{}, 0) - // for rows.Next() { - // row, err := rows.Values() - // if err != nil { - // t.Errorf("Unexpected error for rows.Values(): %v", err) - // } - // outputRows = append(outputRows, row) - // } - - // if rows.Err() != nil { - // t.Errorf("Unexpected error for rows.Err(): %v", rows.Err()) - // } - - // if !reflect.DeepEqual(inputRows, outputRows) { - // t.Errorf("Input rows and output rows do not equal: %v -> %v", inputRows, outputRows) - // } - ensureConnValid(t, conn) } @@ -329,7 +219,6 @@ func TestConnCopyFromFailServerSideMidway(t *testing.T) { {int32(2), nil}, // this row should trigger a failure {int32(3), "def"}, } - // inputReader := strings.NewReader("1\tabc\n2\t\\N\n3\tdef\n") copyCount, err := conn.CopyFrom(pgx.Identifier{"foo"}, []string{"a", "b"}, pgx.CopyFromRows(inputRows)) if err == nil { @@ -366,42 +255,6 @@ func TestConnCopyFromFailServerSideMidway(t *testing.T) { mustExec(t, conn, "truncate foo") - // TODO - - // res, err := conn.CopyFromReader(inputReader, "copy foo from stdin") - // if err == nil { - // t.Errorf("Expected CopyFromReader return error, but it did not") - // } - // if _, ok := err.(*pgconn.PgError); !ok { - // t.Errorf("Expected CopyFromReader return pgx.PgError, but instead it returned: %v", err) - // } - // copyCount = int(res.RowsAffected()) - // if copyCount != 0 { - // t.Errorf("Expected CopyFromReader to return 0 copied rows, but got %d", copyCount) - // } - - // rows, err = conn.Query("select * from foo") - // if err != nil { - // t.Errorf("Unexpected error for Query: %v", err) - // } - - // outputRows = make([][]interface{}, 0) - // for rows.Next() { - // row, err := rows.Values() - // if err != nil { - // t.Errorf("Unexpected error for rows.Values(): %v", err) - // } - // outputRows = append(outputRows, row) - // } - - // if rows.Err() != nil { - // t.Errorf("Unexpected error for rows.Err(): %v", rows.Err()) - // } - - // if len(outputRows) != 0 { - // t.Errorf("Expected 0 rows, but got %v", outputRows) - // } - ensureConnValid(t, conn) }