|
| 1 | +package plan |
| 2 | + |
| 3 | +import ( |
| 4 | + "io" |
| 5 | + "testing" |
| 6 | + |
| 7 | + "github.com/gitql/gitql/mem" |
| 8 | + "github.com/gitql/gitql/sql" |
| 9 | + "github.com/stretchr/testify/assert" |
| 10 | +) |
| 11 | + |
| 12 | +func TestShowTables(t *testing.T) { |
| 13 | + assert := assert.New(t) |
| 14 | + |
| 15 | + unresolvedShowTables := NewShowTables(&sql.UnresolvedDatabase{}) |
| 16 | + |
| 17 | + assert.False(unresolvedShowTables.Resolved()) |
| 18 | + assert.Nil(unresolvedShowTables.Children()) |
| 19 | + |
| 20 | + db := mem.NewDatabase("test") |
| 21 | + db.AddTable("test1", mem.NewTable("test1", nil)) |
| 22 | + db.AddTable("test2", mem.NewTable("test2", nil)) |
| 23 | + db.AddTable("test3", mem.NewTable("test3", nil)) |
| 24 | + |
| 25 | + resolvedShowTables := NewShowTables(db) |
| 26 | + assert.True(resolvedShowTables.Resolved()) |
| 27 | + assert.Nil(resolvedShowTables.Children()) |
| 28 | + |
| 29 | + iter, err := resolvedShowTables.RowIter() |
| 30 | + assert.Nil(err) |
| 31 | + |
| 32 | + res, err := iter.Next() |
| 33 | + assert.Nil(err) |
| 34 | + assert.Equal("test1", res.Fields()[0]) |
| 35 | + |
| 36 | + res, err = iter.Next() |
| 37 | + assert.Nil(err) |
| 38 | + assert.Equal("test2", res.Fields()[0]) |
| 39 | + |
| 40 | + res, err = iter.Next() |
| 41 | + assert.Nil(err) |
| 42 | + assert.Equal("test3", res.Fields()[0]) |
| 43 | + |
| 44 | + _, err = iter.Next() |
| 45 | + assert.Equal(io.EOF, err) |
| 46 | +} |
0 commit comments