• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

ory / keto / 17595125267

09 Sep 2025 08:42PM UTC coverage: 51.075% (+0.05%) from 51.021%
17595125267

push

github

ory-bot
autogen: update license overview

3825 of 7489 relevant lines covered (51.07%)

0.57 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/cmd/client/test_helpers.go
1
// Copyright © 2023 Ory Corp
2
// SPDX-License-Identifier: Apache-2.0
3

4
package client
5

6
import (
7
        "context"
8
        "net"
9
        "testing"
10

11
        "github.com/ory/keto/internal/driver/config"
12

13
        "github.com/ory/x/cmdx"
14
        "github.com/spf13/cobra"
15
        "github.com/stretchr/testify/require"
16
        "golang.org/x/sync/errgroup"
17
        "google.golang.org/grpc"
18

19
        "github.com/ory/keto/internal/driver"
20
        "github.com/ory/keto/internal/namespace"
21
)
22

23
type (
24
        TestServer struct {
25
                Reg              driver.Registry
26
                Namespace        *namespace.Namespace
27
                Addr, FlagRemote string
28
                Cmd              *cmdx.CommandExecuter
29
                Server           *grpc.Server
30
                NewServer        func(ctx context.Context) *grpc.Server
31

32
                errG *errgroup.Group
33
        }
34
        ServerType string
35
)
36

37
const (
38
        WriteServer ServerType = "write"
39
        ReadServer  ServerType = "read"
40
        OplServer   ServerType = "opl"
41
)
42

43
func NewTestServer(t *testing.T,
44
        rw ServerType, nspaces []*namespace.Namespace, newCmd func() *cobra.Command,
45
        registryOpts ...driver.TestRegistryOption,
46
) *TestServer {
×
47
        ctx := context.Background()
×
48
        ts := &TestServer{
×
49
                Reg: driver.NewSqliteTestRegistry(t, false,
×
50
                        append(registryOpts, driver.WithSelfsignedTransportCredentials())...),
×
51
        }
×
52
        require.NoError(t, ts.Reg.Config(ctx).Set(config.KeyNamespaces, nspaces))
×
53

×
54
        switch rw {
×
55
        case ReadServer:
×
56
                ts.NewServer = ts.Reg.ReadGRPCServer
×
57
                ts.FlagRemote = FlagReadRemote
×
58
        case WriteServer:
×
59
                ts.NewServer = ts.Reg.WriteGRPCServer
×
60
                ts.FlagRemote = FlagWriteRemote
×
61
        case OplServer:
×
62
                ts.NewServer = ts.Reg.OplGRPCServer
×
63
                ts.FlagRemote = FlagOplRemote
×
64
        default:
×
65
                t.Logf("Got unknown server type %s", rw)
×
66
                t.FailNow()
×
67
        }
68

69
        ts.Server = ts.NewServer(ctx)
×
70

×
71
        l, err := net.Listen("tcp", "127.0.0.1:0")
×
72
        require.NoError(t, err)
×
73
        ts.Addr = l.Addr().String()
×
74

×
75
        ts.errG = &errgroup.Group{}
×
76
        ts.errG.Go(func() error {
×
77
                return ts.Server.Serve(l)
×
78
        })
×
79

80
        ts.Cmd = &cmdx.CommandExecuter{
×
81
                New: newCmd,
×
82
                PersistentArgs: []string{
×
83
                        "--" + ts.FlagRemote, ts.Addr,
×
84
                        "--insecure-skip-hostname-verification=true",
×
85
                },
×
86
                Ctx: ctx,
×
87
        }
×
88

×
89
        return ts
×
90
}
91

92
func (ts *TestServer) Shutdown(t *testing.T) {
×
93
        ts.Server.GracefulStop()
×
94
        require.NoError(t, ts.errG.Wait())
×
95
}
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc