MCPcopy Create free account
hub / github.com/sql-machine-learning/sqlflow / TestSQLFSWriteAndRead

Function TestSQLFSWriteAndRead

go/sqlfs/reader_test.go:28–85  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

26)
27
28func TestSQLFSWriteAndRead(t *testing.T) {
29 a := assert.New(t)
30 const bufSize = 32 * 1024
31
32 createSQLFSTestingDatabaseOnce.Do(createSQLFSTestingDatabase)
33
34 db := database.GetTestingDBSingleton()
35
36 tbl := fmt.Sprintf("%s.unittest%d", testDatabaseName, rand.Int())
37
38 w, e := Create(db, tbl, database.GetSessionFromTestingDB())
39 a.NoError(e)
40 a.NotNil(w)
41
42 // A small output.
43 buf := []byte("\n\n\n")
44 n, e := w.Write(buf)
45 a.NoError(e)
46 a.Equal(len(buf), n)
47
48 // A big output.
49 buf = make([]byte, bufSize+1)
50 for i := range buf {
51 buf[i] = 'x'
52 }
53 n, e = w.Write(buf)
54 a.NoError(e)
55 a.Equal(len(buf), n)
56
57 a.NoError(w.Close())
58
59 r, e := Open(db.DB, tbl)
60 a.NoError(e)
61 a.NotNil(r)
62
63 // A small read
64 buf = make([]byte, 2)
65 n, e = r.Read(buf)
66 a.NoError(e)
67 a.Equal(2, n)
68 a.Equal(2, strings.Count(string(buf), "\n"))
69
70 // A big read of rest
71 buf = make([]byte, bufSize*2)
72 n, e = r.Read(buf)
73 a.Equal(io.EOF, e)
74 a.Equal(bufSize+2, n)
75 a.Equal(1, strings.Count(string(buf), "\n"))
76 a.Equal(bufSize+1, strings.Count(string(buf), "x"))
77
78 // Another big read
79 n, e = r.Read(buf)
80 a.Equal(io.EOF, e)
81 a.Equal(0, n)
82 a.NoError(r.Close())
83
84 a.NoError(dropTableIfExists(db.DB, tbl))
85}

Callers

nothing calls this directly

Calls 9

GetTestingDBSingletonFunction · 0.92
GetSessionFromTestingDBFunction · 0.92
OpenFunction · 0.85
IntMethod · 0.80
CreateFunction · 0.70
dropTableIfExistsFunction · 0.70
WriteMethod · 0.45
CloseMethod · 0.45
ReadMethod · 0.45

Tested by

no test coverage detected