Some checks failed
kotlin / test (push) Has been skipped
python / test (push) Has been skipped
typescript / test (push) Has been skipped
go / build darwin/amd64 (push) Has been cancelled
go / build linux/amd64 (push) Has been cancelled
go / build windows/amd64 (push) Has been cancelled
go / build darwin/arm64 (push) Has been cancelled
go / build linux/arm64 (push) Has been cancelled
go / build windows/arm64 (push) Has been cancelled
go / test (push) Has been cancelled
go / vuln_check (push) Has been cancelled
44 lines
1.1 KiB
Go
44 lines
1.1 KiB
Go
package clickhouse
|
|
|
|
import (
|
|
"context"
|
|
"os"
|
|
|
|
"github.com/sqlc-dev/sqlc/internal/goldeneye/analysis"
|
|
"github.com/sqlc-dev/sqlc/internal/goldeneye/endtoend"
|
|
)
|
|
|
|
// Analyze runs a case's queries through the clickhouse binary and returns
|
|
// the analysis in the JSON shape sqlc analyze prints.
|
|
func Analyze(ctx context.Context, binary string, c endtoend.Case) ([]byte, error) {
|
|
schema, err := os.ReadFile(c.Schema)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
var fixture []byte
|
|
if c.Fixture != "" {
|
|
if fixture, err = os.ReadFile(c.Fixture); err != nil {
|
|
return nil, err
|
|
}
|
|
}
|
|
queries, err := c.Queries()
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
out, err := analyze(ctx, local{binary: binary}, string(schema), string(fixture), queries)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return analysis.Encode(out)
|
|
}
|
|
|
|
// Check compares what ClickHouse reports for a case with the output the
|
|
// case committed, returning a diff when they differ.
|
|
func Check(ctx context.Context, binary string, c endtoend.Case) (string, error) {
|
|
got, err := Analyze(ctx, binary, c)
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
return c.Compare(got)
|
|
}
|