Skip to content

Commit

Permalink
Share test server between packages
Browse files Browse the repository at this point in the history
  • Loading branch information
fmoor committed Aug 16, 2022
1 parent 64d880c commit d18560e
Show file tree
Hide file tree
Showing 7 changed files with 486 additions and 315 deletions.
23 changes: 23 additions & 0 deletions cmd/edgeql-go/endtoend_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,41 @@
package main

import (
"fmt"
"io"
"io/fs"
"log"
"os"
"os/exec"
"path/filepath"
"strings"
"sync"
"testing"

edgedb "github.com/edgedb/edgedb-go/internal/client"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

var dsn string

func TestMain(m *testing.M) {
o := edgedb.TestClientOptions()
pwd, ok := o.Password.Get()
if !ok {
log.Fatal("missing password")
}
dsn = fmt.Sprintf(
"edgedb://%s:%s@%s:%d?tls_security=%s&tls_ca_file=%s",
o.User,
pwd,
o.Host,
o.Port,
o.TLSOptions.SecurityMode,
o.TLSOptions.CAFile,
)
}

func TestEdgeQLGo(t *testing.T) {
dir, err := os.MkdirTemp("", "edgeql-go-*")
require.NoError(t, err)
Expand Down Expand Up @@ -150,5 +172,6 @@ func run(t *testing.T, dir, name string, args ...string) {
cmd.Dir = dir
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
cmd.Env = []string{fmt.Sprintf("EDGEDB_DSN=%s", dsn)}
require.NoError(t, cmd.Run())
}
3 changes: 1 addition & 2 deletions cmd/edgeql-go/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ func main() {
if err != nil {
log.Fatalf("creating client: %s", err) // nolint:gocritic
}
client := edgedb.InstrospectionClient{Client: c}

fileQueue := queueFilesInBackground()

Expand All @@ -90,7 +89,7 @@ func main() {
go func(queryFile string) {
defer wg.Done()
outFile := getOutFile(queryFile)
q, e := newQuery(ctx, client, queryFile, outFile)
q, e := newQuery(ctx, c, queryFile, outFile)
if e != nil {
log.Fatalf("processing %s: %s", queryFile, e)
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/edgeql-go/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import (

func newQuery(
ctx context.Context,
client edgedb.InstrospectionClient,
c *edgedb.Client,
queryFile,
outFile string,
) (*Query, error) {
Expand All @@ -48,7 +48,7 @@ func newQuery(
log.Fatalf("error reading %q: %s", queryFile, err)
}

description, err := client.Describe(ctx, string(queryBytes))
description, err := edgedb.Describe(ctx, c, string(queryBytes))
if err != nil {
log.Fatalf("error introspecting query %q: %s", queryFile, err)
}
Expand Down
9 changes: 0 additions & 9 deletions internal/client/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ import (
"reflect"

"github.com/edgedb/edgedb-go/internal/codecs"
"github.com/edgedb/edgedb-go/internal/descriptor"
types "github.com/edgedb/edgedb-go/internal/edgedbtypes"
"github.com/edgedb/edgedb-go/internal/header"
)
Expand All @@ -63,14 +62,6 @@ type codecPair struct {
out codecs.Decoder
}

// CommandDescription is the information returned in the CommandDataDescription
// message
type CommandDescription struct {
In descriptor.Descriptor
Out descriptor.Descriptor
Card Cardinality
}

type idPair struct {
in types.UUID
out types.UUID
Expand Down
34 changes: 30 additions & 4 deletions internal/client/introspect.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,23 @@ package edgedb

import (
"context"

"github.com/edgedb/edgedb-go/internal"
"github.com/edgedb/edgedb-go/internal/descriptor"
)

// InstrospectionClient is an client with methods for introspecting.
type InstrospectionClient struct {
*Client
// CommandDescription is the information returned in the CommandDataDescription
// message
type CommandDescription struct {
In descriptor.Descriptor
Out descriptor.Descriptor
Card Cardinality
}

// Describe returns CommandDescription for the provided cmd.
func (c *InstrospectionClient) Describe(
func Describe(
ctx context.Context,
c *Client,
cmd string,
) (*CommandDescription, error) {
conn, err := c.acquire(ctx)
Expand Down Expand Up @@ -61,3 +68,22 @@ func (c *InstrospectionClient) Describe(

return d, nil
}

// ProtocolVersion returns the protocol version used by c.
func ProtocolVersion(
ctx context.Context,
c *Client,
) (internal.ProtocolVersion, error) {
conn, err := c.acquire(ctx)
if err != nil {
return internal.ProtocolVersion{}, err
}

protocolVersion := conn.conn.protocolVersion
err = c.release(conn, nil)
if err != nil {
return internal.ProtocolVersion{}, err
}

return protocolVersion, nil
}
Loading

0 comments on commit d18560e

Please sign in to comment.