(t *testing.T)
| 48 | } |
| 49 | |
| 50 | func TestSQLFSSQLWriterWriteAndRead(t *testing.T) { |
| 51 | createSQLFSTestingDatabaseOnce.Do(createSQLFSTestingDatabase) |
| 52 | db := database.GetTestingDBSingleton() |
| 53 | a := assert.New(t) |
| 54 | |
| 55 | if db.DriverName == "hive" { |
| 56 | t.Skip("Skip as SQLFLOW_TEST_DB is Hive") |
| 57 | } |
| 58 | t.Logf("Confirm executed with %s", db.DriverName) |
| 59 | |
| 60 | tbl := fmt.Sprintf("%s.unittest%d", testDatabaseName, rand.Int()) |
| 61 | w, e := newSQLWriter(db, tbl, bufSize) |
| 62 | a.NoError(e) |
| 63 | a.NotNil(w) |
| 64 | |
| 65 | // A small output. |
| 66 | buf := []byte("\n\n\n") |
| 67 | n, e := w.Write(buf) |
| 68 | a.NoError(e) |
| 69 | a.Equal(len(buf), n) |
| 70 | |
| 71 | // A big output. |
| 72 | buf = make([]byte, bufSize+1) |
| 73 | for i := range buf { |
| 74 | buf[i] = 'x' |
| 75 | } |
| 76 | n, e = w.Write(buf) |
| 77 | a.NoError(e) |
| 78 | a.Equal(len(buf), n) |
| 79 | |
| 80 | a.NoError(w.Close()) |
| 81 | |
| 82 | r, e := Open(db.DB, tbl) |
| 83 | a.NoError(e) |
| 84 | a.NotNil(r) |
| 85 | |
| 86 | // A small read |
| 87 | buf = make([]byte, 2) |
| 88 | n, e = r.Read(buf) |
| 89 | a.NoError(e) |
| 90 | a.Equal(2, n) |
| 91 | a.Equal(2, strings.Count(string(buf), "\n")) |
| 92 | |
| 93 | // A big read of rest |
| 94 | buf = make([]byte, bufSize*2) |
| 95 | n, e = r.Read(buf) |
| 96 | a.Equal(io.EOF, e) |
| 97 | a.Equal(bufSize+2, n) |
| 98 | a.Equal(1, strings.Count(string(buf), "\n")) |
| 99 | a.Equal(bufSize+1, strings.Count(string(buf), "x")) |
| 100 | |
| 101 | // Another big read |
| 102 | n, e = r.Read(buf) |
| 103 | a.Equal(io.EOF, e) |
| 104 | a.Equal(0, n) |
| 105 | a.NoError(r.Close()) |
| 106 | |
| 107 | a.NoError(dropTableIfExists(db.DB, tbl)) |
nothing calls this directly
no test coverage detected