|
| 1 | +package gitquery_test |
| 2 | + |
| 3 | +import ( |
| 4 | + "context" |
| 5 | + "testing" |
| 6 | + |
| 7 | + "github.com/src-d/gitquery" |
| 8 | + "github.com/src-d/gitquery/internal/function" |
| 9 | + "github.com/stretchr/testify/require" |
| 10 | + fixtures "gopkg.in/src-d/go-git-fixtures.v3" |
| 11 | + sqle "gopkg.in/src-d/go-mysql-server.v0" |
| 12 | + "gopkg.in/src-d/go-mysql-server.v0/sql" |
| 13 | +) |
| 14 | + |
| 15 | +func TestIntegration(t *testing.T) { |
| 16 | + engine := sqle.New() |
| 17 | + require.NoError(t, fixtures.Init()) |
| 18 | + defer func() { |
| 19 | + require.NoError(t, fixtures.Clean()) |
| 20 | + }() |
| 21 | + |
| 22 | + path := fixtures.ByTag("worktree").One().Worktree().Root() |
| 23 | + pool := gitquery.NewRepositoryPool() |
| 24 | + _, err := pool.AddGit(path) |
| 25 | + require.NoError(t, err) |
| 26 | + |
| 27 | + engine.AddDatabase(gitquery.NewDatabase("foo", &pool)) |
| 28 | + function.Register(engine.Catalog) |
| 29 | + |
| 30 | + testCases := []struct { |
| 31 | + query string |
| 32 | + result []sql.Row |
| 33 | + }{ |
| 34 | + { |
| 35 | + `SELECT COUNT(c.hash), c.hash |
| 36 | + FROM refs r |
| 37 | + INNER JOIN commits c |
| 38 | + ON history_idx(r.hash, c.hash) >= 0 |
| 39 | + INNER JOIN blobs b |
| 40 | + ON commit_contains(c.hash, b.hash) |
| 41 | + WHERE r.name = 'refs/heads/master' |
| 42 | + GROUP BY c.hash`, |
| 43 | + []sql.Row{ |
| 44 | + {int32(4), "1669dce138d9b841a518c64b10914d88f5e488ea"}, |
| 45 | + {int32(3), "35e85108805c84807bc66a02d91535e1e24b38b9"}, |
| 46 | + {int32(9), "6ecf0ef2c2dffb796033e5a02219af86ec6584e5"}, |
| 47 | + {int32(8), "918c48b83bd081e863dbe1b80f8998f058cd8294"}, |
| 48 | + {int32(3), "a5b8b09e2f8fcb0bb99d3ccb0958157b40890d69"}, |
| 49 | + {int32(6), "af2d6a6954d532f8ffb47615169c8fdf9d383a1a"}, |
| 50 | + {int32(2), "b029517f6300c2da0f4b651b8642506cd6aaf45d"}, |
| 51 | + {int32(3), "b8e471f58bcbca63b07bda20e428190409c2db47"}, |
| 52 | + }, |
| 53 | + }, |
| 54 | + } |
| 55 | + |
| 56 | + for _, tt := range testCases { |
| 57 | + t.Run(tt.query, func(t *testing.T) { |
| 58 | + require := require.New(t) |
| 59 | + session := gitquery.NewSession(context.TODO(), &pool) |
| 60 | + _, iter, err := engine.Query(session, tt.query) |
| 61 | + require.NoError(err) |
| 62 | + rows, err := sql.RowIterToRows(iter) |
| 63 | + require.NoError(err) |
| 64 | + require.ElementsMatch(tt.result, rows) |
| 65 | + }) |
| 66 | + } |
| 67 | +} |
0 commit comments